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.util.*;

//import java.lang.*;

import java.io.*;

public class Solution {

    static long[] fac;

    static int m = (int)1e9+7;

    static int c = 1;

    //    static int[] x = {1,-1,0,0};

//    static int[] y = {0,0,1,-1};

//    static int cycle_node;

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

        Reader.init(System.in);

        BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));

// Do not delete this //

//Uncomment this before using nCrModPFermat

//        fac = new long[200000 + 1];

//        fac[0] = 1;

//

//        for (int i = 1; i <= 200000; i++)

//            fac[i] = (fac[i - 1] * i % 1000000007);

//        long[] fact = factorial((int)1e6);

//        int te = Reader.nextInt();

        int te = 1;

        while(te-->0){

            int n = Reader.nextInt();

            int[] arr = new int[n];

            int[] complement = new int[n];

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

                arr[i] = Reader.nextInt();

                complement[i] = -arr[i]-1;

            }

            int[] pre = new int[n];

            int[] suf = new int[n];

            pre[0] = complement[0];

            suf[n-1] = complement[n-1];

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

                pre[i] = pre[i-1] & complement[i];

            }

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

                suf[i] = suf[i+1] & complement[i];

            }

            int max = -1;

            int idx = -1;

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

                int curr = arr[i]&(i-1>=0 ? pre[i-1] : -1)&(i+1<n ? suf[i+1] : -1);

                if(curr>max){

                    max = curr;

                    idx = i;

                }

            }

            output.write(arr[idx]+" ");

            for(int i = 0;i<=idx-1;i++) output.write(arr[i]+" ");

            for(int i = idx+1;i<n;i++) output.write(arr[i]+" ");

            output.write("\n");

        }

        output.close();

    }

    // Recursive function to return (x ^ n) % m

    static long modexp(long x, long n)

    {

        if (n == 0) {

            return 1;

        }

        else if (n % 2 == 0) {

            return modexp((x * x) % m, n / 2);

        }

        else {

            return (x * modexp((x * x) % m, (n - 1) / 2) % m);

        }

    }

    // Function to return the fraction modulo mod

    static long getFractionModulo(long a, long b)

    {

        long c = gcd(a, b);

        a = a / c;

        b = b / c;

        // (b ^ m-2) % m

        long  d = modexp(b, m - 2);

        // Final answer

        long ans = ((a % m) * (d % m)) % m;

        return ans;

    }

    public static boolean isP(String n){

        StringBuilder s1 = new StringBuilder(n);

        StringBuilder s2 = new StringBuilder(n);

        s2.reverse();

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

            if(s1.charAt(i)!=s2.charAt(i)) return false;

        }

        return true;

    }

    public static long[] factorial(int n){

        long[] factorials = new long[n+1];

        factorials[0] = 1;

        factorials[1] = 1;

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

            factorials[i] = (factorials[i-1]*i)%1000000007;

        }

        return factorials;

    }

    public static long numOfBits(long n){

        long ans = 0;

        while(n>0){

            n = n & (n-1);

            ans++;

        }

        return ans;

    }

    public static long ceilOfFraction(long x, long y){

        // ceil using integer division: ceil(x/y) = (x+y-1)/y

        // using double may go out of range.

        return (x+y-1)/y;

    }

    public static long power(long x, long y, long p) {

        long res = 1;

        x = x % p;

        while (y > 0) {

            if (y % 2 == 1) res = (res * x) % p;

            y = y >> 1;

            x = (x * x) % p;

        }

        return res;

    }

    // Returns n^(-1) mod p

    public static long modInverse(long n, long p) {

        return power(n, p - 2, p);

    }

    // Returns nCr % p using Fermat's

    // little theorem.

    public static long nCrModPFermat(int n, int r, int p) {

        if (n<r) return 0;

        if (r == 0) return 1;

        // Fill factorial array so that we

        // can find all factorial of r, n

        // and n-r

        return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;

    }

    public static long ncr(long n, long r) {

        long p = 1, k = 1;

        if (n - r < r) {

            r = n - r;

        }

        if (r != 0) {

            while (r > 0) {

                p *= n;

                k *= r;

                long m = gcd(p, k);

                p /= m;

                k /= m;

                n--;

                r--;

            }

        } else {

            p = 1;

        }

        return p;

    }

    public static boolean isPrime(long n){

        if (n <= 1) return false;

        if (n <= 3) return true;

        if (n % 2 == 0 || n % 3 == 0) return false;

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

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

                return false;

            }

        }

        return true;

    }

    public static int powOf2JustSmallerThanN(int n) {

        n |= n >> 1;

        n |= n >> 2;

        n |= n >> 4;

        n |= n >> 8;

        n |= n >> 16;

        return n ^ (n >> 1);

    }

    public static long merge(int[] arr, int[] aux, int low, int mid, int high)

    {

        int k = low, i = low, j = mid + 1;

        long inversionCount = 0;

        // while there are elements in the left and right runs

        while (i <= mid && j <= high)

        {

            if (arr[i] <= arr[j]) {

                aux[k++] = arr[i++];

            }

            else {

                aux[k++] = arr[j++];

                inversionCount += (mid - i + 1);    // NOTE

            }

        }

        // copy remaining elements

        while (i <= mid) {

            aux[k++] = arr[i++];

        }

        /* no need to copy the second half (since the remaining items

           are already in their correct position in the temporary array) */

        // copy back to the original array to reflect sorted order

        for (i = low; i <= high; i++) {

            arr[i] = aux[i];

        }

        return inversionCount;

    }

    public static long mergesort(int[] arr, int[] aux, int low, int high)

    {

        if (high <= low) {        // if run size <= 1

            return 0;

        }

        int mid = (low + ((high - low) >> 1));

        long inversionCount = 0;

        // recursively split runs into two halves until run size <= 1,

        // then merges them and return up the call chain

        // split/merge left half

        inversionCount += mergesort(arr, aux, low, mid);

        // split/merge right half

        inversionCount += mergesort(arr, aux, mid + 1, high);

        // merge the two half runs

        inversionCount += merge(arr, aux, low, mid, high);

        return inversionCount;

    }

    public static void reverseArray(int[] arr,int start, int end) {

        int temp;

        while (start < end) {

            temp = arr[start];

            arr[start] = arr[end];

            arr[end] = temp;

            start++;

            end--;

        }

    }

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

        if(a==0){

            return b;

        }

        return gcd(b%a,a);

    }

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

        if(a>b) return a/gcd(b,a) * b;

        return b/gcd(a,b) * a;

    }

    public static long largeExponentMod(long x,long y,long mod){

        // computing (x^y) % mod

        x%=mod;

        long ans = 1;

        while(y>0){

            if((y&1)==1){

                ans = (ans*x)%mod;

            }

            x = (x*x)%mod;

            y = y >> 1;

        }

        return ans;

    }

    public static boolean[] numOfPrimesInRange(long L, long R){

        boolean[] isPrime = new boolean[(int) (R-L+1)];

        Arrays.fill(isPrime,true);

        long lim = (long) Math.sqrt(R);

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

            for (long j = Math.max(i * i, (L + i - 1) / i * i); j <= R; j += i){

                isPrime[(int) (j - L)] = false;

            }

        }

        if (L == 1) isPrime[0] = false;

        return isPrime;

    }

    public static ArrayList<Long> primeFactors(long n){

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

        if(n%2==0){

            factorization.add(2L);

        }

        while(n%2==0){

            n/=2;

        }

        if(n%3==0){

            factorization.add(3L);

        }

        while(n%3==0){

            n/=3;

        }

        if(n%5==0){

            factorization.add(5L);

        }

        while(n%5==0){

//            factorization.add(5L);

            n/=5;

        }

        int[] increments = {4, 2, 4, 2, 4, 6, 2, 6};

        int i = 0;

        for (long d = 7; d * d <= n; d += increments[i++]) {

            if(n%d==0){

                factorization.add(d);

            }

            while (n % d == 0) {

//                factorization.add(d);

                n /= d;

            }

            if (i == 8)

                i = 0;

        }

        if (n > 1)

            factorization.add(n);

        return factorization;

    }

}

class DSU {

    int[] size, parent;

    int n;

    public DSU(int n){

        this.n = n;

        size = new int[n];

        parent = new int[n];

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

            parent[i] = i;

            size[i] = 1;

        }

    }

    public int find(int u){

        if(parent[u]==u){

            return u;

        }

        return parent[u] = find(parent[u]);

    }

    public void merge(int u, int v){

        u = find(u);

        v = find(v);

        if(u!=v){

            if(size[u]>size[v]){

                parent[v] = u;

                size[u] += size[v];

            }

            else{

                parent[u] = v;

                size[v] += size[u];

            }

        }

    }

}

class Reader {

    static BufferedReader reader;

    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */

    static void init(InputStream input) {

        reader = new BufferedReader(

                new InputStreamReader(input) );

        tokenizer = new StringTokenizer("");

    }

    /** get next word */

    static String next() throws IOException {

        while ( ! tokenizer.hasMoreTokens() ) {

            //TODO add check for eof if necessary

            tokenizer = new StringTokenizer(

                    reader.readLine() );

        }

        return tokenizer.nextToken();

    }

