D. Shortest and Longest LIStime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGildong recently learned how to find the longest increasing subsequence (LIS) in O(nlogn)O(nlogn) time for a sequence of length nn. He wants to test himself if he can implement it correctly, but he couldn't find any online judges that would do it (even though there are actually many of them). So instead he's going to make a quiz for you about making permutations of nn distinct integers between 11 and nn, inclusive, to test his code with your output.The quiz is as follows.Gildong provides a string of length n−1n−1, consisting of characters '<' and '>' only. The ii-th (1-indexed) character is the comparison result between the ii-th element and the i+1i+1-st element of the sequence. If the ii-th character of the string is '<', then the ii-th element of the sequence is less than the i+1i+1-st element. If the ii-th character of the string is '>', then the ii-th element of the sequence is greater than the i+1i+1-st element.He wants you to find two possible sequences (not necessarily distinct) consisting of nn distinct integers between 11 and nn, inclusive, each satisfying the comparison results, where the length of the LIS of the first sequence is minimum possible, and the length of the LIS of the second sequence is maximum possible.InputEach test contains one or more test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104).Each test case contains exactly one line, consisting of an integer and a string consisting of characters '<' and '>' only. The integer is nn (2≤n≤2⋅1052≤n≤2⋅105), the length of the permutation you need to find. The string is the comparison results explained in the description. The length of the string is n−1n−1.It is guaranteed that the sum of all nn in all test cases doesn't exceed 2⋅1052⋅105.OutputFor each test case, print two lines with nn integers each. The first line is the sequence with the minimum length of the LIS, and the second line is the sequence with the maximum length of the LIS. If there are multiple answers, print any one of them. Each sequence should contain all integers between 11 and nn, inclusive, and should satisfy the comparison results.It can be shown that at least one answer always exists.ExampleInputCopy3
3 <<
7 >><>><
5 >>><
OutputCopy1 2 3
1 2 3
5 4 3 7 2 1 6
4 3 1 7 5 2 6
4 3 2 1 5
5 4 2 1 3
NoteIn the first case; 11 22 33 is the only possible answer.In the second case, the shortest length of the LIS is 22, and the longest length of the LIS is 33. In the example of the maximum LIS sequence, 44 '33' 11 77 '55' 22 '66' can be one of the possible LIS.

import java.io.*;

import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException

	{

		FastScanner f = new FastScanner();

		int ttt=1;

		ttt=f.nextInt();

		PrintWriter out=new PrintWriter(System.out);

		for(int tt=0;tt<ttt;tt++) {

			int n=f.nextInt();

			char[] l=f.next().toCharArray();

			int num = n, last = 0;

			int[] ans=new int[n];

			for (int i = 0; i < n; i++)

			{

				if (i == n - 1 || l[i] == '>')

				{

					for (int j = i; j >= last; j--)

						ans[j] = num--;

					last = i + 1;

				}

			}

			for (int i:ans) System.out.print(i+" ");

			System.out.println();

			ans=new int[n];

			num = 1;

			last = 0;

			for (int i = 0; i < n; i++)

			{

				if (i == n - 1 || l[i] == '<')

				{

					for (int j = i; j >= last; j--)

						ans[j] = num++;

					last = i + 1;

				}

			}

			for (int i:ans) System.out.print(i+" ");

			System.out.println();

		}

		out.close();

	}

	static void sort(int[] p) {

        ArrayList<Integer> q = new ArrayList<>();

        for (int i: p) q.add( i);

        Collections.sort(q);

        for (int i = 0; i < p.length; i++) p[i] = q.get(i);

    }

	static class FastScanner {

		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer st=new StringTokenizer("");

		String next() {

			while (!st.hasMoreTokens())

				try {

					st=new StringTokenizer(br.readLine());

				} catch (IOException e) {

					e.printStackTrace();

				}

			return st.nextToken();

		}

		int nextInt() {

			return Integer.parseInt(next());

		}

		int[] readArray(int n) {

			int[] a=new int[n];

			for (int i=0; i<n; i++) a[i]=nextInt();

			return a;

		}

		long nextLong() {

			return Long.parseLong(next());

		}

		double nextDouble() {

			return Double.parseDouble(next());

		}

		long[] readLongArray(int n) {

			long[] a=new long[n];

			for (int i=0; i<n; i++) a[i]=nextLong();

			return a;

		}

	}

}


D. Around the Worldtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputGuy-Manuel and Thomas are planning 144144 trips around the world.You are given a simple weighted undirected connected graph with nn vertexes and mm edges with the following restriction: there isn't any simple cycle (i. e. a cycle which doesn't pass through any vertex more than once) of length greater than 33 which passes through the vertex 11. The cost of a path (not necessarily simple) in this graph is defined as the XOR of weights of all edges in that path with each edge being counted as many times as the path passes through it.But the trips with cost 00 aren't exciting. You may choose any subset of edges incident to the vertex 11 and remove them. How many are there such subsets, that, when removed, there is not any nontrivial cycle with the cost equal to 00 which passes through the vertex 11 in the resulting graph? A cycle is called nontrivial if it passes through some edge odd number of times. As the answer can be very big, output it modulo 109+7109+7.InputThe first line contains two integers nn and mm (1≤n,m≤1051≤n,m≤105) — the number of vertexes and edges in the graph. The ii-th of the next mm lines contains three integers aiai, bibi and wiwi (1≤ai,bi≤n,ai≠bi,0≤wi<321≤ai,bi≤n,ai≠bi,0≤wi<32) — the endpoints of the ii-th edge and its weight. It's guaranteed there aren't any multiple edges, the graph is connected and there isn't any simple cycle of length greater than 33 which passes through the vertex 11.OutputOutput the answer modulo 109+7109+7.ExamplesInputCopy6 8
1 2 0
2 3 1
2 4 3
2 6 2
3 4 8
3 5 4
5 4 5
5 6 6
OutputCopy2
InputCopy7 9
1 2 0
1 3 1
2 3 9
2 4 3
2 5 4
4 5 7
3 6 6
3 7 7
6 7 8
OutputCopy1
InputCopy4 4
1 2 27
1 3 1
1 4 1
3 4 0
OutputCopy6NoteThe pictures below represent the graphs from examples.  In the first example; there aren't any nontrivial cycles with cost 00, so we can either remove or keep the only edge incident to the vertex 11.  In the second example, if we don't remove the edge 1−21−2, then there is a cycle 1−2−4−5−2−11−2−4−5−2−1 with cost 00; also if we don't remove the edge 1−31−3, then there is a cycle 1−3−2−4−5−2−3−11−3−2−4−5−2−3−1 of cost 00. The only valid subset consists of both edges.  In the third example, all subsets are valid except for those two in which both edges 1−31−3 and 1−41−4 are kept.

//package com.company;

import java.io.*;

import java.util.*;

public class Main {

    public static class Task {

        boolean insertVector(int[] base, int vector) {

            for (int i = 0; i < 5; i++) {

                if ((vector & (1 << i)) == 0) continue;

                if ((base[i] & (1 << i)) == 0) {

                    base[i] = vector;

                    for (int j = i + 1; j < 5; j++) if (base[j] > 0 && (base[i] & (1 << j)) != 0) {

                        base[i] ^= base[j];

                    }

                    for (int j = i - 1; j >= 0; j--) if ((base[j] & (1 << i)) != 0) {

                        base[j] ^= base[i];

                    }

                    return true;

                }

                vector ^= base[i];

            }

            return false;

        }

        public class ArrayHash {

            int[] array;

            public ArrayHash(int[] array) {

                this.array = Arrays.copyOf(array, array.length);

            }

            @Override

            public boolean equals(Object o) {

                if (this == o) return true;

                if (o == null || getClass() != o.getClass()) return false;

                ArrayHash arrayHash = (ArrayHash) o;

                return Arrays.equals(array, arrayHash.array);

            }

            @Override

            public int hashCode() {

                return Arrays.hashCode(array);

            }

        }

        public class DisjointSet {

            int[] arr;

            public DisjointSet(int n) {

                arr = new int[n];

                Arrays.fill(arr, -1);

            }

            int find(int x) {

                if (arr[x] < 0) return x;

                return arr[x] = find(arr[x]);

            }

            boolean union(int a, int b) {

                int ra = find(a), rb = find(b);

                if (ra == rb) return false;

                arr[ra] = rb;

                return true;

            }

        }

        public class Pair {

            int a, b;

            public Pair(int a, int b) {

                this.a = a;

                this.b = b;

            }

        }

        public class Triple {

            int a, b, c;

            public Triple(int a, int b, int c) {

                this.a = a;

                this.b = b;

                this.c = c;

            }

            public Triple(int[] z) {

                this.a = z[0];

                this.b = z[1];

                this.c = z[2];

            }

        }

        int S = 374;

        int[] xorValues;

        int[] root;

        int[] parent;

        int[][] inputEdges;

        int[][] dpVal;

        boolean[] off;

        List<Triple> additionalEdges;

        List<Pair>[] treeEdges;

        List<Integer>[] treeBasis;

        int[] treeBasisIndex;

        Map<ArrayHash, Integer> basisToIndex;

        List<ArrayHash> indexToBasis;

        int[][] basisTransition = new int[S][S];

        void dfs(int u, int p, int r, int val) {

            root[u] = r;

            parent[u] = p;

            xorValues[u] = val;

            for (Pair v: treeEdges[u]) if (v.a != p) {

                dfs(v.a, u, r, val ^ v.b);

            }

        }

        int mod = 1_000_000_007;

