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

			 import java.util.*;

			 import java.math.*;

			 import java.io.*;

			 import java.util.stream.Collectors;

	import java.text.DecimalFormat;

		       public class A{

		              static FastScanner scan=new FastScanner();

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

		static int n;

		static long PS[];

		static long MIN[];

		static boolean check(long x,long TH)

		{

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

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

			x=x%n;

			x--;

		//	out.println(x);

			if(x>=0)

			TH+=MIN[(int)x];

			return TH<=0;

		}

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

				     {

					int tt=1;

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

		//			tt=scan.nextInt();

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

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

				outer:while(tt-->0)

					{

long H=scan.nextLong();

long TH=H;

						 n=scan.nextInt();

						 long arr[]=new long[n];

						 MIN=new long[n];

						 PS=new long[n];

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

						 {

						 	arr[i]=scan.nextLong();

						 	TH+=arr[i];

						 	if(TH<=0)

						 	{

						 		out.println(i+1);

						 		out.close();

						 		return;

						 	}

						 }

						 PS[0]=arr[0];

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

						 {

						 	PS[i]=arr[i];

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

						 }

						 MIN[0]=PS[0];

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

						 {

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

						 }

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

						 {

						 	out.println(-1);

						 	out.close();

						 	return;

						 }

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

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

//out.println(H)

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

						long abs=-PS[n-1];

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

						{

							if(PS[i]>=0)

								continue;

							TH=H;

							TH+=PS[i];

							ans=Math.min(ans,(i+1)+((TH/abs)+(TH%abs==0?0:1))*n);

//out.println(ans+" "+i+" "+TH+" "+PS[0]+" "+((TH/abs)+(TH%abs==0?0:1))*n);

						}

						 out.println(ans);

	}

				out.close();

							}

										     static class FastScanner

								{

								    private int BS = 1 << 16;

								    private char NC = (char) 0;

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

								    private int bId = 0, size = 0;

								    private char c = NC;

								    private double cnt = 1;

								    private BufferedInputStream in;

								    public FastScanner() {

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

								    }

								    public FastScanner(String s) {

								        try {

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

								        } catch (Exception e) {

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

								        }

								    }

								    private char getChar() {

								        while (bId == size) {

								            try {

								                size = in.read(buf);

								            } catch (Exception e) {

								                return NC;

								            }

								            if (size == -1) return NC;

								            bId = 0;

								        }

								        return (char) buf[bId++];

								    }

								    public int nextInt() {

								        return (int) nextLong();

								    }

								    public int[] nextInts(int N) {

								        int[] res = new int[N];

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

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

								        }

								        return res;

								    }

								    public long[] nextLongs(int N) {

								        long[] res = new long[N];

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

								            res[i] = nextLong();

								        }

								        return res;

								    }

								    public long nextLong() {

								        cnt = 1;

								        boolean neg = false;

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

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

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

								        }

								        long res = 0;

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

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

								            cnt *= 10;

								        }

								        return neg ? -res : res;

								    }

								    public double nextDouble() {

								        double cur = nextLong();

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

								    }

								    public double[] nextDoubles(int N) {

								        double[] res = new double[N];

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

								            res[i] = nextDouble();

								        }

								        return res;

								    }

								    public String next() {

								        StringBuilder res = new StringBuilder();

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

								        while (c > 32) {

								            res.append(c);

								            c = getChar();

								        }

								        return res.toString();

								    }

								    public String nextLine() {

								        StringBuilder res = new StringBuilder();

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

								        while (c != '\n') {

								            res.append(c);

								            c = getChar();

								        }

								        return res.toString();

								    }

								    public boolean hasNext() {

								        if (c > 32) return true;

								        while (true) {

								            c = getChar();

								            if (c == NC) return false;

								            else if (c > 32) return true;

								        }

								    }

								}

										     static class Pair implements Comparable<Pair>{

										            public long x, y,z;

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

										                x=x1;

										                y=y1;

										                z=z1;

										            }

										             public Pair(long x1, long y1) {

										                x=x1;

										                y=y1;

										            }

										            @Override

										            public int hashCode() {

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

										            }

										            public String toString() {

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

										            }

										            @Override

										            public boolean equals(Object o){

										                if (o == this) return true;

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

										                Pair t = (Pair)o;

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

										            }

										    public int compareTo(Pair o)

										    {

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

										        }

										    }

										}