    static String nextLine() throws IOException {

        return reader.readLine();

    }

    static int nextInt() throws IOException {

        return Integer.parseInt( next() );

    }

    static long nextLong() throws IOException{

        return Long.parseLong(next() );

    }

    static double nextDouble() throws IOException {

        return Double.parseDouble( next() );

    }

}

class SegTree{

    int n; // array size

    // Max size of tree

    public int[] tree;

    public SegTree(int n){

        this.n = n;

        tree = new int[4*n];

    }

    // function to build the tree

    void update(int pos, int val, int s, int e, int treeIdx){

        if(pos < s || pos > e){

            return;

        }

        if(s == e){

            tree[treeIdx] = val;

            return;

        }

        int mid = s + (e - s) / 2;

        update(pos, val, s, mid, 2 * treeIdx);

        update(pos, val, mid + 1, e, 2 * treeIdx + 1);

        tree[treeIdx] = tree[2 * treeIdx] + tree[2 * treeIdx + 1];

    }

    void update(int pos, int val){

        update(pos, val, 1, n, 1);

    }

    int query(int qs, int qe, int s, int e, int treeIdx){

        if(qs <= s && qe >= e){

            return tree[treeIdx];

        }

        if(qs > e || qe < s){

            return 0;

        }

        int mid = s + (e - s) / 2;

        int subQuery1 = query(qs, qe, s, mid, 2 * treeIdx);

        int subQuery2 = query(qs, qe, mid + 1, e, 2 * treeIdx + 1);

        int res = subQuery1 + subQuery2;

        return res;

    }

    int query(int l, int r){

        return query(l, r, 1, n, 1);

    }

}


B. CopyCopyCopyCopyCopytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEhab has an array aa of length nn. He has just enough free time to make a new array consisting of nn copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?A sequence aa is a subsequence of an array bb if aa can be obtained from bb by deletion of several (possibly, zero or all) elements. The longest increasing subsequence of an array is the longest subsequence such that its elements are ordered in strictly increasing order.InputThe first line contains an integer tt — the number of test cases you need to solve. The description of the test cases follows.The first line of each test case contains an integer nn (1≤n≤1051≤n≤105) — the number of elements in the array aa.The second line contains nn space-separated integers a1a1, a2a2, ……, anan (1≤ai≤1091≤ai≤109) — the elements of the array aa.The sum of nn across the test cases doesn't exceed 105105.OutputFor each testcase, output the length of the longest increasing subsequence of aa if you concatenate it to itself nn times.ExampleInputCopy2
3
3 2 1
6
3 1 4 1 5 9
OutputCopy3
5
NoteIn the first sample; the new array is [3,2,1,3,2,1,3,2,1][3,2,1,3,2,1,3,2,1]. The longest increasing subsequence is marked in bold.In the second sample, the longest increasing subsequence will be [1,3,4,5,9][1,3,4,5,9].

import java.util.*;

public class CopyCopyCopyCopyCopy1325B

{

    public static void main(String args[])

    {

        Scanner scan = new Scanner(System.in);

        int t = scan.nextInt();

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

        {

            int n = scan.nextInt();

            Integer[] arr = new Integer[n];

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

            {

                arr[j] = scan.nextInt();

            }

            int count = 0;

            Set<Integer> set = new HashSet<Integer>(Arrays.asList(arr));

            for(Integer x : set)

            {

                // System.out.print(x + " ");

                count++;

            }

            System.out.println(count);

        }

        scan.close();

    }

}


A. Angry Studentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's a walking tour day in SIS.Winter; so tt groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P":   "A" corresponds to an angry student  "P" corresponds to a patient student Such string describes the row from the last to the first student.Every minute every angry student throws a snowball at the next student. Formally, if an angry student corresponds to the character with index ii in the string describing a group then they will throw a snowball at the student that corresponds to the character with index i+1i+1 (students are given from the last to the first student). If the target student was not angry yet, they become angry. Even if the first (the rightmost in the string) student is angry, they don't throw a snowball since there is no one in front of them.Let's look at the first example test. The row initially looks like this: PPAP. Then, after a minute the only single angry student will throw a snowball at the student in front of them, and they also become angry: PPAA. After that, no more students will become angry.Your task is to help SIS.Winter teachers to determine the last moment a student becomes angry for every group.InputThe first line contains a single integer tt — the number of groups of students (1≤t≤1001≤t≤100). The following 2t2t lines contain descriptions of groups of students.The description of the group starts with an integer kiki (1≤ki≤1001≤ki≤100) — the number of students in the group, followed by a string sisi, consisting of kiki letters "A" and "P", which describes the ii-th group of students.OutputFor every group output single integer — the last moment a student becomes angry.ExamplesInputCopy1
4
PPAP
OutputCopy1
InputCopy3
12
APPAPPPAPPPP
3
AAP
3
PPA
OutputCopy4
1
0
NoteIn the first test; after 11 minute the state of students becomes PPAA. After that, no new angry students will appear.In the second tets, state of students in the first group is:   after 11 minute — AAPAAPPAAPPP  after 22 minutes — AAAAAAPAAAPP  after 33 minutes — AAAAAAAAAAAP  after 44 minutes all 1212 students are angry In the second group after 11 minute, all students are angry.

//ღ(¯`◕‿◕´¯) ♫ ♪ ♫ YuSuF ♫ ♪ ♫ (¯`◕‿◕´¯)ღ

import java.util.*;

public class Angry_Students {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int t = in.nextInt();

        while (t-- > 0) {

            int n = in.nextInt();

            char ar[] = in.next().toCharArray();

            int counter = 0;

            while (true) {

                boolean hasAP = false;

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

                    if (ar[i] == 'A' && ar[i + 1] == 'P') {

                        hasAP = true;

                        ar[i + 1] = 'A';

                        i++;

                    }

                }

                if (!hasAP) {

                    break;

                } else {

                    counter++;

                }

            }

            System.out.println(counter);

        }

    }

}


B. Count Subrectanglestime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array aa of length nn and array bb of length mm both consisting of only integers 00 and 11. Consider a matrix cc of size n×mn×m formed by following rule: ci,j=ai⋅bjci,j=ai⋅bj (i.e. aiai multiplied by bjbj). It's easy to see that cc consists of only zeroes and ones too.How many subrectangles of size (area) kk consisting only of ones are there in cc?A subrectangle is an intersection of a consecutive (subsequent) segment of rows and a consecutive (subsequent) segment of columns. I.e. consider four integers x1,x2,y1,y2x1,x2,y1,y2 (1≤x1≤x2≤n1≤x1≤x2≤n, 1≤y1≤y2≤m1≤y1≤y2≤m) a subrectangle c[x1…x2][y1…y2]c[x1…x2][y1…y2] is an intersection of the rows x1,x1+1,x1+2,…,x2x1,x1+1,x1+2,…,x2 and the columns y1,y1+1,y1+2,…,y2y1,y1+1,y1+2,…,y2.The size (area) of a subrectangle is the total number of cells in it.InputThe first line contains three integers nn, mm and kk (1≤n,m≤40000,1≤k≤n⋅m1≤n,m≤40000,1≤k≤n⋅m), length of array aa, length of array bb and required size of subrectangles.The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤10≤ai≤1), elements of aa.The third line contains mm integers b1,b2,…,bmb1,b2,…,bm (0≤bi≤10≤bi≤1), elements of bb.OutputOutput single integer — the number of subrectangles of cc with size (area) kk consisting only of ones.ExamplesInputCopy3 3 2
1 0 1
1 1 1
OutputCopy4
InputCopy3 5 4
1 1 1
1 1 1 1 1
OutputCopy14
NoteIn first example matrix cc is:  There are 44 subrectangles of size 22 consisting of only ones in it:  In second example matrix cc is:

import static java.lang.Math.max;

import static java.lang.Math.min;

import static java.lang.Math.abs;

import java.util.*;

import java.io.*;

import java.math.*;

public class B_Count_Subrectangles {

    static long mod = Long.MAX_VALUE;

    public static void main(String[] args) {

        OutputStream outputStream = System.out;

        PrintWriter out = new PrintWriter(outputStream);

        FastReader f = new FastReader();

        int t = 1;

        while(t-- > 0){

            solve(f, out);

        }

        out.close();

    }

    public static void solve(FastReader f, PrintWriter out) {

        int n = f.nextInt();

        int m = f.nextInt();

        int k = f.nextInt();

        int a[] = f.nextArray(n);

        int b[] = f.nextArray(m);

        ArrayList<Pair> arrli = allDivisors(n, m, k);

        long ans = 0;

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

            ans += func(a, arrli.get(i).row) * func(b, arrli.get(i).col);

        }