        int add(int a, int b) {

            int c = a + b;

            if (c >= mod) return c - mod;

            return c;

        }

        int getIndexOfBasis(int[] basis) {

            ArrayHash ar = new ArrayHash(basis);

            if (!basisToIndex.containsKey(ar)) {

                basisToIndex.put(ar, basisToIndex.size());

                indexToBasis.add(ar);

            }

            if (basisToIndex.size() > S) throw new RuntimeException();

            return basisToIndex.get(ar);

        }

        int merge(int basisIndex1, int basisIndex2) {

            if (basisTransition[basisIndex1][basisIndex2] == -2) {

                int[] basis1 = Arrays.copyOf(indexToBasis.get(basisIndex1).array, 5);

                int[] basis2 = Arrays.copyOf(indexToBasis.get(basisIndex2).array, 5);

                boolean valid = true;

                for (int b : basis2) {

                    if (b != 0) {

                        if (!insertVector(basis1, b)) {

                            valid = false;

                        }

                    }

                }

                if (valid) {

                    basisTransition[basisIndex1][basisIndex2] = basisTransition[basisIndex2][basisIndex1] = getIndexOfBasis(basis1);

                } else {

                    basisTransition[basisIndex1][basisIndex2] = basisTransition[basisIndex2][basisIndex1] = -1;

                }

            }

            return basisTransition[basisIndex1][basisIndex2];

        }

        public void solve(Scanner sc, PrintWriter pw) throws IOException {

            for (int i = 0; i < S; i++) {

                Arrays.fill(basisTransition[i], -2);

            }

            basisToIndex = new HashMap<>();

            indexToBasis = new ArrayList<>();

            int n = sc.nextInt();

            int m = sc.nextInt();

            xorValues = new int[n];

            root = new int[n];

            parent = new int[n];

            off = new boolean[n];

            Arrays.fill(off, true);

            treeEdges = new List[n];

            additionalEdges = new ArrayList<>();

            treeBasis = new List[n];

            treeBasisIndex = new int[n];

            getIndexOfBasis(new int[5]);

            DisjointSet djs = new DisjointSet(n);

            for (int i = 0; i < n; i++) {

                treeEdges[i] = new ArrayList<>();

                treeBasis[i] = new ArrayList<>();

            }

            inputEdges = new int[m][3];

            for (int i = 0; i < m; i++) {

                for (int j = 0; j < 3; j++) {

                    inputEdges[i][j] = sc.nextInt();

                }

            }

            for (int i = 0; i < m; i++) {

                inputEdges[i][0]--;

                inputEdges[i][1]--;

                if (inputEdges[i][0] == 0 || inputEdges[i][1] == 0) {

                    djs.union(inputEdges[i][0], inputEdges[i][1]);

                    treeEdges[inputEdges[i][0]].add(new Pair(inputEdges[i][1], inputEdges[i][2]));

                    treeEdges[inputEdges[i][1]].add(new Pair(inputEdges[i][0], inputEdges[i][2]));

                }

            }

            for (int i = 0; i < m; i++) {

                if (inputEdges[i][0] != 0 && inputEdges[i][1] != 0) {

                    if (djs.union(inputEdges[i][0], inputEdges[i][1])) {

                        treeEdges[inputEdges[i][0]].add(new Pair(inputEdges[i][1], inputEdges[i][2]));

                        treeEdges[inputEdges[i][1]].add(new Pair(inputEdges[i][0], inputEdges[i][2]));

                    } else {

                        additionalEdges.add(new Triple(inputEdges[i]));

                    }

                }

            }

            for (Pair p: treeEdges[0]) {

                off[p.a] = false;

                dfs(p.a, 0, p.a, p.b);

            }

            List<Triple> pairedTrees = new ArrayList<>();

            for (Triple tri: additionalEdges) {

                int a = tri.a;

                int b = tri.b;

                if (root[a] != root[b]) {

                    if (a != root[a] || b != root[b]) throw new RuntimeException();

                    pairedTrees.add(tri);

                    // across

                } else {

                    int cycle = tri.c ^ xorValues[a] ^ xorValues[b];

                    treeBasis[root[a]].add(cycle);

                }

            }

            List<List<Integer>> choicesForTree = new ArrayList<>();

            for (int i = 1; i < n; i++) if (root[i] == i) {

                int[] basis = new int[5];

                for (int cycle: treeBasis[i]) {

                    if (!insertVector(basis, cycle)) {

                        off[i] = true;

                    }

                }

                if (!off[i]) {

                    treeBasisIndex[i] = getIndexOfBasis(basis);

                }

            }

            for (Triple p: pairedTrees) {

                if (off[p.a] || off[p.b]) {

                    off[p.a] = off[p.b] = true;

                    continue;

                }

                off[p.a] = true;

                off[p.b] = true;

                int nr;

                if ((nr = merge(treeBasisIndex[p.a], treeBasisIndex[p.b])) != -1) {

                    List<Integer> choices = new ArrayList<>();

                    int[] basis = Arrays.copyOf(indexToBasis.get(nr).array, 5);

                    choices.add(nr);

                    choices.add(nr);

                    if (insertVector(basis, p.c ^ xorValues[p.a] ^ xorValues[p.b])) {

                        choices.add(getIndexOfBasis(basis));

                    }

                    choicesForTree.add(choices);

                }

            }

            for (int i = 1; i < n; i++) if (root[i] == i && !off[i]) {

                List<Integer> choice = new ArrayList<>();

                choice.add(treeBasisIndex[i]);

                choicesForTree.add(choice);

            }

            dpVal = new int[2][S]; // \sum_{i=0}^5 {5 \choose i}_2

            dpVal[0][0] = 1;

            int cur = 0, next = 1;

            for (List<Integer> choices: choicesForTree) {

                System.arraycopy(dpVal[cur], 0, dpVal[next], 0, S);

                for (int choice: choices) {

                    for (int i = 0; i < S; i++) if (dpVal[cur][i] > 0) {

                        int nr;

                        if ((nr = merge(i, choice)) != -1) {

                            dpVal[next][nr] = add(dpVal[next][nr], dpVal[cur][i]);

                        }

                    }

                }

                cur ^= 1;

                next ^= 1;

            }

            int total = 0;

            for (int i = 0; i < S; i++) total = add(total, dpVal[cur][i]);

            pw.println(total);

        }

    }

    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {

        Scanner sc = new Scanner(System.in);

//        Scanner sc = new Scanner(new FileInputStream("input"));

        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));

//        PrintWriter pw = new PrintWriter(new FileOutputStream("input"));

        Runtime runtime = Runtime.getRuntime();

        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();

        TIME_START = System.currentTimeMillis();

        Task t = new Task();

        t.solve(sc, pw);

        TIME_END = System.currentTimeMillis();

        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();

        pw.close();

        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);

        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");

    }

    static class Scanner {

        StringTokenizer st;

        BufferedReader br;

        public Scanner(InputStream s) {

            br = new BufferedReader(new InputStreamReader(s));

        }

        public Scanner(FileReader s) throws FileNotFoundException {

            br = new BufferedReader(s);

        }

        public String next() throws IOException {

            while (st == null || !st.hasMoreTokens())

                st = new StringTokenizer(br.readLine());

            return st.nextToken();

        }

        public int nextInt() throws IOException {

            return Integer.parseInt(next());

        }

        public long nextLong() throws IOException {

            return Long.parseLong(next());

        }

        public String nextLine() throws IOException {

            return br.readLine();

        }

        public double nextDouble() throws IOException {

            return Double.parseDouble(next());

        }

        public boolean ready() throws IOException {

            return br.ready();

        }

    }

}


D. Same GCDstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers aa and mm. Calculate the number of integers xx such that 0≤x<m0≤x<m and gcd(a,m)=gcd(a+x,m)gcd(a,m)=gcd(a+x,m).Note: gcd(a,b)gcd(a,b) is the greatest common divisor of aa and bb.InputThe first line contains the single integer TT (1≤T≤501≤T≤50) — the number of test cases.Next TT lines contain test cases — one per line. Each line contains two integers aa and mm (1≤a<m≤10101≤a<m≤1010).OutputPrint TT integers — one per test case. For each test case print the number of appropriate xx-s.ExampleInputCopy3
4 9
5 10
42 9999999967
OutputCopy6
1
9999999966
NoteIn the first test case appropriate xx-s are [0,1,3,4,6,7][0,1,3,4,6,7].In the second test case the only appropriate xx is 00.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.sort;

public class Main {
    static FastReader fastReader;
    static PrintWriter out;
    static int mod = 998244353;
    public static void main(String[] args) {
        fastReader = new FastReader();

//        int tt = 1;

        int tt = fastReader.nextInt();
        out = new PrintWriter(System.out);
        while(tt-- > 0) {
            long a = fastReader.nextLong();
            long m = fastReader.nextLong();
            long gcd = gcd(a,m);
            out.println(solve(m/gcd));
        }
        out.close();
    }

    private static long solve(long x) {
        long temp = x;
        for(long i = 2; i*i <=x ; i++){
            if(x% i == 0){
                temp -=(temp/i);
                while(x % i == 0){
                    x/=i;
                }

            }
        }
        if(x > 1){
            temp -=(temp/x);
        }
        return temp;
    }

    public static class Pair{
        int val;
        int index;

        public Pair(int val, int index) {
            this.val = val;
            this.index = index;
        }

        @Override
        public String toString() {
            return "Pair{" +
                    "val=" + val +
                    ", index=" + index +
                    '}';
        }
    }