B. Hypersettime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes; shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.Polina came up with a new game called "Hyperset". In her game, there are nn cards with kk features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k=4k=4.Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.InputThe first line of each test contains two integers nn and kk (1≤n≤15001≤n≤1500, 1≤k≤301≤k≤30) — number of cards and number of features.Each of the following nn lines contains a card description: a string consisting of kk letters "S", "E", "T". The ii-th character of this string decribes the ii-th feature of that card. All cards are distinct.OutputOutput a single integer — the number of ways to choose three cards that form a set.ExamplesInputCopy3 3
SET
ETS
TSE
OutputCopy1InputCopy3 4
SETE
ETSE
TSES
OutputCopy0InputCopy5 4
SETT
TEST
EEET
ESTE
STES
OutputCopy2NoteIn the third example test; these two triples of cards are sets:  "SETT"; "TEST"; "EEET"  "TEST"; "ESTE", "STES"

// have faith in yourself!!!!!

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

public class CodeForces {
    /*-------------------------------------------EDITING CODE STARTS HERE-------------------------------------------*/
    public static void main(String[] args) throws IOException {
        openIO();
        int testCase = 1;
//        testCase = sc. nextInt();
        for (int i = 1; i <= testCase; i++) solve(i);
        closeIO();
    }

    public static void solve(int tCase) throws IOException {
        int n= sc.nextInt();
        int k = sc.nextInt();
        Map<String,Integer> set = new HashMap<>();
        String[] str = new String[n];
        for(int i=0;i<n;i++){
            str[i] = sc.next();
            set.put(str[i],i);
        }
        int cnt = 0;
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                StringBuilder third = new StringBuilder();
                for(int l=0;l<k;l++){
                    if(str[i].charAt(l)==str[j].charAt(l))third.append(str[i].charAt(l));
                    else {
                       if(str[i].charAt(l)!='S' && str[j].charAt(l)!='S')third.append('S');
                       else if(str[i].charAt(l)!='E' && str[j].charAt(l)!='E')third.append('E');
                       else if(str[i].charAt(l)!='T' && str[j].charAt(l)!='T')third.append('T');
                    }
                }
                String s = third.toString();
                if(set.containsKey(s) && set.get(s) > j ){
//                    out.println(str[i]+" "+str[j]+" "+third);
                    cnt++;
                }
            }
        }
        out.println(cnt);

    }

    public static int mod = (int) 1e9 + 7;
    //    public static int mod =  998244353;
    public static int inf_int = (int) 2e9 ;
    public static  long inf_long = (long) 2e14;

    public static void _sort(int[] arr,boolean isAscending){
        int n = arr.length;
        List<Integer> list = new ArrayList<>();
        for(int ele : arr)list.add(ele);
        Collections.sort(list);
        if(!isAscending)Collections.reverse(list);
        for(int i=0;i<n;i++)arr[i] = list.get(i);
    }

    public static void _sort(long[] arr,boolean isAscending){
        int n = arr.length;
        List<Long> list = new ArrayList<>();
        for(long ele : arr)list.add(ele);
        Collections.sort(list);
        if(!isAscending)Collections.reverse(list);
        for(int i=0;i<n;i++)arr[i] = list.get(i);
    }

    static class Pair<K,V> {
        K f;
        V s;
        public Pair(K f) {
            this.f = f;
        }
        public Pair(K f, V s) {
            this.f = f;
            this.s = s;
        }
    }

    /*-------------------------------------------EDITING CODE ENDS HERE-------------------------------------------*/
    static FastestReader sc;
    static PrintWriter out;
    private static void openIO() throws IOException{
        sc = new FastestReader();
        out = new PrintWriter(System.out);
    }
    /*-------------------------------------------FAST INPUT STARTS HERE---------------------------------------------*/

    public static void closeIO() throws IOException{
        out.flush();
        out.close();
        sc.close();
    }
    private static final class FastestReader {
        private static final int BUFFER_SIZE = 1 << 16;
        private final DataInputStream din;
        private final byte[] buffer;
        private int bufferPointer, bytesRead;

        public FastestReader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public FastestReader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }

        private int skip() throws IOException {
            int b;
            //noinspection StatementWithEmptyBody
            while ((b = read()) != -1 && isSpaceChar(b)) {}
            return b;
        }

        public String next() throws IOException {
            int b = skip();
            final StringBuilder sb = new StringBuilder();
            while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            final boolean neg = c == '-';
            if (neg) { c = read(); }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg) { return -ret; }
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ') { c = read(); }
            final boolean neg = c == '-';
            if (neg) { c = read(); }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) { return -ret; }
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') { c = read(); }
            final boolean neg = c == '-';
            if (neg) { c = read(); }

            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg) { return -ret; }
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) { buffer[0] = -1; }
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead) { fillBuffer(); }
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            din.close();
        }
    }
    /*---------------------------------------------FAST INPUT ENDS HERE ---------------------------------------------*/
}