        out.println(ans);

    }

    static class Pair {

        int row;

        int col;

        public Pair(int row, int col) {

            this.row = row;

            this.col = col;

        }

    }

    public static int func(int arr[], int x) {

        int n = arr.length;

        int ans = 0;

        int count1 = 0;

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

            if(arr[i] == 1) {

                count1++;

            }

        }

        if(count1 == x) {

            ans++;

        }

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

            count1 += arr[i];

            count1 -= arr[i-x];

            if(count1 == x) {

                ans++;

            }

        }

        return ans;

    }

    // Sort an array

    public static void sort(int arr[]) {

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

        for(int i: arr) {

            al.add(i);

        }

        Collections.sort(al);

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

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

        }

    }

    // Find all divisors of n

    public static ArrayList<Pair> allDivisors(int n, int m, int k) {

        ArrayList<Pair> arrli = new ArrayList<>();

        for(int i = 1; i*i <= k; i++) {

            if(k%i == 0) {

                if(i <= n && k/i <= m) {

                    arrli.add(new Pair(i, k/i));

                }

                if(i != k/i && k/i <= n && i <= m) {

                    arrli.add(new Pair(k/i, i));

                }

            }

        }

        return arrli;

    }

    // Check if n is prime or not

    public static boolean isPrime(int 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; i*i <= n; i += 6) {

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

                return false;

            }

        }

        return true;

    }

    // Find gcd of a and b

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

        long dividend = a > b ? a : b;

        long divisor =  a < b ? a : b;

        while(divisor > 0) {

            long reminder = dividend % divisor;

            dividend = divisor;

            divisor = reminder;

        }

        return dividend;

    }

    // Find lcm of a and b

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

        long lcm = gcd(a, b);

        long hcf = (a * b) / lcm;

        return hcf;

    }

    // Find factorial in O(n) time

    public static long fact(int n) {

        long res = 1;

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

            res = res * i;

        }

        return res;

    }

    // Find power in O(logb) time

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

        long res = 1;

        while(b > 0) {

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

                res = (res * a)%mod;

            }

            a = (a * a)%mod;

            b >>= 1;

        }

        return res;

    }

    // Find nCr

    public static long nCr(int n, int r) {

        if(r < 0 || r > n) {

            return 0;

        }

        long ans = fact(n) / (fact(r) * fact(n-r));

        return ans;

    }

    // Find nPr

    public static long nPr(int n, int r) {

        if(r < 0 || r > n) {

            return 0;

        }

        long ans = fact(n) / fact(r);

        return ans;

    }

    // sort all characters of a string

    public static String sortString(String inputString) {

        char tempArray[] = inputString.toCharArray();

        Arrays.sort(tempArray);

        return new String(tempArray);

    }

    // User defined class for fast I/O

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

        }

        boolean hasNext() {

            if (st != null && st.hasMoreTokens()) {

                return true;

            }

            String tmp;

            try {

                br.mark(1000);

                tmp = br.readLine();

                if (tmp == null) {

                    return false;

                }

                br.reset();

            } catch (IOException e) {

                return false;

            }

            return true;

        }

        int nextInt() {

            return Integer.parseInt(next());

        }

        long nextLong() {

            return Long.parseLong(next());

        }

        double nextDouble() {

            return Double.parseDouble(next());

        }

        float nextFloat() {

            return Float.parseFloat(next());

        }

        boolean nextBoolean() {

            return Boolean.parseBoolean(next());

        }

        String nextLine() {

            String str = "";

            try {

                str = br.readLine();

            }

            catch (IOException e) {

                e.printStackTrace();

            }

            return str;

        }

        int[] nextArray(int n) {

            int[] a = new int[n];

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

                a[i] = nextInt();

            }

            return a;

        }

    }

}

/**

Dec  Char                           Dec  Char     Dec  Char     Dec  Char

---------                           ---------     ---------     ----------

  0  NUL (null)                      32  SPACE     64  @         96  `

  1  SOH (start of heading)          33  !         65  A         97  a

  2  STX (start of text)             34  "         66  B         98  b

  3  ETX (end of text)               35  #         67  C         99  c

  4  EOT (end of transmission)       36  $         68  D        100  d

  5  ENQ (enquiry)                   37  %         69  E        101  e

  6  ACK (acknowledge)               38  &         70  F        102  f

  7  BEL (bell)                      39  '         71  G        103  g

  8  BS  (backspace)                 40  (         72  H        104  h

  9  TAB (horizontal tab)            41  )         73  I        105  i

 10  LF  (NL line feed, new line)    42  *         74  J        106  j

 11  VT  (vertical tab)              43  +         75  K        107  k

 12  FF  (NP form feed, new page)    44  ,         76  L        108  l

 13  CR  (carriage return)           45  -         77  M        109  m

 14  SO  (shift out)                 46  .         78  N        110  n

 15  SI  (shift in)                  47  /         79  O        111  o

 16  DLE (data link escape)          48  0         80  P        112  p

 17  DC1 (device control 1)          49  1         81  Q        113  q

 18  DC2 (device control 2)          50  2         82  R        114  r

 19  DC3 (device control 3)          51  3         83  S        115  s

 20  DC4 (device control 4)          52  4         84  T        116  t

 21  NAK (negative acknowledge)      53  5         85  U        117  u

 22  SYN (synchronous idle)          54  6         86  V        118  v

 23  ETB (end of trans. block)       55  7         87  W        119  w

 24  CAN (cancel)                    56  8         88  X        120  x

 25  EM  (end of medium)             57  9         89  Y        121  y

 26  SUB (substitute)                58  :         90  Z        122  z

 27  ESC (escape)                    59  ;         91  [        123  {

 28  FS  (file separator)            60  <         92  \        124  |

 29  GS  (group separator)           61  =         93  ]        125  }

 30  RS  (record separator)          62  >         94  ^        126  ~

 31  US  (unit separator)            63  ?         95  _        127  DEL

 */

// (a/b)%mod == (a * moduloInverse(b)) % mod;

// moduloInverse(b) = power(b, mod-2);


F. Maximum White Subtreetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree consisting of nn vertices. A tree is a connected undirected graph with n−1n−1 edges. Each vertex vv of this tree has a color assigned to it (av=1av=1 if the vertex vv is white and 00 if the vertex vv is black).You have to solve the following problem for each vertex vv: what is the maximum difference between the number of white and the number of black vertices you can obtain if you choose some subtree of the given tree that contains the vertex vv? The subtree of the tree is the connected subgraph of the given tree. More formally, if you choose the subtree that contains cntwcntw white vertices and cntbcntb black vertices, you have to maximize cntw−cntbcntw−cntb.InputThe first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of vertices in the tree.The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤10≤ai≤1), where aiai is the color of the ii-th vertex.Each of the next n−1n−1 lines describes an edge of the tree. Edge ii is denoted by two integers uiui and vivi, the labels of vertices it connects (1≤ui,vi≤n,ui≠vi(1≤ui,vi≤n,ui≠vi).It is guaranteed that the given edges form a tree.OutputPrint nn integers res1,res2,…,resnres1,res2,…,resn, where resiresi is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex ii.ExamplesInputCopy9
0 1 1 1 0 0 0 0 1
1 2
1 3
3 4
3 5
2 6
4 7
6 8
5 9
OutputCopy2 2 2 2 2 1 1 0 2
InputCopy4
0 0 1 0
1 2
1 3
1 4
OutputCopy0 -1 1 -1
NoteThe first example is shown below:The black vertices have bold borders.In the second example; the best subtree for vertices 2,32,3 and 44 are vertices 2,32,3 and 44 correspondingly. And the best subtree for the vertex 11 is the subtree consisting of vertices 11 and 33.

import java.util.*;
import java.io.*;

public class maximumWhiteSubtreeCF {

    private static class Kattio extends PrintWriter {
		private BufferedReader r;
		private StringTokenizer st;
		public Kattio() { this(System.in, System.out); }
		public Kattio(InputStream i, OutputStream o) {
			super(o);
			r = new BufferedReader(new InputStreamReader(i));
		}
		public Kattio(String problemName) throws IOException {
			super(problemName + ".out");
			r = new BufferedReader(new FileReader(problemName + ".in"));
		}
		public String next() {
			try {
				while (st == null || !st.hasMoreTokens())
					st = new StringTokenizer(r.readLine());
				return st.nextToken();
			} catch (Exception e) { }
			return null;
		}
		public int nextInt() { return Integer.parseInt(next()); }
		public double nextDouble() { return Double.parseDouble(next()); }
		public long nextLong() { return Long.parseLong(next()); }
	}

    public static Hashtable <Integer, ArrayList<Integer>> tree;
    public static int [] dpDown;
    public static int [] dpUp;
    public static void main (String[]args) throws IOException {
        Kattio scan = new Kattio ();

        int nodeNumber = scan.nextInt();
        int edgeNumber = nodeNumber - 1;

        int [] nodeColors = new int [nodeNumber];

        for (int i = 0; i < nodeNumber; i++) {
            nodeColors[i] = scan.nextInt();
        }

        tree = new Hashtable <Integer, ArrayList<Integer>>();

        for (int i = 0; i < nodeNumber; i++) {
            tree.put(i, new ArrayList<Integer>());
        }

        for (int i = 0; i < edgeNumber; i++) {
            int firstNode = scan.nextInt() - 1;
            int secondNode = scan.nextInt() - 1;

            ArrayList<Integer> temp = tree.get(firstNode);
            temp.add(secondNode);
            tree.put(firstNode, temp);

            ArrayList<Integer> tempTwo = tree.get(secondNode);
            tempTwo.add(firstNode);
            tree.put(secondNode, tempTwo);
        }

        dpDown = new int [nodeNumber];

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

            // Current node is white
            if (nodeColors[i] == 1) {
                dpDown[i] = 1;
            }
            // Current node is black
            else {
                dpDown[i] = -1;
            }
        }

        dpDownDFS(0, -1);

        dpUp = new int [nodeNumber];
        dpUp[0] = 0;

        for (int i = 0; i < tree.get(0).size(); i++) {
            dpUpDFS(tree.get(0).get(i), 0);
        }

        for (int i = 0; i < nodeNumber; i++) {
            int curAnswer = 0;

            if (dpDown[i] == -1) {
                curAnswer = -1;

                if (dpUp[i] > 0) {
                    curAnswer += dpUp[i];
                }
            }
            else {
                curAnswer = dpDown[i];

                if (dpUp[i] > 0) {
                    curAnswer += dpUp[i];
                }
            }

            System.out.print(curAnswer + " ");
        }
    }

    public static void dpUpDFS (int currentNode, int parentNode) {
        int curAnswer = 0;

        if (dpUp[parentNode] > 0) {
            curAnswer = dpUp[parentNode];
        }

        if (dpDown[currentNode] == -1) {
            curAnswer += dpDown[parentNode];
        }
        else {
            if (dpDown[parentNode] - dpDown[currentNode] > 0) {
                curAnswer += dpDown[parentNode] - dpDown[currentNode];
            }
            else {
                curAnswer -= (dpDown[currentNode] - dpDown[parentNode]);
            }
        }

        dpUp[currentNode] = curAnswer;

        ArrayList<Integer> temp = tree.get(currentNode);

        for (int i = 0; i < temp.size(); i++) {
            int childNode = temp.get(i);
            if (childNode == parentNode) {
                continue;
            }

            dpUpDFS(childNode, currentNode);
        }
    }

    public static void dpDownDFS (int currentNode, int parentNode) {
        ArrayList<Integer> temp = tree.get(currentNode);

        for (int i = 0; i < temp.size(); i++) {
            int childNode = temp.get(i);

            if (childNode == parentNode) {
                continue;
            }

            dpDownDFS(childNode, currentNode);
            if (dpDown[childNode] > 0) {
                dpDown[currentNode] += dpDown[childNode];
            }
        }
    }
}