    // constants
    static final int IBIG = 1000000007;
    static final int IMAX = 2147483647;
    static final long LMAX = 9223372036854775807L;
    static Random __r = new Random();
    static int[][] direction = new int[][]{{-1,-1}, {-1,0}, {-1,1},  {0,1}, {1,1},  {1,0},  {1,-1},  {0, -1}};

    // math util
    static int minof(int a, int b, int c) {
        return min(a, min(b, c));
    }

    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;
    }
    static char maxc(char a, char b){
        if(a > b){
            return a;
        }
        return b;
    }
    static long minof(long a, long b, long c) {
        return min(a, min(b, c));
    }

    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;
    }

    static int maxof(int a, int b, int c) {
        return max(a, max(b, c));
    }

    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;
    }

    static long maxof(long a, long b, long c) {
        return max(a, max(b, c));
    }

    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;
    }

    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;
    }

    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;
    }

    static int fli(double d) {
        return (int) d;
    }

    static int cei(double d) {
        return (int) ceil(d);
    }

    static long fll(double d) {
        return (long) d;
    }

    static long cel(double d) {
        return (long) ceil(d);
    }

    static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static int lcm(int a, int b) {
        return (a / gcd(a, b)) * b;
    }

    static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static long lcm(long a, long b) {
        return (a / gcd(a, b)) * b;
    }

    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) };
    }

    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) };
    }

    static int randInt(int min, int max) {
        return __r.nextInt(max - min + 1) + min;
    }

    static long mix(long x) {
        x += 0x9e3779b97f4a7c15L;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L;
        x = (x ^ (x >> 27)) * 0x94d049bb133111ebL;
        return x ^ (x >> 31);
    }

    public static boolean[] findPrimes(int limit) {
        assert limit >= 2;

        final boolean[] nonPrimes = new boolean[limit];
        nonPrimes[0] = true;
        nonPrimes[1] = true;

        int sqrt = (int) Math.sqrt(limit);
        for (int i = 2; i <= sqrt; i++) {
            if (nonPrimes[i])
                continue;
            for (int j = i; j < limit; j += i) {
                if (!nonPrimes[j] && i != j)
                    nonPrimes[j] = true;
            }
        }

        return nonPrimes;
    }

    // array util
    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;
        }
    }

    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;
        }
    }

    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;
        }
    }

    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;
        }
    }

    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;
        }
    }

    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;
        }
    }

    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;
        }
    }

    static void rsort(int[] a) {
        shuffle(a);
        sort(a);
    }

    static void rsort(long[] a) {
        shuffle(a);
        sort(a);
    }

    static void rsort(double[] a) {
        shuffle(a);
        sort(a);
    }

    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;
    }

    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;
    }

    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;
    }

    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;
    }

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(
                    new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] ria(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = Integer.parseInt(next());
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] rla(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = Long.parseLong(next());
            return a;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


A. New Year and Namingtime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputHappy new year! The year 2020 is also known as Year Gyeongja (경자년; gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of nn strings s1,s2,s3,…,sns1,s2,s3,…,sn and mm strings t1,t2,t3,…,tmt1,t2,t3,…,tm. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings xx and yy as the string that is obtained by writing down strings xx and yy one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings s1s1 and t1t1. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if n=3,m=4,s=n=3,m=4,s={"a", "b", "c"}, t=t= {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat.  You are given two sequences of strings of size nn and mm and also qq queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system?InputThe first line contains two integers n,mn,m (1≤n,m≤201≤n,m≤20).The next line contains nn strings s1,s2,…,sns1,s2,…,sn. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least 11 and at most 1010.The next line contains mm strings t1,t2,…,tmt1,t2,…,tm. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least 11 and at most 1010.Among the given n+mn+m strings may be duplicates (that is, they are not necessarily all different).The next line contains a single integer qq (1≤q≤20201≤q≤2020).In the next qq lines, an integer yy (1≤y≤1091≤y≤109) is given, denoting the year we want to know the name for.OutputPrint qq lines. For each line, print the name of the year as per the rule described above.ExampleInputCopy10 12
sin im gye gap eul byeong jeong mu gi gyeong
yu sul hae ja chuk in myo jin sa o mi sin
14
1
2
3
4
10
11
12
13
73
2016
2017
2018
2019
2020
OutputCopysinyu
imsul
gyehae
gapja
gyeongo
sinmi
imsin
gyeyu
gyeyu
byeongsin
jeongyu
musul
gihae
gyeongja
NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal.

import java.util.*;
import java.io.*;
public class NewYearAndNaming{
    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int m = scn.nextInt();

        String[] pre = new String[n];
        String[] suff = new String[m];

        for(int i=0;i<n;i++){
            pre[i] = scn.next();
        }
        for(int j=0;j<m;j++){
            suff[j] = scn.next();
        }

        int t = scn.nextInt();

        while(t>0){
            int year = scn.nextInt();
            int preidx = (year-1)%n;
            int suffidx = (year-1)%m;

            String name = pre[preidx] + suff[suffidx];
            System.out.println(name);
            t--;
        }
    }
}


C. Fadi and LCMtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday; Osama gave Fadi an integer XX, and Fadi was wondering about the minimum possible value of max(a,b)max(a,b) such that LCM(a,b)LCM(a,b) equals XX. Both aa and bb should be positive integers.LCM(a,b)LCM(a,b) is the smallest positive integer that is divisible by both aa and bb. For example, LCM(6,8)=24LCM(6,8)=24, LCM(4,12)=12LCM(4,12)=12, LCM(2,3)=6LCM(2,3)=6.Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?InputThe first and only line contains an integer XX (1≤X≤10121≤X≤1012).OutputPrint two positive integers, aa and bb, such that the value of max(a,b)max(a,b) is minimum possible and LCM(a,b)LCM(a,b) equals XX. If there are several possible such pairs, you can print any.ExamplesInputCopy2
OutputCopy1 2
InputCopy6
OutputCopy2 3
InputCopy4
OutputCopy1 4
InputCopy1
OutputCopy1 1

////package com.company;

import com.sun.source.tree.ArrayAccessTree;

import javax.swing.*;

import java.beans.IntrospectionException;

import java.math.BigInteger;

import java.util.*;

import java.io.*;

public class Main {

    static class pair implements Comparable<pair> {

        long a = 0;

        long b = 0;

        // int cnt;

        pair(long b, long a) {

            this.a = b;

            this.b = a;

            // cnt = x;

        }

        @Override

        public int compareTo(pair o) {

            if(this.a != o.a)

                return (int) (this.a - o.a);

            else

                return (int) (this.b - o.b);

        }

//        public boolean equals(Object o) {

//            if (o instanceof pair) {

//                pair p = (pair) o;

//                return p.a == a && p.b == b;

//            }

//            return false;

//        }

//

//        public int hashCode() {

//            return (Long.valueOf(a).hashCode()) * 31 + (Long.valueOf(b).hashCode());

//        }

    }

    static class FastReader {

        BufferedReader br;

        StringTokenizer st;

        public FastReader() {

            br = new BufferedReader(new InputStreamReader(System.in));

        }

        String next() {

            while (st == null || !st.hasMoreTokens()) {

                try {

                    st = new StringTokenizer(br.readLine());

                } catch (IOException e) {

                    e.printStackTrace();

                }

            }

            return st.nextToken();

        }

        int nextInt() {

            return Integer.parseInt(next());

        }

        long nextLong() {

            return Long.parseLong(next());

        }

        double nextDouble() {

            return Double.parseDouble(next());

        }

        String nextLine() {

            String str = "";

            try {

                str = br.readLine().trim();

            } catch (Exception e) {

                e.printStackTrace();

            }

            return str;

        }

    }

    static class FastWriter {

        private final BufferedWriter bw;

        public FastWriter() {

            this.bw = new BufferedWriter(new OutputStreamWriter(System.out));

        }

        public void prlong(Object object) throws IOException {

            bw.append("" + object);

        }

        public void prlongln(Object object) throws IOException {

            prlong(object);

            bw.append("\n");

        }

        public void close() throws IOException {

            bw.close();

        }

    }

    public static long gcd(long a, long b) {

        if (a == 0)

            return b;

        return gcd(b % a, a);

    }

    //HASHsET COLLISION AVOIDING CODE FOR STORING STRINGS

//    HashSet<Long> set = new HashSet<>();

//                for(int i = 0; i < s.length(); i++){

//        int b = 0;

//        long h = 1;

//        for(int j=i; j<s.length(); j++){

//            h = 131*h + (int)s.charAt(j);

//            b += bad[(int)(s.charAt(j)-'a')];

//            if(b<=k){

//                set.add(h);

//            }

//        }

//    }

//                System.out.println(set.size());

    //dsu

    static int[] par, rank;

    public static void dsu(int n) {

        par = new int[n];

        rank = new int[n];

        for (int i = 0; i < n; i++) {

            par[i] = i;

            rank[i] = 1;

        }

    }

    static int find(int u) {

        return par[u] == -1 ? -1 : par[u] == u ? u : (par[u] = find(par[u]));

    }

    static void union(int u, int v) {

        int a = find(u), b = find(v);

        if (a != b && a != -1 && b != -1) {

            par[b] = a;

            rank[a] += rank[b];

        }

    }

    static void disunion(int u, int v) {

        int a = find(u), b = find(v);

        if (a != -1 && a == b) {

            par[a] = -1;

        }

    }

    static class Calc_nCr {

        private final long[] fact;

        private final long[] invfact;

        private final int p;

        Calc_nCr(int n, int prime) {

            fact = new long[n + 5];

            invfact = new long[n + 5];

            p = prime;

            fact[0] = 1;

            for (int i = 1; i <= n; i++) {

                fact[i] = (i * fact[i - 1]) % p;

            }

            invfact[n] = pow(fact[n], p - 2, p);

            for (int i = n - 1; i >= 0; i--) {

                invfact[i] = (invfact[i + 1] * (i + 1)) % p;

            }

        }

        private long nCr(int n, int r) {

            if (r > n || n < 0 || r < 0) return 0;

            return (((fact[n] * invfact[r]) % p) * invfact[n - r]) % p;

        }

        private static long pow(long a, long b, int mod) {

            long result = 1;

            while (b > 0) {

                if ((b & 1L) == 1) {

                    result = (result * a) % mod;

                }

                a = (a * a) % mod;

                b >>= 1;

            }

            return result;

        }

    }

    static void sort(long[] a ) {

        ArrayList<Long> l = new ArrayList<>();

        for(long i: a) {

            l.add(i);

        }

        Collections.sort(l);

        for(int i =0;i<a.length;++i) {

            a[i] = l.get(i);

        }

    }

    public static void main(String[] args) {

        try {

            FastReader in = new FastReader();

            FastWriter out = new FastWriter();

            int mx=10000000;

            boolean isPrime[] = new boolean[mx+5]; int primeDiv[] = new int[mx+5];

            for (int i = 0; i <= mx; i++) {

                isPrime[i] = true;

            }

            for(int i =0;i<primeDiv.length;i++)

                primeDiv[i]=i;

            isPrime[0] = isPrime[1] = false;

            for (long i = 2; i <= mx; i++) {

                if (isPrime[(int)i]) {

                    for (long j = i*i; j <= mx; j += i) {

                        if (primeDiv[(int)j] == j) {

                            primeDiv[(int)j] = (int)i;

                        }

                        isPrime[(int)j] = false;

                    }

                }

            }

//            System.out.println(

//                    String.format("%.12f", x));

            int testCases=1;

//            int n =in.nextInt();

//            long  arr[]=new long[n];

//            ArrayList<Long>ans=new ArrayList<>();

//            for(int i =0;i<n;i++)

//

//

//            }       ans.add(in.nextLong());

//            Collections.sort(ans);

//            for(int i =0;i<n;i++)

//                arr[i]=ans.get(i);

            fl:

            while (testCases-- > 0) {

long x =in.nextLong();

long ans =x;

for(long i =1;i*i<x;i++)

{

    if(x%i==0&&gcd(x/i,i)==1)

    {

        ans=Math.min(ans,x/i);

    }

}

                System.out.println(x/ans+" "+ans);

            }

            out.close();

        } catch (Exception e) {

            return;

        }

    }

    static long comb(int r,int n)

    {

        long result;

        result = factorial(n)/(factorial(r)*factorial(n-r));

        return result;

    }

    static long factorial(int n) {

        int c;

        long result = 1;

        for (c = 1; c <= n; c++)

            result = result*c;

        return result;

    }

    static void  LongestPalindromicPrefix(String str,int lps[]){

//        String temp = str + '/';

//        str = reverse(str);

//        temp += str;

        String temp =str;

        int n = temp.length();

        for(int i = 1; i < n; i++)

        {

            int len = lps[i - 1];

            while (len > 0 && temp.charAt(len) !=

                    temp.charAt(i))

            {

                len = lps[len - 1];

            }

            if (temp.charAt(i) == temp.charAt(len))

            {

                len++;

            }

            lps[i] = len;

        }

//        return temp.substring(0, lps[n - 1]);

    }

    static String reverse(String input)

    {

        char[] a = input.toCharArray();

        int l, r = a.length - 1;

        for(l = 0; l < r; l++, r--)

        {

            char temp = a[l];

            a[l] = a[r];

            a[r] = temp;

        }

        return String.valueOf(a);

    }

}

/*

 *

 *　　┏┓　　　┏┓+ +

 *　┏┛┻━━━┛┻┓ + +

 *　┃　　　　　　　┃

 *　┃　　　━　　　┃ ++ + + +

 *   ████━████+

 *  ◥██◤　◥██◤ +

 *　┃　　　┻　　　┃

 *　┃　　　　　　　┃ + +

 *　┗━┓　　　┏━┛

 *　　　┃　　┃      JACKS PET FROM ANOTHER WORLD

 *　　　┃　　┃

 *　　　┃　 　 ┗━━━┓

 *　　　┃ 　　　　　　 ┣┓-------

 *　　  ┃ 　　　　　 　┏┛-------

 *　    ┗┓┓┏━┳┓┏┛ + + + +

 *　　　　┃┫┫　┃┫┫

 *　　　　┗┻┛　┗┻┛+ + + +

 */

//RULES

//TAKE INPUT AS LONG IN CASE OF SUM OR MULITPLICATION OR CHECK THE CONTSRaint of the array

//Always use stringbuilder of out.println for strinof out.println for string or high level output

// IMPORTANT TRs1 TO USE BRUTE FORCE TECHNIQUE TO SOLVE THE PROs1 OTHER CERTAIN LIMIT IS GIVENIT IS GIVEN

//Read minute details if coming wrong for no idea questions


A. Anu Has a Functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnu has created her own function ff: f(x,y)=(x|y)−yf(x,y)=(x|y)−y where || denotes the bitwise OR operation. For example, f(11,6)=(11|6)−6=15−6=9f(11,6)=(11|6)−6=15−6=9. It can be proved that for any nonnegative numbers xx and yy value of f(x,y)f(x,y) is also nonnegative. She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems.A value of an array [a1,a2,…,an][a1,a2,…,an] is defined as f(f(…f(f(a1,a2),a3),…an−1),an)f(f(…f(f(a1,a2),a3),…an−1),an) (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible?InputThe first line contains a single integer nn (1≤n≤1051≤n≤105).The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109). Elements of the array are not guaranteed to be different.OutputOutput nn integers, the reordering of the array with maximum value. If there are multiple answers, print any.ExamplesInputCopy4
4 0 11 6
OutputCopy11 6 4 0InputCopy1
13
OutputCopy13 NoteIn the first testcase; value of the array [11,6,4,0][11,6,4,0] is f(f(f(11,6),4),0)=f(f(9,4),0)=f(9,0)=9f(f(f(11,6),4),0)=f(f(9,4),0)=f(9,0)=9.[11,4,0,6][11,4,0,6] is also a valid answer.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class P1299A {

    public static void main(String[] args) {

        FastScanner s = new FastScanner();
        int n = s.nextInt();
        int[] arr = s.readArray(n);
        for (int i = 31; i >= 0; i--) {
            int count = 0;
            for (int j : arr) {
                if ((j & (1 << i)) > 0) {
                    count++;
                }
            }
            if (count == 1) {
                for (int j = 0; j < n; j++) {
                    if ((arr[j] & (1 << i)) > 0) {
                        int temp = arr[j];
                        arr[j] = arr[0];
                        arr[0] = temp;
                    }
                }
                break;
            }
        }
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < n; i++) {
            ans.append(arr[i]);
            if (i != n - 1) {
                ans.append(" ");
            }
        }
        System.out.println(ans);

    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}


G. Autocompletiontime limit per test7 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a set of strings SS. Each string consists of lowercase Latin letters.For each string in this set, you want to calculate the minimum number of seconds required to type this string. To type a string, you have to start with an empty string and transform it into the string you want to type using the following actions:  if the current string is tt, choose some lowercase Latin letter cc and append it to the back of tt, so the current string becomes t+ct+c. This action takes 11 second;  use autocompletion. When you try to autocomplete the current string tt, a list of all strings s∈Ss∈S such that tt is a prefix of ss is shown to you. This list includes tt itself, if tt is a string from SS, and the strings are ordered lexicographically. You can transform tt into the ii-th string from this list in ii seconds. Note that you may choose any string from this list you want, it is not necessarily the string you are trying to type. What is the minimum number of seconds that you have to spend to type each string from SS?Note that the strings from SS are given in an unusual way.InputThe first line contains one integer nn (1≤n≤1061≤n≤106).Then nn lines follow, the ii-th line contains one integer pipi (0≤pi<i0≤pi<i) and one lowercase Latin character cici. These lines form some set of strings such that SS is its subset as follows: there are n+1n+1 strings, numbered from 00 to nn; the 00-th string is an empty string, and the ii-th string (i≥1i≥1) is the result of appending the character cici to the string pipi. It is guaranteed that all these strings are distinct.The next line contains one integer kk (1≤k≤n1≤k≤n) — the number of strings in SS.The last line contains kk integers a1a1, a2a2, ..., akak (1≤ai≤n1≤ai≤n, all aiai are pairwise distinct) denoting the indices of the strings generated by above-mentioned process that form the set SS — formally, if we denote the ii-th generated string as sisi, then S=sa1,sa2,…,sakS=sa1,sa2,…,sak.OutputPrint kk integers, the ii-th of them should be equal to the minimum number of seconds required to type the string saisai.ExamplesInputCopy10
0 i
1 q
2 g
0 k
1 e
5 r
4 m
5 h
3 p
3 e
5
8 9 1 10 6
OutputCopy2 4 1 3 3
InputCopy8
0 a
1 b
2 a
2 b
4 a
4 b
5 c
6 d
5
2 3 4 7 8
OutputCopy1 2 2 4 4
NoteIn the first example; SS consists of the following strings: ieh, iqgp, i, iqge, ier.

import java.io.*;

import java.util.*;

public class Main{

	static int[][]children;

	static boolean[]S;

	static int[]smaller,ans;

	static int counter;

	static void dfs(int i) {

		smaller[i]=counter;

		if(S[i])counter++;

		for(int c=0;c<26;c++) {

			if(children[i][c]!=0) {

				dfs(children[i][c]);

			}

		}

	}

	static void dfs2(int i,int append,int autoC) {

		if(S[i]) {

			ans[i]=Math.min(append, autoC);

		}

		else {

			ans[i]=append;

		}

		if(autoC>append+1) {

			autoC=append+1;

		}

		for(int c=0;c<26;c++) {

			int nxt=children[i][c];

			if(nxt!=0) {

				dfs2(nxt, ans[i]+1, autoC+smaller[nxt]-smaller[i]);

			}

		}

	}

	public static void main(String[] args) throws IOException {

		MScanner sc=new MScanner(System.in);

		PrintWriter pw=new PrintWriter(System.out);

		int n=sc.nextInt();

		children=new int[n+1][26];

		for(int i=1;i<=n;i++) {

			int par=sc.nextInt();char c=sc.nextChar();

			children[par][c-'a']=i;

		}

		S=new boolean[n+1];

		int k=sc.nextInt();

		int[]ks=new int[k];

		for(int i=0;i<k;i++) {

			ks[i]=sc.nextInt();

			S[ks[i]]=true;

		}

		smaller=new int[n+1];

		dfs(0);

		ans=new int[n+1];

		dfs2(0, 0, 1);

		for(int i=0;i<k;i++)pw.println(ans[ks[i]]);

		pw.flush();

	}

	static class MScanner {

		StringTokenizer st;

		BufferedReader br;

		public MScanner(InputStream system) {

			br = new BufferedReader(new InputStreamReader(system));

		}

		public MScanner(String file) throws Exception {

			br = new BufferedReader(new FileReader(file));

		}

		public String next() throws IOException {

			while (st == null || !st.hasMoreTokens())

				st = new StringTokenizer(br.readLine());

			return st.nextToken();

		}

		public int[] takearr(int n) throws IOException {

	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();

	        return in;

		}

		public long[] takearrl(int n) throws IOException {

	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();

	        return in;

		}

		public Integer[] takearrobj(int n) throws IOException {

	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();

	        return in;

		}

		public Long[] takearrlobj(int n) throws IOException {

	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();

	        return in;

		}

		public String nextLine() throws IOException {

			return br.readLine();

		}

		public int nextInt() throws IOException {

			return Integer.parseInt(next());

		}

		public double nextDouble() throws IOException {

			return Double.parseDouble(next());

		}

		public char nextChar() throws IOException {

			return next().charAt(0);

		}

		public Long nextLong() throws IOException {

			return Long.parseLong(next());

		}

		public boolean ready() throws IOException {

			return br.ready();

		}

		public void waitForInput() throws InterruptedException {

			Thread.sleep(3000);

		}

	}

}


B. Bogosorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a1,a2,…,ana1,a2,…,an. Array is good if for each pair of indexes i<ji<j the condition j−aj≠i−aij−aj≠i−ai holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).For example, if a=[1,1,3,5]a=[1,1,3,5], then shuffled arrays [1,3,5,1][1,3,5,1], [3,5,1,1][3,5,1,1] and [5,3,1,1][5,3,1,1] are good, but shuffled arrays [3,1,5,1][3,1,5,1], [1,1,3,5][1,1,3,5] and [1,1,5,3][1,1,5,3] aren't.It's guaranteed that it's always possible to shuffle an array to meet this condition.InputThe first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.The first line of each test case contains one integer nn (1≤n≤1001≤n≤100) — the length of array aa.The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100).OutputFor each test case print the shuffled version of the array aa which is good.ExampleInputCopy3
1
7
4
1 1 3 5
6
3 2 1 5 6 4
OutputCopy7
1 5 1 3
2 4 6 1 3 5

/******************************************************************************

Welcome to GDB Online.

GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,

C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.

Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/

/******************************************************************************

Welcome to GDB Online.

GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,

C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.

Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/

/******************************************************************************

Welcome to GDB Online.

GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,

C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.

Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/

/* package codechef; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

public class Main

{

	public static void main (String[] args) throws java.lang.Exception

	{

		Scanner sc=new Scanner(System.in);

		int t=sc.nextInt();

		for(int p1=0;p1<t;p1++)

		{

		  int n=sc.nextInt();

		 int[] arr=new int[n];

		  int[] ans=new int[n];

		 for(int p=0;p<n;p++)

		 {

		     arr[p]=sc.nextInt();

		 }

		 Arrays.sort(arr);

		 for(int p=n-1;p>=0;p--)

		 {

		      ans[n-1-p]=arr[p];

		 }

		      for(int j=0;j<n;j++)

		      {

		          System.out.print(ans[j]+" ");

		      }

		      System.out.println(" ");

		  }

	}

}


B. Kuroni and Simple Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNow that Kuroni has reached 10 years old; he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence!We say that a string formed by nn characters '(' or ')' is simple if its length nn is even and positive, its first n2n2 characters are '(', and its last n2n2 characters are ')'. For example, the strings () and (()) are simple, while the strings )( and ()() are not simple.Kuroni will be given a string formed by characters '(' and ')' (the given string is not necessarily simple). An operation consists of choosing a subsequence of the characters of the string that forms a simple string and removing all the characters of this subsequence from the string. Note that this subsequence doesn't have to be continuous. For example, he can apply the operation to the string ')()(()))', to choose a subsequence of bold characters, as it forms a simple string '(())', delete these bold characters from the string and to get '))()'. Kuroni has to perform the minimum possible number of operations on the string, in such a way that no more operations can be performed on the remaining string. The resulting string does not have to be empty.Since the given string is too large, Kuroni is unable to figure out how to minimize the number of operations. Can you help him do it instead?A sequence of characters aa is a subsequence of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters.InputThe only line of input contains a string ss (1≤|s|≤10001≤|s|≤1000) formed by characters '(' and ')', where |s||s| is the length of ss.OutputIn the first line, print an integer kk  — the minimum number of operations you have to apply. Then, print 2k2k lines describing the operations in the following format:For each operation, print a line containing an integer mm  — the number of characters in the subsequence you will remove.Then, print a line containing mm integers 1≤a1<a2<⋯<am1≤a1<a2<⋯<am  — the indices of the characters you will remove. All integers must be less than or equal to the length of the current string, and the corresponding subsequence must form a simple string.If there are multiple valid sequences of operations with the smallest kk, you may print any of them.ExamplesInputCopy(()((
OutputCopy1
2
1 3
InputCopy)(
OutputCopy0
InputCopy(()())
OutputCopy1
4
1 2 5 6
NoteIn the first sample; the string is '(()(('. The operation described corresponds to deleting the bolded subsequence. The resulting string is '((('; and no more operations can be performed on it. Another valid answer is choosing indices 22 and 33, which results in the same final string.In the second sample, it is already impossible to perform any operations.

import java.io.*;

import java.lang.reflect.Array;

import java.math.BigInteger;

import java.util.*;

public class Main {

    static class Pair {

        double l,r;

        public Pair(double l,double r) {

            this.l=l;

            this.r=r;

        }

    }

    static int mod=1073741824;

    public static void main(String[] args) throws IOException

    {

        InputStream inputStream = System.in;

        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);

        OutputWriter out = new OutputWriter(outputStream);

        TaskC solver = new TaskC();

        solver.solve(1, in, out);

        out.close();

    }

    static class TaskC

    {

        public static void solve(int testNumber, InputReader in, OutputWriter out)

        {

            String s=in.readString();

            int n=s.length(),flag=0;

            ArrayList<Integer> al=new ArrayList<>();

            int l=0,r=n-1,k=0;

            while(l<r)

            {

                if(s.charAt(l)=='(' && s.charAt(r)==')')

                {

                    al.add(l+1);

                    al.add(r+1);

                    ++l;

                    --r;

                }

                else if(s.charAt(l)=='(' && s.charAt(r)!=')')

                {

                    --r;

                }

                else if(s.charAt(l)!='(' && s.charAt(r)==')')

                {

                    ++l;

                }

                else

                {

                    ++l;

                    --r;

                }

            }

            if(al.size()==0)

            {

                out.printLine(0);

            }

            else

            {

                out.printLine(1);

                out.printLine(al.size());

                Collections.sort(al);

                for(int i=0;i<al.size();++i)

                {

                    out.print(al.get(i)+" ");

                }

                out.printLine();

            }

        }

    }

    static class InputReader {

        private InputStream stream;

        private byte[] buf = new byte[1024];

        private int curChar;

        private int numChars;

        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {

            this.stream = stream;

        }

        public int read() {

            if (numChars == -1) {

                throw new InputMismatchException();

            }

            if (curChar >= numChars) {

                curChar = 0;

                try {

                    numChars = stream.read(buf);

                } catch (IOException e) {

                    throw new InputMismatchException();

                }

                if (numChars <= 0) {

                    return -1;

                }

            }

            return buf[curChar++];

        }

        public int readInt() {

            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;

        }

        public int[] nextIntArray(int arraySize) {

            int[] array = new int[arraySize];

            for (int i = 0; i < arraySize; i++) {

                array[i] = readInt();

            }

            return array;

        }

        public String readString() {

            int c = read();

            while (isSpaceChar(c)) {

                c = read();

            }

            StringBuilder res = new StringBuilder();

            do {

                if (Character.isValidCodePoint(c)) {

                    res.appendCodePoint(c);

                }

                c = read();

            } while (!isSpaceChar(c));

            return res.toString();

        }

        public boolean isNewLine(int c) {

            return c == '\n';

        }

        public String nextLine() {

            int c = read();

            StringBuilder result = new StringBuilder();

            do {

                result.appendCodePoint(c);

                c = read();

            } while (!isNewLine(c));

            return result.toString();

        }

        public long nextLong() {

            int c = read();

            while (isSpaceChar(c)) {

                c = read();

            }

            int sign = 1;

            if (c == '-') {

                sign = -1;

                c = read();

            }

            long result = 0;

            do {

                if (c < '0' || c > '9') {

                    throw new InputMismatchException();

                }

                result *= 10;

                result += c & 15;

                c = read();

            } while (!isSpaceChar(c));

            return result * sign;

        }

        public long[] nextLongArray(int arraySize) {

            long array[] = new long[arraySize];

            for (int i = 0; i < arraySize; i++) {

                array[i] = nextLong();

            }

            return array;

        }

        public double nextDouble() {

            double ret = 0, div = 1;

            byte c = (byte) read();

            while (c <= ' ') {

                c = (byte) read();

            }

            boolean neg = (c == '-');

            if (neg) {

                c = (byte) read();

            }

            do {

                ret = ret * 10 + c - '0';

            } while ((c = (byte) read()) >= '0' && c <= '9');

            if (c == '.') {

                while ((c = (byte) read()) >= '0' && c <= '9') {

                    ret += (c - '0') / (div *= 10);

                }

            }

            if (neg) {

                return -ret;

            }

            return ret;

        }

        public boolean isSpaceChar(int c) {

            if (filter != null) {

                return filter.isSpaceChar(c);

            }

            return isWhitespace(c);

        }

        public static boolean isWhitespace(int c) {

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;

        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);

        }

    }

    static class CP {

        static boolean isPrime(long n) {

            if (n <= 1)

                return false;

            if (n == 2 || n == 3)

                return true;

            if (n % 2 == 0 || n % 3 == 0)

                return false;

            for (int i = 5; (long) i * i <= n; i += 6) {

                if (n % i == 0 || n % (i + 2) == 0)

                    return false;

            }

            return true;

        }

        static String addChar(String s, int n, String ch) {

            String res =s+String.join("", Collections.nCopies(n, ch));

            return res;

        }

        static int ifnotPrime(int[] prime, int x) {

            return (prime[x / 64] & (1 << ((x >> 1) & 31)));

        }

        static void makeComposite(int[] prime, int x) {

            prime[x / 64] |= (1 << ((x >> 1) & 31));

        }

        static ArrayList<Integer> bitWiseSieve(int n) {

            ArrayList<Integer> al = new ArrayList<>();

            int prime[] = new int[n / 64 + 1];

            for (int i = 3; i * i <= n; i += 2) {

                if (ifnotPrime(prime, i) == 0)

                    for (int j = i * i, k = i << 1;

                         j < n; j += k)

                        makeComposite(prime, j);

            }

            al.add(2);

            for (int i = 3; i <= n; i += 2)

                if (ifnotPrime(prime, i) == 0)

                    al.add(i);

            return al;

        }

        public static long[] sort(long arr[]){

            List<Long> list = new ArrayList<>();

            for(long n : arr){list.add(n);}

            Collections.sort(list);

            for(int i=0;i<arr.length;i++){

                arr[i] = list.get(i);

            }

            return arr;

        }

        static ArrayList<Integer> sieve(long size) {

            ArrayList<Integer> pr = new ArrayList<Integer>();

            boolean prime[] = new boolean[(int) size];

            for (int i = 2; i < prime.length; i++) prime[i] = true;

            for (int i = 2; i * i < prime.length; i++) {

                if (prime[i]) {

                    for (int j = i * i; j < prime.length; j += i) {

                        prime[j] = false;

                    }

                }

            }

            for (int i = 2; i < prime.length; i++) if (prime[i]) pr.add(i);

            return pr;

        }

        static ArrayList<Integer> segmented_sieve(int l, int r, ArrayList<Integer> primes) {

            ArrayList<Integer> al=new ArrayList<>();

            if (l == 1) ++l;

            int max = r - l + 1;

            int arr[] = new int[max];

            for (int p : primes) {

                if (p * p <= r) {

                    int i = (l / p) * p;

                    if (i < l) i += p;

                    for (; i <= r; i += p) {

                        if (i != p) {

                            arr[i - l] = 1;

                        }

                    }

                }

            }

            for (int i = 0; i < max; ++i) {

                if (arr[i] == 0) {

                    al.add(l+i);

                }

            }

            return al;

        }

        static boolean isfPrime(long n, int iteration) {

            if (n == 0 || n == 1)

                return false;

            if (n == 2)

                return true;

            if (n % 2 == 0)

                return false;

            Random rand = new Random();

            for (int i = 0; i < iteration; i++) {

                long r = Math.abs(rand.nextLong());

                long a = r % (n - 1) + 1;

                if (modPow(a, n - 1, n) != 1)

                    return false;

            }

            return true;

        }

        static long modPow(long a, long b, long c) {

            long res = 1;

            for (int i = 0; i < b; i++) {

                res *= a;

                res %= c;

            }

            return res % c;

        }

        private static long binPower(long a, long l, long mod) {

            long res = 0;

            while (l > 0) {

                if ((l & 1) == 1) {

                    res = mulmod(res, a, mod);

                    ;

                    l >>= 1;

                }

                a = mulmod(a, a, mod);

            }

            return res;

        }

        private static long mulmod(long a, long b, long c) {

            long x = 0, y = a % c;

            while (b > 0) {

                if (b % 2 == 1) {

                    x = (x + y) % c;

                }

                y = (y * 2L) % c;

                b /= 2;

            }

            return x % c;

        }

        static long binary_Expo(long a, long b) {

            long res = 1;

            while (b != 0) {

                if ((b & 1) == 1) {

                    res *= a;

                    --b;

                }

                a *= a;

                b /= 2;

            }

            return res;

        }

        static long Modular_Expo(long a, long b) {

            long res = 1;

            while (b != 0) {

                if ((b & 1) == 1) {

                    res = (res * a) % 1000000007 ;

                    --b;

                }

                a = (a * a) % 1000000007;

                b /= 2;

            }

            return res%1000000007;

        }

        static int i_gcd(int a, int b) {

            while (true) {

                if (b == 0)

                    return a;

                int c = a;

                a = b;

                b = c % b;

            }

        }

        static long gcd(long a, long b) {

            if (b == 0)

                return a;

            return gcd(b, a % b);

        }

        static long ceil_div(long a, long b) {

            return (a + b - 1) / b;

        }

        static int getIthBitFromInt(int bits, int i) {

            return (bits >> (i - 1)) & 1;

        }

        private static TreeMap<Long, Long> primeFactorize(long n) {

            TreeMap<Long, Long> pf = new TreeMap<>(Collections.reverseOrder());

            long cnt = 0;

            long total = 1;

            for (long i = 2; (long) i * i <= n; ++i) {

                if (n % i == 0) {

                    cnt = 0;

                    while (n % i == 0) {

                        ++cnt;

                        n /= i;

                    }

                    pf.put(cnt, i);

                    //total*=(cnt+1);

                }

            }

            if (n > 1) {

                pf.put(1L, n);

                //total*=2;

            }

            return pf;

        }

        static long upper_Bound(long a[], long x) {

            long l = -1, r = a.length;

            while (l + 1 < r) {

                long m = (l + r) >>> 1;

                if (a[(int) m] <= x)

                    l = m;

                else

                    r = m;

            }

            return l + 1;

        }

        static int lower_Bound(ArrayList<Integer> a,int x) {

            int l = 0, r = a.size()-1,ans=-1,mid=0;

            while(l<=r)

            {

                mid=(l+r)>>1;

                if(a.get(mid)<=x)

                {

                    ans=mid;

                    l=mid+1;

                }

                else

                {

                    r=mid-1;

                }

            }

            return ans;

        }

        static int lower_Bound(int a[],int x) {

            int l = -1, r = a.length;

            while (l + 1 < r) {

                int m = (l + r) >>> 1;

                if (a[(int) m] >= x)

                    r = m;

                else

                    l = m;

            }

            return r;

        }

        static int upperBound(int a[], int x) {// x is the key or target value

            int l=-1,r=a.length;

            while(l+1<r) {

                int m=(l+r)>>>1;

                if(a[m]<=x) l=m;

                else r=m;

            }

            return l+1;

        }

        static int bsh(int  a[],int t) {

            int ans =-1;

            int i = 0, j = a.length - 1;

            while (i <= j) {

                int mid = i + (j - i) / 2;

                if (a[mid] > t) {

                    ans = mid;

                    //System.out.print("uppr "+a[ans]);

                    j=mid-1;

                }

                else{

                    //System.out.print("less "+a[mid]);

                    i=mid+1;

                }

            }

            return ans;

        }

        static int bsl(int a[],int t) {

            int ans =-1;

            int i = 0, j = a.length-1;

            while (i <= j) {

                int mid = i + (j - i) / 2;

                if (a[mid] <= t) {

                    ans = mid;

                    i=mid+1;

                } else if (a[mid] > t) {

                    j = mid - 1;

                }

            }

            return ans;

        }

        static int upper_Bound(ArrayList<Integer> a,int x)  //closest to the right

        {

            int l = 0, r = a.size()-1,ans=-1,mid=0;

            while(l<=r)

            {

                mid=(l+r)>>1;

                if(a.get(mid)>x)

                {

                    ans=mid;

                    r=mid-1;

                }

                else

                {

                    l=mid+1;

                }

            }

            return ans;

        }

        static boolean isSquarefactor(int x, int factor, int target) {

            int s = (int) Math.round(Math.sqrt(x));

            return factor * s * s == target;

        }

        static boolean isSquare(int x) {

            int s = (int) Math.round(Math.sqrt(x));

            return x * x == s;

        }

        static void sort(int a[]) // heap sort

        {

            PriorityQueue<Integer> q = new PriorityQueue<>();

            for (int i = 0; i < a.length; i++)

                q.add(a[i]);

            for (int i = 0; i < a.length; i++)

                a[i] = q.poll();

        }

        static void shuffle(int[] in) {

            for (int i = 0; i < in.length; i++) {

                int idx = (int) (Math.random() * in.length);

                fast_swap(in, idx, i);

            }

        }

        static boolean isPalindrome(String s)

        {

            StringBuilder sb=new StringBuilder(s);

            sb.reverse();

            if(s.equals(sb.toString()))

            {

                return true;

            }

            return false;

        }

        static int[] computeLps(String pat) {

            int len = 0, i = 1, m = pat.length();

            int lps[] = new int[m];

            lps[0] = 0;

            while (i < m) {

                if (pat.charAt(i) == pat.charAt(len)) {

                    ++len;

                    lps[i] = len;

                    ++i;

                } else {

                    if (len != 0) {

                        len = lps[len - 1];

                    } else {

                        lps[i] = len;

                        ++i;

                    }

                }

            }

            return lps;

        }

        static void kmp(String s, String pat,int[] prf,int[] st) {

            int n = s.length(), m = pat.length();

            int lps[] = computeLps(pat);

            int i = 0, j = 0;

            while (i < n) {

                if (s.charAt(i) == pat.charAt(j)) {

                    i++;

                    j++;

                    if (j == m) {

                        ++prf[(i-j)+m];

                        ++st[(i-j)+1];

                        j=lps[j - 1];

                    }

                } else {

                    if (j != 0) {

                        j = lps[j - 1];

                    } else {

                        i++;

                    }

                }

            }

        }

        static void reverse_ruffle_sort(int a[]) {

            shuffle(a);

            Arrays.sort(a);

            for (int l = 0, r = a.length - 1; l < r; ++l, --r)

                fast_swap(a, l, r);

        }

        static void ruffle_sort(int a[]) {

            shuffle(a);

            Arrays.sort(a);

        }

        static int getMax(int arr[], int n) {

            int mx = arr[0];

            for (int i = 1; i < n; i++)

                if (arr[i] > mx)

                    mx = arr[i];

            return mx;

        }

        static ArrayList<Long> primeFactors(long n) {

            ArrayList<Long> al = new ArrayList<>();

            al.add(1L);

            while (n % 2 == 0) {

                if(!al.contains(2L))

                {

                    al.add(2L);

                }

                n /= 2L;

            }

            for (int i = 3; (long) i * i <= n; i += 2) {

                while ((n % i == 0)) {

                    if(!al.contains((long)i))

                    {

                        al.add((long) i);

                    }

                    n /= i;

                }

            }

            if (n > 2) {

                if(!al.contains(n))

                {

                    al.add(n);

                }

            }

            return al;

        }

        static int[] z_function(String s) {

            int n = s.length(), z[] = new int[n];

            for (int i = 1, l = 0, r = 0; i < n; ++i) {

                if (i <= r)

                    z[i] = Math.min(z[i - l], r - i + 1);

                while (i + z[i] < n && s.charAt(z[i]) == s.charAt(i + z[i]))

                    ++z[i];

                if (i + z[i] - 1 > r) {

                    l = i;

                    r = i + z[i] - 1;

                }

            }

            return z;

        }

        static void swap(int a[], int idx1, int idx2) {

            a[idx1] += a[idx2];

            a[idx2] = a[idx1] - a[idx2];

            a[idx1] -= a[idx2];

        }

        static void fast_swap(int[] a, int idx1, int idx2) {

            if (a[idx1] == a[idx2])

                return;

            a[idx1] ^= a[idx2];

            a[idx2] ^= a[idx1];

            a[idx1] ^= a[idx2];

        }

        public static void fast_sort(long[] array) {

            ArrayList<Long> copy = new ArrayList<>();

            for (long i : array)

                copy.add(i);

            Collections.sort(copy);

            for (int i = 0; i < array.length; i++)

                array[i] = copy.get(i);

        }

        static int divCount(int n) {

            boolean hash[] = new boolean[n + 1];

            Arrays.fill(hash, true);

            for (int p = 2; p * p < n; p++)

                if (hash[p] == true)

                    for (int i = p * 2; i < n; i += p)

                        hash[i] = false;

            int total = 1;

            for (int p = 2; p <= n; p++) {

                if (hash[p]) {

                    int count = 0;

                    if (n % p == 0) {

                        while (n % p == 0) {

                            n = n / p;

                            count++;

                        }

                        total = total * (count + 1);

                    }

                }

            }

            return total;

        }

        static long binomialCoeff(long n,long k)

        {

            long res = 1;

            // Since C(n, k) = C(n, n-k)

            if (k > n - k)

                k = n - k;

            // Calculate value of

            // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]

            for (int i = 0; i < k; ++i) {

                res = (res*(n - i));

                res /= (i + 1);

            }

            return res;

        }

        static long c(long fact[],long n,long k)

        {

            if(k>n) return 0;

            long res=fact[(int)n];

            res= (int) ((res * Modular_Expo(fact[(int)k], mod - 2))%mod);

            res= (int) ((res * Modular_Expo(fact[(int)n - (int)k], mod - 2))%mod);

            return res%mod;

        }

        public static ArrayList<Long> getFactors(long x) {

            ArrayList<Long> facts=new ArrayList<>();

            for(long i=2;i*i<=x;++i)

            {

                if(x%i==0)

                {

                    facts.add(i);

                    if(i!=x/i)

                    {

                        facts.add(x/i);

                    }

                }

            }

            return facts;

        }

        public static HashMap<Integer, Integer> sortMap(HashMap<Integer, Integer> map) {

            List<Map.Entry<Integer,Integer>> list=new LinkedList<>(map.entrySet());

            Collections.sort(list,(o1,o2)->o2.getValue()-o1.getValue());

            HashMap<Integer,Integer> temp=new LinkedHashMap<>();

            for(Map.Entry<Integer,Integer> i:list)

            {

                temp.put(i.getKey(),i.getValue());

            }

            return temp;

        }

        public static long lcm(long l,long l2) {

            long val=CP.gcd(l,l2);

            return (l*l2)/val;

        }

    }

    static void py() {

        System.out.println("YES");

    }

    static void pn() {

        System.out.println("NO");

    }

    static class OutputWriter {

        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {

            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));

        }

        public OutputWriter(Writer writer) {

            this.writer = new PrintWriter(writer);

        }

        public void print(int[] array) {

            for (int i = 0; i < array.length; i++) {

                if (i != 0) {

                    writer.print(' ');

                }

                writer.print(array[i]);

            }

        }

        public void printLine(int[] array) {

            print(array);

            writer.println();

        }

        public void close() {

            writer.close();

        }

        public void printLine(long i) {

            writer.println(i);

        }

        public void printLine(int i) {

            writer.println(i);

        }

        public void printLine(char c)

        {

            writer.println(c);

        }

        public void print(Object... objects) {

            for (int i = 0; i < objects.length; i++) {

                if (i != 0) {

                    writer.print(' ');

                }

                writer.print(objects[i]);

            }

        }

        public void printLine(Object... objects) {

            print(objects);

            writer.println();

        }

    }

}


A. Dead Pixeltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputScreen resolution of Polycarp's monitor is a×ba×b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x,y)(x,y) (0≤x<a,0≤y<b0≤x<a,0≤y<b). You can consider columns of pixels to be numbered from 00 to a−1a−1, and rows — from 00 to b−1b−1.Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.InputIn the first line you are given an integer tt (1≤t≤1041≤t≤104) — the number of test cases in the test. In the next lines you are given descriptions of tt test cases.Each test case contains a single line which consists of 44 integers a,b,xa,b,x and yy (1≤a,b≤1041≤a,b≤104; 0≤x<a0≤x<a; 0≤y<b0≤y<b) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2a+b>2 (e.g. a=b=1a=b=1 is impossible).OutputPrint tt integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.ExampleInputCopy6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
OutputCopy56
6
442
1
45
80
NoteIn the first test case; the screen resolution is 8×88×8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.

import java.util.*;

import java.io.*;

import java.lang.*;

import java.math.*;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.StringTokenizer;

import java.math.BigInteger;

import static java.lang.Math.max;

public class HelloWorld {

    public static void main(String[] args) throws IOException {

        Scanner input=new Scanner(System.in);

        //static FastReader input=new FastReader();

        //static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        int t=input.nextInt();

        while(t>0) {

            int n,i,m,j,k,f;

            long count=0,a,b,x,y,s1,s2,s3,s4,s;

            a=input.nextInt();

            b=input.nextInt();

            x=input.nextInt();

            y=input.nextInt();

            x++;

            y++;

            //ArrayList<Long>ara= new ArrayList<>();

            //long ara[]=new long[i];

            //Collections.sort(ara1);

            s1=(x-1)*b;

            s2=a*(y-1);

            s3=(a-x)*b;

            s4=a*(b-y);

            s=max(s4,max(s3,max(s2,s1)));

            System.out.println(s);

            //System.out.println(s1+" "+s2+" "+s3+" "+s4);

            t--;

        }

        input.close();

        System.out.close();

    }

    /*static class FastReader

    {

        BufferedReader br;

        StringTokenizer st;

        public FastReader()

        {

            br = new BufferedReader(new InputStreamReader(System.in));

        }

        String next()

        {

            while (st == null || !st.hasMoreElements())

            {

                try

                {

                    st = new StringTokenizer(br.readLine());

                }

                catch (IOException  e)

                {

                    e.printStackTrace();

                }

            }

            return st.nextToken();

        }

        int nextInt()

        {

            return Integer.parseInt(next());

        }

        long nextLong()

        {

            return Long.parseLong(next());

        }

        double nextDouble()

        {

            return Double.parseDouble(next());

        }

        int[] readIntArray(int n)

        {

            int a[]=new int[n];

            for(int i=0;i<n;i++)a[i]=nextInt();

            return a;

        }

        long[] readLongArray(int n)

        {

            long a[]=new long[n];

            for(int i=0;i<n;i++)a[i]=nextLong();

            return a;

        }

        String nextLine()

        {

            String str = "";

            try

            {

                str = br.readLine();

            }

            catch (IOException e)

            {

                e.printStackTrace();

            }

            return str;

        }

    }*/

}