E. Messenger Simulatortime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is a frequent user of the very popular messenger. He's chatting with his friends all the time. He has nn friends, numbered from 11 to nn.Recall that a permutation of size nn is an array of size nn such that each integer from 11 to nn occurs exactly once in this array.So his recent chat list can be represented with a permutation pp of size nn. p1p1 is the most recent friend Polycarp talked to, p2p2 is the second most recent and so on.Initially, Polycarp's recent chat list pp looks like 1,2,…,n1,2,…,n (in other words, it is an identity permutation).After that he receives mm messages, the jj-th message comes from the friend ajaj. And that causes friend ajaj to move to the first position in a permutation, shifting everyone between the first position and the current position of ajaj by 11. Note that if the friend ajaj is in the first position already then nothing happens.For example, let the recent chat list be p=[4,1,5,3,2]p=[4,1,5,3,2]:   if he gets messaged by friend 33, then pp becomes [3,4,1,5,2][3,4,1,5,2];  if he gets messaged by friend 44, then pp doesn't change [4,1,5,3,2][4,1,5,3,2];  if he gets messaged by friend 22, then pp becomes [2,4,1,5,3][2,4,1,5,3]. For each friend consider all position he has been at in the beginning and after receiving each message. Polycarp wants to know what were the minimum and the maximum positions.InputThe first line contains two integers nn and mm (1≤n,m≤3⋅1051≤n,m≤3⋅105) — the number of Polycarp's friends and the number of received messages, respectively.The second line contains mm integers a1,a2,…,ama1,a2,…,am (1≤ai≤n1≤ai≤n) — the descriptions of the received messages.OutputPrint nn pairs of integers. For each friend output the minimum and the maximum positions he has been in the beginning and after receiving each message.ExamplesInputCopy5 4
3 5 1 4
OutputCopy1 3
2 5
1 4
1 5
1 5
InputCopy4 3
1 2 4
OutputCopy1 3
1 2
3 4
1 4
NoteIn the first example; Polycarp's recent chat list looks like this:   [1,2,3,4,5][1,2,3,4,5]  [3,1,2,4,5][3,1,2,4,5]  [5,3,1,2,4][5,3,1,2,4]  [1,5,3,2,4][1,5,3,2,4]  [4,1,5,3,2][4,1,5,3,2] So, for example, the positions of the friend 22 are 2,3,4,4,52,3,4,4,5, respectively. Out of these 22 is the minimum one and 55 is the maximum one. Thus, the answer for the friend 22 is a pair (2,5)(2,5).In the second example, Polycarp's recent chat list looks like this:   [1,2,3,4][1,2,3,4]  [1,2,3,4][1,2,3,4]  [2,1,3,4][2,1,3,4]  [4,2,1,3][4,2,1,3]

import java.io.*;

import java.util.*;

public class Main {

    static class SegTree {

        int[] t;

        int n;

        SegTree(int[] a) {

            this.n = a.length;

            this.t = new int[4 * this.n];

            build(a, 1, 0, this.n - 1);

        }

        void build(int[] a, int v, int tl, int tr) {

            if(tl == tr)

                t[v] = a[tl];

            else {

                int tm = (tl + tr) / 2;

                build(a, 2 * v, tl, tm);

                build(a, 2 * v + 1, tm + 1, tr);

                t[v] = t[2 * v] + t[2 * v + 1];

            }

        }

        int query(int v, int l, int r, int tl, int tr) {

            if(l > r)

                return 0;

            if(l == tl && r == tr)

                return t[v];

            int tm = (tl + tr) / 2;

            return query(2 * v, l, Math.min(tm, r), tl, tm) +

                    query(2 * v + 1, Math.max(tm + 1, l), r, tm + 1, tr);

        }

        int query(int l, int r) {

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

        }

        void update(int pos, int add, int v, int tl, int tr) {

            if(tl == tr)

                t[v] += add;

            else {

                int tm = (tl + tr) / 2;

                if(pos <= tm)

                    update(pos, add, 2 * v, tl, tm);

                else

                    update(pos, add, 2 * v + 1, tm + 1, tr);

                t[v] = t[2 * v] + t[2 * v + 1];

            }

        }

        void update(int pos, int val) {

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

        }

    }

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

        Scanner in = new Scanner(System.in);

        int n = in.nextInt(), m = in.nextInt();

        int[] ans = new int[n];

        int[] pos = new int[n];

        int[] cnt = new int[n + m];

        boolean[] mi = new boolean[n];

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

            pos[i] = m + i;

            ans[i] = i;

            cnt[m + i] = 1;

        }

        SegTree t = new SegTree(cnt);

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

            int x = in.nextInt() - 1;

            mi[x] = true;

            ans[x] = Math.max(ans[x], t.query(0, pos[x]));

            t.update(pos[x], -1);

            pos[x] = m - i - 1;

            t.update(pos[x], 1);

        }

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

            ans[i] = Math.max(ans[i], t.query(0, pos[i]));

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

            System.out.println((mi[i] ? 1 : (i + 1)) + " " + ans[i]);

    }

}