B. Just Eat It!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday; Yasser and Adel are at the shop buying cupcakes. There are nn cupcake types, arranged from 11 to nn on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type ii is an integer aiai. There are both tasty and nasty cupcakes, so the tastiness can be positive, zero or negative.Yasser, of course, wants to try them all, so he will buy exactly one cupcake of each type.On the other hand, Adel will choose some segment [l,r][l,r] (1≤l≤r≤n)(1≤l≤r≤n) that does not include all of cupcakes (he can't choose [l,r]=[1,n][l,r]=[1,n]) and buy exactly one cupcake of each of types l,l+1,…,rl,l+1,…,r.After that they will compare the total tastiness of the cupcakes each of them have bought. Yasser will be happy if the total tastiness of cupcakes he buys is strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel's choice.For example, let the tastinesses of the cupcakes be [7,4,−1][7,4,−1]. Yasser will buy all of them, the total tastiness will be 7+4−1=107+4−1=10. Adel can choose segments [7],[4],[−1],[7,4][7],[4],[−1],[7,4] or [4,−1][4,−1], their total tastinesses are 7,4,−1,117,4,−1,11 and 33, respectively. Adel can choose segment with tastiness 1111, and as 1010 is not strictly greater than 1111, Yasser won't be happy :(Find out if Yasser will be happy after visiting the shop.InputEach test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). The description of the test cases follows.The first line of each test case contains nn (2≤n≤1052≤n≤105).The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109), where aiai represents the tastiness of the ii-th type of cupcake.It is guaranteed that the sum of nn over all test cases doesn't exceed 105105.OutputFor each test case, print "YES", if the total tastiness of cupcakes Yasser buys will always be strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel's choice. Otherwise, print "NO".ExampleInputCopy3
4
1 2 3 4
3
7 4 -1
3
5 -5 5
OutputCopyYES
NO
NO
NoteIn the first example; the total tastiness of any segment Adel can choose is less than the total tastiness of all cupcakes.In the second example; Adel will choose the segment [1,2][1,2] with total tastiness 1111, which is not less than the total tastiness of all cupcakes, which is 1010.In the third example, Adel can choose the segment [3,3][3,3] with total tastiness of 55. Note that Yasser's cupcakes' total tastiness is also 55, so in that case, the total tastiness of Yasser's cupcakes isn't strictly greater than the total tastiness of Adel's cupcakes.

    import com.sun.security.jgss.GSSUtil;

    import java.io.*;

    import java.lang.reflect.Array;

    import java.util.*;

    import java.util.HashSet;

    import java.util.StringTokenizer;

    public class cf799 {

        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 print(Object object) throws IOException {

                bw.append("" + object);

            }

            public void println(Object object) throws IOException {

                print(object);

                bw.append("\n");

            }

            public void close() throws IOException {

                bw.close();

            }

        }

        public static int fast(){

            FastReader sc = new FastReader();

            return sc.nextInt();

        }

        static  boolean isPrime(int num)

        {

            if(num<=1)

            {

                return true;

            }

            for(int i=2;i*i<=num;i++)

            {

                if((num%i)==0)

                    return  false;

            }

            return true;

        }

        static void gfdfg(HashMap<Integer,ArrayList<Integer>> map,boolean[] arrr){

            for(int i=2;i<=100000;i++){

                if(!arrr[i]){

                    map.putIfAbsent(i,new ArrayList<>());

                    map.get(i).add(i);

                    for(int j=i*2;j<=100000;j+=i){

                        arrr[j]=true;

                        // air[j]=i;

                        //ekaur[j]+=1;

                        map.putIfAbsent(j,new ArrayList<>());

                        map.get(j).add(i);

                    }

                }

            }

        }

        public static void main(String[] args) {

            try {

                FastReader sc = new FastReader();

                FastWriter out = new FastWriter();

int t=sc.nextInt();

while (t-->0) {

    int n = sc.nextInt();

    int[] arr = new int[n];

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

    arr[i]=sc.nextInt();

}

long count1=0;

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

    count1+=arr[i];

}

long count2=kadane(arr,0,n-1);

long count3=Math.max(count2,kadane(arr,1,n));

if(count1>count3){

    System.out.println("YES");

}else{

    System.out.println("NO");

}

}

            }catch (Exception e) {

                return;

            }

        }

        public static long kadane(int [] arr,int i,int j){

            long ans=0;

            long max=0;

            for(int f=i;f<j;f++){

                max+=arr[f];

                if(max<0){

                    max=0;

                }

                ans=Math.max(ans,max);

            }

            return ans;

        }

        public static long gfg(int [] arr,long num){

            int n=arr.length;

            long submin=Long.MIN_VALUE;

            long sum=0;

            int count=0;

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

                if(sum==num){

                    submin=Math.max(submin,count);

                    sum=arr[i];

                    count=1;

                }

                else if(sum>num){

                    submin=-1;

                    break;

                }else{

                    sum+=arr[i];

                    count++;

                }

            }

            if(sum==num){

                submin=Math.max(submin,count);

            }

            if(sum>num){

                submin=-1;

            }

            return submin==Long.MIN_VALUE?-1:submin;

        }

        private static int abcdefghijklmopqrstuvwxyz(int max) {

            int temp=max;

            int num=0;

            while(temp>0){

                num++;

                temp=temp>>1;

            }

            int ans=0;

            int count=1;

            while(num-->0){

                ans+=count;

                count*=2;

            }

            return ans;

        }

        private static void reverse(int[] lowsum) {

            for(int i=lowsum.length-1;i>0;i--){

              lowsum[i]=lowsum[i-1];

            }

            lowsum[0]=0;

        }

        private static void ff(ArrayList<Integer> ar , ArrayList<Integer> ar2) {

            for (Integer integer : ar2) {

                int count = 0;

                int num = integer;

                while (num % 2 == 0) {

                    count++;

                    num /= 2;

                }

                ar.add(count);

            }

        }

        public static int lcm(int a,int b){

            return (a/gcd(a,b))*b;

        }

        private static int gcd(int a, int b) {

            if(b==0)return a;

            return gcd(b,a%b);

        }

        static class Pair {

            int a;

            int b;

            Pair(int a, int b) {

                this.a = a;

                this.b = b;

            }

        }

    }