E. Superhero Battletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA superhero fights with a monster. The battle consists of rounds; each of which lasts exactly nn minutes. After a round ends, the next round starts immediately. This is repeated over and over again.Each round has the same scenario. It is described by a sequence of nn numbers: d1,d2,…,dnd1,d2,…,dn (−106≤di≤106−106≤di≤106). The ii-th element means that monster's hp (hit points) changes by the value didi during the ii-th minute of each round. Formally, if before the ii-th minute of a round the monster's hp is hh, then after the ii-th minute it changes to h:=h+dih:=h+di.The monster's initial hp is HH. It means that before the battle the monster has HH hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 00. Print -1 if the battle continues infinitely.InputThe first line contains two integers HH and nn (1≤H≤10121≤H≤1012, 1≤n≤2⋅1051≤n≤2⋅105). The second line contains the sequence of integers d1,d2,…,dnd1,d2,…,dn (−106≤di≤106−106≤di≤106), where didi is the value to change monster's hp in the ii-th minute of a round.OutputPrint -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer kk such that kk is the first minute after which the monster is dead.ExamplesInputCopy1000 6
-100 -200 -300 125 77 -4
OutputCopy9
InputCopy1000000000000 5
-1 0 0 0 0
OutputCopy4999999999996
InputCopy10 4
-3 -6 5 4
OutputCopy-1

			 import java.util.*;

			 import java.math.*;

			 import java.io.*;

			 import java.util.stream.Collectors;

	import java.text.DecimalFormat;

		       public class A{

		              static FastScanner scan=new FastScanner();

		              public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));

		static int n;

		static long PS[];

		static long MIN[];

		static boolean check(long x,long TH)

		{

			TH+=(PS[n-1]*((x-(x%n))/n));

		//	TH+=(PS[n-1]*((x-(x%n))/n));

			x=x%n;

			x--;

		//	out.println(x);

			if(x>=0)

			TH+=MIN[(int)x];

			return TH<=0;

		}

				public static void main(String[] args)  throws Exception

				     {

					int tt=1;

		//	System.out.println(check(0));

		//			tt=scan.nextInt();

			//	scan=new FastScanner("clumsy.in");

				//out=new PrintWriter("clumsy.out");

				outer:while(tt-->0)

					{

long H=scan.nextLong();

long TH=H;

						 n=scan.nextInt();

						 long arr[]=new long[n];

						 MIN=new long[n];

						 PS=new long[n];

						 for(int i=0;i<n;i++)

						 {

						 	arr[i]=scan.nextLong();

						 	TH+=arr[i];

						 	if(TH<=0)

						 	{

						 		out.println(i+1);

						 		out.close();

						 		return;

						 	}

						 }

						 PS[0]=arr[0];

						 for(int i=1;i<n;i++)

						 {

						 	PS[i]=arr[i];

						 	PS[i]+=PS[i-1];

						 }

						 MIN[0]=PS[0];

						 for(int i=1;i<n;i++)

						 {

						 	MIN[i]=Math.min(PS[i],MIN[i-1]);

						 }

						 if(PS[n-1]>=0)

						 {

						 	out.println(-1);

						 	out.close();

						 	return;

						 }

						 long l=1,r=(long)1e18,ans=(long)1e18+5;

//out.println(PS[n-1]);

//out.println(H)

					//out.println(check(4301,H));

						for(int i=0;i<n;i++)

						{

							TH=H;

							TH+=PS[i];

							l=1;

							r=(long)(1e12);

						//	if(i==2)

						//		out.println(TH+PS[n-1]);

							while(l<=r)

							{

								long mid=(l+r)/2;

								if(check(mid*n,TH))

								{

									//if(i==3)

									///out.println(mid*n);

									r=mid-1;

									ans=Math.min(ans,(i+1)+mid*n);

								}

								else l=mid+1;

							}

						}

						for(int i=0;i<n;i++)

						{

							TH=H;

							TH+=PS[i];

							l=1;

							r=(long)(1e9);

						//	if(i==2)

						//		out.println(TH+PS[n-1]);

							while(l<=r)

							{

								long mid=(l+r)/2;

								if(check(mid*n,TH))

								{

									//if(i==3)

									///out.println(mid*n);

									r=mid-1;

									ans=Math.min(ans,(i+1)+mid*n);

								}

								else l=mid+1;

							}

						}

						for(int i=0;i<n;i++)

						{

							TH=H;

							TH+=PS[i];

							l=1;

							r=(long)(1e7);

						//	if(i==2)

						//		out.println(TH+PS[n-1]);

							while(l<=r)

							{

								long mid=(l+r)/2;

								if(check(mid*n,TH))

								{

									//if(i==3)

									///out.println(mid*n);

									r=mid-1;

									ans=Math.min(ans,(i+1)+mid*n);

								}

								else l=mid+1;

							}

						}

						 out.println(ans);

	}

				out.close();

							}

										     static class FastScanner

								{

								    private int BS = 1 << 16;

								    private char NC = (char) 0;

								    private byte[] buf = new byte[BS];

								    private int bId = 0, size = 0;

								    private char c = NC;

								    private double cnt = 1;

								    private BufferedInputStream in;

								    public FastScanner() {

								        in = new BufferedInputStream(System.in, BS);

								    }

								    public FastScanner(String s) {

								        try {

								            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);

								        } catch (Exception e) {

								            in = new BufferedInputStream(System.in, BS);

								        }

								    }

								    private char getChar() {

								        while (bId == size) {

								            try {

								                size = in.read(buf);

								            } catch (Exception e) {

								                return NC;

								            }

								            if (size == -1) return NC;

								            bId = 0;

								        }

								        return (char) buf[bId++];

								    }

								    public int nextInt() {

								        return (int) nextLong();

								    }

								    public int[] nextInts(int N) {

								        int[] res = new int[N];

								        for (int i = 0; i < N; i++) {

								            res[i] = (int) nextLong();

								        }

								        return res;

								    }

								    public long[] nextLongs(int N) {

								        long[] res = new long[N];

								        for (int i = 0; i < N; i++) {

								            res[i] = nextLong();

								        }

								        return res;

								    }

								    public long nextLong() {

								        cnt = 1;

								        boolean neg = false;

								        if (c == NC) c = getChar();

								        for (; (c < '0' || c > '9'); c = getChar()) {

								            if (c == '-') neg = true;

								        }

								        long res = 0;

								        for (; c >= '0' && c <= '9'; c = getChar()) {

								            res = (res << 3) + (res << 1) + c - '0';

								            cnt *= 10;

								        }

								        return neg ? -res : res;

								    }

								    public double nextDouble() {

								        double cur = nextLong();

								        return c != '.' ? cur : cur + nextLong() / cnt;

								    }

								    public double[] nextDoubles(int N) {

								        double[] res = new double[N];

								        for (int i = 0; i < N; i++) {

								            res[i] = nextDouble();

								        }

								        return res;

								    }

								    public String next() {

								        StringBuilder res = new StringBuilder();

								        while (c <= 32) c = getChar();

								        while (c > 32) {

								            res.append(c);

								            c = getChar();

								        }

								        return res.toString();

								    }

								    public String nextLine() {

								        StringBuilder res = new StringBuilder();

								        while (c <= 32) c = getChar();

								        while (c != '\n') {

								            res.append(c);

								            c = getChar();

								        }

								        return res.toString();

								    }

								    public boolean hasNext() {

								        if (c > 32) return true;

								        while (true) {

								            c = getChar();

								            if (c == NC) return false;

								            else if (c > 32) return true;

								        }

								    }

								}

										     static class Pair implements Comparable<Pair>{

										            public long x, y,z;

										            public Pair(long x1, long y1,long z1) {

										                x=x1;

										                y=y1;

										                z=z1;

										            }

										             public Pair(long x1, long y1) {

										                x=x1;

										                y=y1;

										            }

										            @Override

										            public int hashCode() {

										                return (int)(x + 31 * y);

										            }

										            public String toString() {

										                return x + " " + y+" "+z;

										            }

										            @Override

										            public boolean equals(Object o){

										                if (o == this) return true;

										                if (o.getClass() != getClass()) return false;

										                Pair t = (Pair)o;

										                return t.x == x && t.y == y&&t.z==z;

										            }

										    public int compareTo(Pair o)

										    {

										return (int)(o.x-x);

										        }

										    }

										}