C. Cow and Messagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However; Bessie is sure that there is a secret message hidden inside.The text is a string ss of lowercase Latin letters. She considers a string tt as hidden in string ss if tt exists as a subsequence of ss whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices 11, 33, and 55, which form an arithmetic progression with a common difference of 22. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of SS are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!For example, in the string aaabb, a is hidden 33 times, b is hidden 22 times, ab is hidden 66 times, aa is hidden 33 times, bb is hidden 11 time, aab is hidden 22 times, aaa is hidden 11 time, abb is hidden 11 time, aaab is hidden 11 time, aabb is hidden 11 time, and aaabb is hidden 11 time. The number of occurrences of the secret message is 66.InputThe first line contains a string ss of lowercase Latin letters (1≤|s|≤1051≤|s|≤105) — the text that Bessie intercepted.OutputOutput a single integer  — the number of occurrences of the secret message.ExamplesInputCopyaaabb
OutputCopy6
InputCopyusaco
OutputCopy1
InputCopylol
OutputCopy2
NoteIn the first example; these are all the hidden strings and their indice sets:   a occurs at (1)(1), (2)(2), (3)(3)  b occurs at (4)(4), (5)(5)  ab occurs at (1,4)(1,4), (1,5)(1,5), (2,4)(2,4), (2,5)(2,5), (3,4)(3,4), (3,5)(3,5)  aa occurs at (1,2)(1,2), (1,3)(1,3), (2,3)(2,3)  bb occurs at (4,5)(4,5)  aab occurs at (1,3,5)(1,3,5), (2,3,4)(2,3,4)  aaa occurs at (1,2,3)(1,2,3)  abb occurs at (3,4,5)(3,4,5)  aaab occurs at (1,2,3,4)(1,2,3,4)  aabb occurs at (2,3,4,5)(2,3,4,5)  aaabb occurs at (1,2,3,4,5)(1,2,3,4,5)  Note that all the sets of indices are arithmetic progressions.In the second example, no hidden string occurs more than once.In the third example, the hidden string is the letter l.

/* 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

{

   //------------------------------------------------input class---------------------------------------//

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

        String nextLine() {

            String str = "";

            try{ str = br.readLine();  }

            catch (IOException e){  e.printStackTrace(); }

            return str;

        }

    }

    //-------------------------------------------segment tree-----------------------------------------//

    static int[] segment;

    static void constructSt(int n, int[] arr){

        segment = new int[n*4+1];

        formSt(arr, 1,0,n-1);

    }

    public static void formSt(int[] arr, int node, int s, int e){

        if(s==e){

            segment[node]= arr[s];

            return;

        }

        formSt(arr, node*2,s,s+(e-s)/2);

        formSt(arr, node*2+1,s+(e-s)/2+1,e);

        segment[node]=Math.max(segment[node*2],segment[node*2+1]);

    }

    public static int findMax( int node, int s, int e,int l , int r){

        if(l>e||s>r) return -1;

        if(s==e) return segment[node];

        if(l<=s&&r>=e) return segment[node];

        int mid = s+(e-s)/2;

        return Math.max(findMax(node*2,s,mid,l,r),findMax(node*2+1,mid+1,e,l,r));

    }

    //-----------------------------------------dsu-----------------------------------------//

    static int[] parent,rank;

    public static void dsu(int n){

        parent = new int[n]; rank = new int[n];

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

    }

    public static int find(int i){

        if(i==parent[i] ) return i;

        return parent[i]=find(parent[i]);

    }

    public static void merge(int i, int j){

        if(rank[i]>=rank[j]){

            rank[i]+=rank[j];

            parent[j]=i;

        }

        else {

            rank[j]+=rank[i];

            parent[i]=j;

        }

    }

    //-------------------------------------------topological sort--------------------------------------//

     public static int[] topo(List<List<Integer>> a , int n , int[] in){

        int[] ans = new int[n+1];

        PriorityQueue<Integer> p = new PriorityQueue<>((x,y)->a.get(x).size()-a.get(y).size());

        for(int i =1;i<=n;i++) if(in[i]==0) p.add(i);

        int i =1;

        while(p.size()>0){

            int e = p.poll();

            ans[i++]= e;

            for(int temp : a.get(e)){

                in[temp]--;

                if(in[temp]==0)

                p.add(temp);

            }

        }

        return ans;

    }

    //-------------------------------------------max--------------------------------------------------//

    public static int max (int a, int b){

        return a>=b?a:b;

    }

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

        return a>=b?a:b;

    }

     public static int max (int a, int b, int c){

        return Math.max(a,Math.max(b,c));

    }

     public static long max (long a, long b, long c){

        return Math.max(a,Math.max(b,c));

    }

    //------------------------------------------min---------------------------------------------------//

     public static int min (int a, int b){

        return a<=b?a:b;

    }

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

        return a<=b?a:b;

    }

     public static int min (int a, int b, int c){

        return Math.min(a,Math.min(b,c));

    }

     public static long min (long a, long b, long c){

        return Math.min(a,Math.min(b,c));

    }

    //----------------------------------------- gcd-----------------------------------------//

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

        if(a==0) return b;

        if(b==0 ) return a;

        if(a<b) return gcd(b%a,a);

        return gcd(a%b,b);

    }

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

        if(a==0) return b;

        if(b==0 ) return a;

        if(a<b) return gcd(b%a,a);

        return gcd(a%b,b);

    }

    //-------------------------------------lcm------------------------------------------------------//

    public static int lcm(int a, int b){

        return (a*b)/gcd(a,b);

    }

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

        return (a*b)/gcd(a,b);

    }

    //---------------------------------------------binary search--------------------------------------//

    public static  int binary(int arr[], int x)

    {

        int l = 0, r = arr.length - 1;

        while (l <= r) {

            int m = l + (r - l) / 2;

            if (arr[m] == x) return m;

            if (arr[m] < x) l = m + 1;

            else r = m - 1;

        }

        return -1;

    }

     public static int binary(long arr[], long x)

    {

        int l = 0, r = arr.length - 1;

        while (l <= r) {

            int m = l + (r - l) / 2;

            if (arr[m] == x)  return m;

            if (arr[m] < x)   l = m + 1;

            else  r = m - 1;

        }

        return -1;

    }

    //---------------------------------------helping methods---------------------------------------------//

    //------------------------------------------main------------------------------------------------------//

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

	{

	 OutputStream outputStream =System.out;

        PrintWriter out =new PrintWriter(outputStream);

        FastReader sc =new FastReader();

        int t =1;

        while(t-->0){

            char[] a = sc.nextLine().toCharArray();

            int n  = a.length;

            long[][] dp = new long[26][26];

            long[] freq = new long[26];

            long max =0;

            for(char e: a){

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

                     dp[e-'a'][i]+= freq[i];

                     max = max(dp[e-'a'][i],max);

                }

                freq[e-'a']++;

                max= max(max, freq[e-'a']);

            }

            out.print(max);

          out.print("\n");

        }

	    out.close();

		// your code goes here"

	}

}

 class pair

    {

        long x;

        long y;

        public pair(long x , long y)

        {

            this.x= x;

            this.y= y;

        }

    }

class node{

    int x, y;

     public node(int x , int y)

        {

            this.x= x;

            this.y= y;

        }

}

class solution{

    }


B. Infinite Prefixestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given string ss of length nn consisting of 0-s and 1-s. You build an infinite string tt as a concatenation of an infinite number of strings ss, or t=ssss…t=ssss… For example, if s=s= 10010, then t=t= 100101001010010...Calculate the number of prefixes of tt with balance equal to xx. The balance of some string qq is equal to cnt0,q−cnt1,qcnt0,q−cnt1,q, where cnt0,qcnt0,q is the number of occurrences of 0 in qq, and cnt1,qcnt1,q is the number of occurrences of 1 in qq. The number of such prefixes can be infinite; if it is so, you must say that.A prefix is a string consisting of several first letters of a given string, without any reorders. An empty prefix is also a valid prefix. For example, the string "abcd" has 5 prefixes: empty string, "a", "ab", "abc" and "abcd".InputThe first line contains the single integer TT (1≤T≤1001≤T≤100) — the number of test cases.Next 2T2T lines contain descriptions of test cases — two lines per test case. The first line contains two integers nn and xx (1≤n≤1051≤n≤105, −109≤x≤109−109≤x≤109) — the length of string ss and the desired balance, respectively.The second line contains the binary string ss (|s|=n|s|=n, si∈{0,1}si∈{0,1}).It's guaranteed that the total sum of nn doesn't exceed 105105.OutputPrint TT integers — one per test case. For each test case print the number of prefixes or −1−1 if there is an infinite number of such prefixes.ExampleInputCopy4
6 10
010010
5 3
10101
1 0
0
2 0
01
OutputCopy3
0
1
-1
NoteIn the first test case; there are 3 good prefixes of tt: with length 2828, 3030 and 3232.

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    BInfinitePrefixes solver = new BInfinitePrefixes();
    int testCount = Integer.parseInt(in.next());
    for (int i = 1; i <= testCount; i++)
      solver.solve(i, in, out);
    out.close();
  }

  static class BInfinitePrefixes {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      int n = in.nextInt();
      int x = in.nextInt();
      String s = in.nextString();
      int sum = 0;
      for (int i = 0; i < n; i++) {
        if (s.charAt(i) == '0') {
          sum++;
        } else {
          sum--;
        }
      }

      int cnt = 0;
      int res = 0;

      for (int i = 0; i < n; i++) {
        if (sum == 0) {
          if (cnt == x) {
            out.println(-1);
            return;
          }
        } else {
          if ((long) (x - cnt) * sum >= 0 && (x - cnt) % sum == 0) {
            res++;
          }
        }

        if (s.charAt(i) == '0') {
          cnt++;
        } else {
          cnt--;
        }
      }
      out.println(res);
    }

  }

  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 close() {
      writer.close();
    }

    public void println(int i) {
      writer.println(i);
    }

  }

  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 UnknownError();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new UnknownError();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public int nextInt() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new UnknownError();
        }
        res *= 10;
        res += c - '0';
        c = read();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public String nextString() {
      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 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 String next() {
      return nextString();
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);

    }

  }
}


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.*;

public class practice {

    public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

        int t = scan.nextInt();

        while (t --> 0) {

            int a = scan.nextInt();
            int b = scan.nextInt();
            int x = scan.nextInt();
            int y = scan.nextInt();
            int max = 0;

            if ((x == 0 && y == 0) || (x == 0 && y == b - 1) || (x == a - 1 && y == 0) || (x == a - 1 && y == b - 1)) {

                max = Math.max(a * (b - 1), (a - 1) * b);
            } else if (x == 0 || x == a - 1) {

                int len = Math.max(y, (b - 1) - y);
                max = Math.max(a * len, (a - 1) * b);
            } else if (y == 0 || y == b - 1) {

                int len = Math.max(x, (a - 1) - x);
                max = Math.max(b * len, a * (b - 1));
            } else {

                int i = x * b;
                int j = a * y;
                int k = ((a - 1) - x) * b;
                int l = a * ((b - 1) - y);
                max = Math.max(i, Math.max(j, Math.max(k, l)));
            }

            System.out.println(max);
        }

        scan.close();
    }
}


C. Perfect Keyboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row; where all 2626 lowercase Latin letters will be arranged in some order.Polycarp uses the same password ss on all websites where he is registered (it is bad, but he doesn't care). He wants to assemble a keyboard that will allow to type this password very easily. He doesn't like to move his fingers while typing the password, so, for each pair of adjacent characters in ss, they should be adjacent on the keyboard. For example, if the password is abacaba, then the layout cabdefghi... is perfect, since characters a and c are adjacent on the keyboard, and a and b are adjacent on the keyboard. It is guaranteed that there are no two adjacent equal characters in ss, so, for example, the password cannot be password (two characters s are adjacent).Can you help Polycarp with choosing the perfect layout of the keyboard, if it is possible?InputThe first line contains one integer TT (1≤T≤10001≤T≤1000) — the number of test cases.Then TT lines follow, each containing one string ss (1≤|s|≤2001≤|s|≤200) representing the test case. ss consists of lowercase Latin letters only. There are no two adjacent equal characters in ss.OutputFor each test case, do the following:  if it is impossible to assemble a perfect keyboard, print NO (in upper case, it matters in this problem);  otherwise, print YES (in upper case), and then a string consisting of 2626 lowercase Latin letters — the perfect layout. Each Latin letter should appear in this string exactly once. If there are multiple answers, print any of them. ExampleInputCopy5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza
OutputCopyYES
bacdefghijklmnopqrstuvwxyz
YES
edocabfghijklmnpqrstuvwxyz
NO
YES
xzytabcdefghijklmnopqrsuvw
NO

import static java.lang.Math.max;

import static java.lang.Math.min;

import static java.lang.Math.abs;

import java.util.*;

import java.io.*;

import java.math.*;

public class C_Perfect_Keyboard {

    static long mod = Long.MAX_VALUE;

    static OutputStream outputStream = System.out;

    static PrintWriter out = new PrintWriter(outputStream);

    static FastReader f = new FastReader();

    public static void main(String[] args) {

        int t = f.nextInt();

        while(t-- > 0){

            solve();

        }

        out.close();

    }

    public static void solve() {

        String s = f.nextLine();

        int n = s.length();

        if(n == 1) {

            out.println("YES");

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

                out.print((char)('a'+i));

            }

            out.println();

            return;

        }

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

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

            adj.add(new ArrayList<>());

        }

        int deg[] = new int[26];

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

            int u = s.charAt(i)-'a';

            int v = s.charAt(i-1)-'a';

            boolean flag = true;

            for(int x: adj.get(u)) {

                if(x == v) {

                    flag = false;

                    break;

                }

            }

            if(flag) {

                adj.get(u).add(v);

                adj.get(v).add(u);

                deg[u]++;

                deg[v]++;

                if(deg[u] > 2 || deg[v] > 2) {

                    out.println("NO");

                    return;

                }

            }

        }

        if(detectCycle(adj)) {

            out.println("NO");

            return;

        }

        boolean taken[] = new boolean[26];

        StringBuilder sb = new StringBuilder();

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

            if(deg[i] == 1) {

                dfs(adj, i, taken, sb);

                break;

            }

        }

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

            if(!taken[i]) {

                sb.append((char)('a'+i));

            }

        }

        out.println("YES");

        out.println(sb);

    }

    public static void dfs(ArrayList<ArrayList<Integer>> adj, int s, boolean taken[], StringBuilder sb) {

        taken[s] = true;

        sb.append((char)('a'+s));

        for(int v: adj.get(s)) {

            if(!taken[v]) {

                dfs(adj, v, taken, sb);

            }

        }

    }

    public static boolean detectCycle(ArrayList<ArrayList<Integer>> adj) {

        boolean visited[] = new boolean[26];

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

            if(!visited[i]) {

                if(dfs(adj, i, -1, visited)) {

                    return true;

                }

            }

        }

        return false;

    }

    public static boolean dfs(ArrayList<ArrayList<Integer>> adj, int u, int p, boolean visited[]) {

        visited[u] = true;

        for(int v: adj.get(u)) {

            if(!visited[v]) {

                if(dfs(adj, v, u, visited)) {

                    return true;

                }

            } else if(v != p) {

                return true;

            }

        }

        return false;

    }

    // Sort an array

    public static void sort(int arr[]) {

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

        for(int i: arr) {

            al.add(i);

        }

        Collections.sort(al);

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

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

        }

    }

    // Find all divisors of n

    public static void allDivisors(int n) {

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

            if(n%i == 0) {

                System.out.println(i + " ");

                if(i != n/i) {

                    System.out.println(n/i + " ");

                }

            }

        }

    }

    // Check if n is prime or not

    public static boolean isPrime(int 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; i*i <= n; i += 6) {

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

                return false;

            }

        }

        return true;

    }

    // Find gcd of a and b

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

        long dividend = a > b ? a : b;

        long divisor =  a < b ? a : b;

        while(divisor > 0) {

            long reminder = dividend % divisor;

            dividend = divisor;

            divisor = reminder;

        }

        return dividend;

    }

    // Find lcm of a and b

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

        long lcm = gcd(a, b);

        long hcf = (a * b) / lcm;

        return hcf;

    }

    // Find factorial in O(n) time

    public static long fact(int n) {

        long res = 1;

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

            res = res * i;

        }

        return res;

    }

    // Find power in O(logb) time

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

        long res = 1;

        while(b > 0) {

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

                res = (res * a)%mod;

            }

            a = (a * a)%mod;

            b >>= 1;

        }

        return res;

    }

    // Find nCr

    public static long nCr(int n, int r) {

        if(r < 0 || r > n) {

            return 0;

        }

        long ans = fact(n) / (fact(r) * fact(n-r));

        return ans;

    }

    // Find nPr

    public static long nPr(int n, int r) {

        if(r < 0 || r > n) {

            return 0;

        }

        long ans = fact(n) / fact(r);

        return ans;

    }

    // sort all characters of a string

    public static String sortString(String inputString) {

        char tempArray[] = inputString.toCharArray();

        Arrays.sort(tempArray);

        return new String(tempArray);

    }

    // User defined class for fast I/O

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

        }

        boolean hasNext() {

            if (st != null && st.hasMoreTokens()) {

                return true;

            }

            String tmp;

            try {

                br.mark(1000);

                tmp = br.readLine();

                if (tmp == null) {

                    return false;

                }

                br.reset();

            } catch (IOException e) {

                return false;

            }

            return true;

        }

        int nextInt() {

            return Integer.parseInt(next());

        }

        long nextLong() {

            return Long.parseLong(next());

        }

        double nextDouble() {

            return Double.parseDouble(next());

        }

        float nextFloat() {

            return Float.parseFloat(next());

        }

        boolean nextBoolean() {

            return Boolean.parseBoolean(next());

        }

        String nextLine() {

            String str = "";

            try {

                str = br.readLine();

            }

            catch (IOException e) {

                e.printStackTrace();

            }

            return str;

        }

        int[] nextArray(int n) {

            int[] a = new int[n];

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

                a[i] = nextInt();

            }

            return a;

        }

    }

}

/**

Dec  Char                           Dec  Char     Dec  Char     Dec  Char

---------                           ---------     ---------     ----------

  0  NUL (null)                      32  SPACE     64  @         96  `

  1  SOH (start of heading)          33  !         65  A         97  a

  2  STX (start of text)             34  "         66  B         98  b

  3  ETX (end of text)               35  #         67  C         99  c

  4  EOT (end of transmission)       36  $         68  D        100  d

  5  ENQ (enquiry)                   37  %         69  E        101  e

  6  ACK (acknowledge)               38  &         70  F        102  f

  7  BEL (bell)                      39  '         71  G        103  g

  8  BS  (backspace)                 40  (         72  H        104  h

  9  TAB (horizontal tab)            41  )         73  I        105  i

 10  LF  (NL line feed, new line)    42  *         74  J        106  j

 11  VT  (vertical tab)              43  +         75  K        107  k

 12  FF  (NP form feed, new page)    44  ,         76  L        108  l

 13  CR  (carriage return)           45  -         77  M        109  m

 14  SO  (shift out)                 46  .         78  N        110  n

 15  SI  (shift in)                  47  /         79  O        111  o

 16  DLE (data link escape)          48  0         80  P        112  p

 17  DC1 (device control 1)          49  1         81  Q        113  q

 18  DC2 (device control 2)          50  2         82  R        114  r

 19  DC3 (device control 3)          51  3         83  S        115  s

 20  DC4 (device control 4)          52  4         84  T        116  t

 21  NAK (negative acknowledge)      53  5         85  U        117  u

 22  SYN (synchronous idle)          54  6         86  V        118  v

 23  ETB (end of trans. block)       55  7         87  W        119  w

 24  CAN (cancel)                    56  8         88  X        120  x

 25  EM  (end of medium)             57  9         89  Y        121  y

 26  SUB (substitute)                58  :         90  Z        122  z

 27  ESC (escape)                    59  ;         91  [        123  {

 28  FS  (file separator)            60  <         92  \        124  |

 29  GS  (group separator)           61  =         93  ]        125  }

 30  RS  (record separator)          62  >         94  ^        126  ~

 31  US  (unit separator)            63  ?         95  _        127  DEL

 */

// (a/b)%mod == (a * moduloInverse(b)) % mod;

// moduloInverse(b) = power(b, mod-2);


E. Permutation Separationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p1,p2,…,pnp1,p2,…,pn (an array where each integer from 11 to nn appears exactly once). The weight of the ii-th element of this permutation is aiai.At first, you separate your permutation into two non-empty sets — prefix and suffix. More formally, the first set contains elements p1,p2,…,pkp1,p2,…,pk, the second — pk+1,pk+2,…,pnpk+1,pk+2,…,pn, where 1≤k<n1≤k<n.After that, you may move elements between sets. The operation you are allowed to do is to choose some element of the first set and move it to the second set, or vice versa (move from the second set to the first). You have to pay aiai dollars to move the element pipi.Your goal is to make it so that each element of the first set is less than each element of the second set. Note that if one of the sets is empty, this condition is met.For example, if p=[3,1,2]p=[3,1,2] and a=[7,1,4]a=[7,1,4], then the optimal strategy is: separate pp into two parts [3,1][3,1] and [2][2] and then move the 22-element into first set (it costs 44). And if p=[3,5,1,6,2,4]p=[3,5,1,6,2,4], a=[9,1,9,9,1,9]a=[9,1,9,9,1,9], then the optimal strategy is: separate pp into two parts [3,5,1][3,5,1] and [6,2,4][6,2,4], and then move the 22-element into first set (it costs 11), and 55-element into second set (it also costs 11).Calculate the minimum number of dollars you have to spend.InputThe first line contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the length of permutation.The second line contains nn integers p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤pi≤n). It's guaranteed that this sequence contains each element from 11 to nn exactly once.The third line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).OutputPrint one integer — the minimum number of dollars you have to spend.ExamplesInputCopy3
3 1 2
7 1 4
OutputCopy4
InputCopy4
2 4 1 3
5 9 8 3
OutputCopy3
InputCopy6
3 5 1 6 2 4
9 1 9 9 1 9
OutputCopy2

import java.util.*;
import java.io.*;

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	long mod=998244353;
	long gcd(long a,long b) {
		return a==0?b:gcd(b%a,a);
	}
	void work() {
		int n=ni();
		int[] A=nia(n);
		long[] W=na(n);
		long[] sum=new long[n];
		for(int i=0;i<n;i++) {
			sum[A[i]]=W[i];
		}
		for(int i=1;i<n;i++) {
			sum[i]+=sum[i-1];
		}
		Node root=new Node();
		for(int i=0;i<n;i++) {
			update(root,0,n-1,i,i,sum[i]);
		}
		long ret=Long.MAX_VALUE;
		long s=0;
		for(int i=0;i<n-1;i++) {
			int node=A[i];
			long w=W[i];
			s+=w;//前缀空集
			update(root,0,n-1,node,n-1,-w);
			if(node!=0)update(root,0,n-1,0,node-1,w);
			ret=Math.min(ret, root.min);
			ret=Math.min(ret, s);
		}
		out.println(ret);
	}

	void u2(Node node,long v) {
		node.min+=v;
		node.lazy+=v;
	}
	void updatelazy(Node node) {
		u2(getLnode(node),node.lazy);
		u2(getRnode(node),node.lazy);
		node.lazy=0;
	}
	private void update(Node node, int l, int r, int s,int e,long v) {
		if(l>=s&&r<=e) {
			node.min+=v;
			node.lazy+=v;
			return;
		}
		updatelazy(node);
		int m=l+(r-l)/2;
		if(m>=s) {
			update(getLnode(node),l,m,s,e,v);
		}
		if(m+1<=e) {
			update(getRnode(node),m+1,r,s,e,v);
		}
		node.min=Math.min(getLnode(node).min,getRnode(node).min);//左右节点可能有lazy标记
	}

	private Node getLnode(Node node) {
		if(node.lnode==null)node.lnode=new Node();
		return node.lnode;
	}
	private Node getRnode(Node node) {
		if(node.rnode==null)node.rnode=new Node();
		return node.rnode;
	}
	class Node{
		Node lnode,rnode;
		long lazy;
		long min;
	}

	//input
	private ArrayList<Integer>[] ng(int n, int m) {
		ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i]=new ArrayList<>();
		}
		for(int i=1;i<=m;i++) {
			int s=in.nextInt()-1,e=in.nextInt()-1;
			graph[s].add(e);
			graph[e].add(s);
		}
		return graph;
	}

	private int ni() {
		return in.nextInt();
	}

	private long nl() {
		return in.nextLong();
	}

	private long[] na(int n) {
		long[] A=new long[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextLong();
		}
		return A;
	}
	private int[] nia(int n) {
		int[] A=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextInt()-1;//
		}
		return A;
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

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

	public String next()
	{
		while(st==null || !st.hasMoreElements())//回车，空行情况
		{
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

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

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


A. Three Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three strings aa, bb and cc of the same length nn. The strings consist of lowercase English letters only. The ii-th letter of aa is aiai, the ii-th letter of bb is bibi, the ii-th letter of cc is cici.For every ii (1≤i≤n1≤i≤n) you must swap (i.e. exchange) cici with either aiai or bibi. So in total you'll perform exactly nn swap operations, each of them either ci↔aici↔ai or ci↔bici↔bi (ii iterates over all integers between 11 and nn, inclusive).For example, if aa is "code", bb is "true", and cc is "help", you can make cc equal to "crue" taking the 11-st and the 44-th letters from aa and the others from bb. In this way aa becomes "hodp" and bb becomes "tele".Is it possible that after these swaps the string aa becomes exactly the same as the string bb?InputThe input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001≤t≤100)  — the number of test cases. The description of the test cases follows.The first line of each test case contains a string of lowercase English letters aa.The second line of each test case contains a string of lowercase English letters bb.The third line of each test case contains a string of lowercase English letters cc.It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding 100100.OutputPrint tt lines with answers for all test cases. For each test case:If it is possible to make string aa equal to string bb print "YES" (without quotes), otherwise print "NO" (without quotes).You can print either lowercase or uppercase letters in the answers.ExampleInputCopy4
aaa
bbb
ccc
abc
bca
bca
aabb
bbaa
baba
imi
mii
iim
OutputCopyNO
YES
YES
NO
NoteIn the first test case; it is impossible to do the swaps so that string aa becomes exactly the same as string bb.In the second test case, you should swap cici with aiai for all possible ii. After the swaps aa becomes "bca", bb becomes "bca" and cc becomes "abc". Here the strings aa and bb are equal.In the third test case, you should swap c1c1 with a1a1, c2c2 with b2b2, c3c3 with b3b3 and c4c4 with a4a4. Then string aa becomes "baba", string bb becomes "baba" and string cc becomes "abab". Here the strings aa and bb are equal.In the fourth test case, it is impossible to do the swaps so that string aa becomes exactly the same as string bb.

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class App

{

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

    {

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

        int t = Integer.parseInt(reader.readLine());

        while(t > 0)

        {

            System.out.println(solve(reader) ? "YES" : "NO");

            t -= 1;

        }

        reader.close();

    }

    public static boolean solve(BufferedReader reader) throws Exception

    {

        String a = reader.readLine();

        String b = reader.readLine();

        String c = reader.readLine();

        int n = a.length();

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

        {

            char currentA = a.charAt(i);

            char currentB = b.charAt(i);

            char currentC = c.charAt(i);

            if(currentC != currentA && currentC != currentB)

            {

                return false;

            }

        }

        return true;

    }

}


B. String Modificationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has a string ss of length nn. He decides to make the following modification to the string:   Pick an integer kk, (1≤k≤n1≤k≤n).  For ii from 11 to n−k+1n−k+1, reverse the substring s[i:i+k−1]s[i:i+k−1] of ss. For example, if string ss is qwer and k=2k=2, below is the series of transformations the string goes through:   qwer (original string)  wqer (after reversing the first substring of length 22)  weqr (after reversing the second substring of length 22)  werq (after reversing the last substring of length 22)  Hence, the resulting string after modifying ss with k=2k=2 is werq. Vasya wants to choose a kk such that the string obtained after the above-mentioned modification is lexicographically smallest possible among all choices of kk. Among all such kk, he wants to choose the smallest one. Since he is busy attending Felicity 2020, he asks for your help.A string aa is lexicographically smaller than a string bb if and only if one of the following holds:   aa is a prefix of bb, but a≠ba≠b;  in the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb. InputEach test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤50001≤t≤5000). The description of the test cases follows.The first line of each test case contains a single integer nn (1≤n≤50001≤n≤5000) — the length of the string ss.The second line of each test case contains the string ss of nn lowercase latin letters.It is guaranteed that the sum of nn over all test cases does not exceed 50005000.OutputFor each testcase output two lines:In the first line output the lexicographically smallest string s′s′ achievable after the above-mentioned modification. In the second line output the appropriate value of kk (1≤k≤n1≤k≤n) that you chose for performing the modification. If there are multiple values of kk that give the lexicographically smallest string, output the smallest value of kk among them.ExampleInputCopy6
4
abab
6
qwerty
5
aaaaa
6
alaska
9
lfpbavjsm
1
p
OutputCopyabab
1
ertyqw
3
aaaaa
1
aksala
6
avjsmbpfl
5
p
1
NoteIn the first testcase of the first sample; the string modification results for the sample abab are as follows :   for k=1k=1 : abab  for k=2k=2 : baba  for k=3k=3 : abab  for k=4k=4 : babaThe lexicographically smallest string achievable through modification is abab for k=1k=1 and 33. Smallest value of kk needed to achieve is hence 11.

import java.util.*;

import java.lang.*;

import java.io.*;

public class Solution {

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

        Reader.init(System.in);

        BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));

        int t = Reader.nextInt();

//        int t = 1;

        while(t-->0) {

            int n = Reader.nextInt();

            String s = Reader.next();

            ArrayList<String> arr = new ArrayList<>();

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

                int len = n-k-1;

                if(len%2==0){

                    String c = s.substring(k-1) + s.substring(0,k-1);

                    arr.add(c);

                }

                else{

                    StringBuilder temp = new StringBuilder(s.substring(0,k-1));

                    temp.reverse();

                    String c = s.substring(k-1) + temp.toString();

                    arr.add(c);

                }

            }

            ArrayList<String> copy = new ArrayList<>(arr);

            Collections.sort(arr);

            output.write(arr.get(0)+"\n");

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

                if(copy.get(i).equals(arr.get(0))){

                    output.write(i+1+"\n");

                    break;

                }

            }

        }

        output.close();

    }

//abab

//1

//ertyqw

//3

//aaaaa

//1

//aksala

//6

//avjsmbpfl

//5

//p

//1

    public static long[] factorial(int n){

        long[] factorials = new long[n+1];

        factorials[1] = 1;

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

            factorials[i] = (factorials[i-1]*i)%((int)1e9+7);

        }

        return factorials;

    }

    public static long numOfBits(long n){

        long ans = 0;

        while(n>0){

            n = n & (n-1);

            ans++;

        }

        return ans;

    }

    public static long ceilOfFraction(long x, long y){

        // ceil using integer division: ceil(x/y) = (x+y-1)/y

        // using double may go out of range.

        return (x+y-1)/y;

    }

    public static int power(int x, int y, int p) {

        int res = 1;

        x = x % p;

        while (y > 0) {

            if (y % 2 == 1) res = (res * x) % p;

            y = y >> 1;

            x = (x * x) % p;

        }

        return res;

    }

    // Returns n^(-1) mod p

    public static int modInverse(int n, int p) {

        return power(n, p - 2, p);

    }

    // Returns nCr % p using Fermat's

    // little theorem.

    public static int nCrModPFermat(int n, int r, int p) {

        if (n<r) return 0;

        if (r == 0) return 1;

        // Fill factorial array so that we

        // can find all factorial of r, n

        // and n-r

        int[] fac = new int[n + 1];

        fac[0] = 1;

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

            fac[i] = fac[i - 1] * i % p;

        return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;

    }

    public static long ncr(long n, long r) {

        long p = 1, k = 1;

        if (n - r < r) {

            r = n - r;

        }

        if (r != 0) {

            while (r > 0) {

                p *= n;

                k *= r;

                long m = gcd(p, k);

                p /= m;

                k /= m;

                n--;

                r--;

            }

        } else {

            p = 1;

        }

        return p;

    }

    public static boolean isPrime(long n){

        if (n <= 1) return false;

        if (n <= 3) return true;

        if (n % 2 == 0 || n % 3 == 0) return false;

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

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

                return false;

            }

        }

        return true;

    }

    public static int powOf2JustSmallerThanN(int n) {

        n |= n >> 1;

        n |= n >> 2;

        n |= n >> 4;

        n |= n >> 8;

        n |= n >> 16;

        return n ^ (n >> 1);

    }

    public static int mergeSortAndCount(int[] arr, int l, int r) {

        int count = 0;

        if (l < r) {

            int m = (l + r) / 2;

            count += mergeSortAndCount(arr, l, m);

            count += mergeSortAndCount(arr, m + 1, r);

            count += mergeAndCount(arr, l, m, r);

        }

        return count;

    }

    public static int mergeAndCount(int[] arr, int l, int m, int r) {

        int[] left = Arrays.copyOfRange(arr, l, m + 1);

        int[] right = Arrays.copyOfRange(arr, m + 1, r + 1);

        int i = 0, j = 0, k = l, swaps = 0;

        while (i < left.length && j < right.length) {

            if (left[i] <= right[j])

                arr[k++] = left[i++];

            else {

                arr[k++] = right[j++];

                swaps += (m + 1) - (l + i);

            }

        }

        while (i < left.length)

            arr[k++] = left[i++];

        while (j < right.length)

            arr[k++] = right[j++];

        return swaps;

    }

    public static void reverseArray(int[] arr,int start, int end) {

        int temp;

        while (start < end) {

            temp = arr[start];

            arr[start] = arr[end];

            arr[end] = temp;

            start++;

            end--;

        }

    }

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

        if(a==0){

            return b;

        }

        return gcd(b%a,a);

    }

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

        if(a>b) return a/gcd(b,a) * b;

        return b/gcd(a,b) * a;

    }

    public static long largeExponentMod(long x,long y,long mod){

        // computing (x^y) % mod

        x%=mod;

        long ans = 1;

        while(y>0){

            if((y&1)==1){

                ans = (ans*x)%mod;

            }

            x = (x*x)%mod;

            y = y >> 1;

        }

        return ans;

    }

    public static boolean[] numOfPrimesInRange(long L, long R){

        boolean[] isPrime = new boolean[(int) (R-L+1)];

        Arrays.fill(isPrime,true);

        long lim = (long) Math.sqrt(R);

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

            for (long j = Math.max(i * i, (L + i - 1) / i * i); j <= R; j += i){

                isPrime[(int) (j - L)] = false;

            }

        }

        if (L == 1) isPrime[0] = false;

        return isPrime;

    }

    public static ArrayList<Long> primeFactors(long n){

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

        if(n%2==0){

            factorization.add(2L);

        }

        while(n%2==0){

            n/=2;

        }

        if(n%3==0){

            factorization.add(3L);

        }

        while(n%3==0){

            n/=3;

        }

        if(n%5==0){

            factorization.add(5L);

        }

        while(n%5==0){

//            factorization.add(5L);

            n/=5;

        }

        int[] increments = {4, 2, 4, 2, 4, 6, 2, 6};

        int i = 0;

        for (long d = 7; d * d <= n; d += increments[i++]) {

            if(n%d==0){

                factorization.add(d);

            }

            while (n % d == 0) {

//                factorization.add(d);

                n /= d;

            }

            if (i == 8)

                i = 0;

        }

        if (n > 1)

            factorization.add(n);

        return factorization;

    }

}

class DSU {

    int[] size, parent;

    int n;

    public DSU(int n){

        this.n = n;

        size = new int[n];

        parent = new int[n];

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

            parent[i] = i;

            size[i] = 1;

        }

    }

    public int find(int u){

        if(parent[u]==u){

            return u;

        }

        return parent[u] = find(parent[u]);

    }

    public void merge(int u, int v){

        u = find(u);

        v = find(v);

        if(u!=v){

            if(size[u]>size[v]){

                parent[v] = u;

                size[u] += size[v];

            }

            else{

                parent[u] = v;

                size[v] += size[u];

            }

        }

    }

}

class Reader {

    static BufferedReader reader;

    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */

    static void init(InputStream input) {

        reader = new BufferedReader(

                new InputStreamReader(input) );

        tokenizer = new StringTokenizer("");

    }

    /** get next word */

    static String next() throws IOException {

        while ( ! tokenizer.hasMoreTokens() ) {

            //TODO add check for eof if necessary

            tokenizer = new StringTokenizer(

                    reader.readLine() );

        }

        return tokenizer.nextToken();

    }

    static String nextLine() throws IOException {

        return reader.readLine();

    }

    static int nextInt() throws IOException {

        return Integer.parseInt( next() );

    }

    static long nextLong() throws IOException{

        return Long.parseLong(next() );

    }

    static double nextDouble() throws IOException {

        return Double.parseDouble( next() );

    }

}