The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 50) separated by a single space. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1).

import java.util.Scanner;

public class NextRound2 {
    public static void main(String[] args){
        Scanner scan  = new Scanner(System.in);
        int n,k,score=-1,count=0;
        n = scan.nextInt();
        k = scan.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scan.nextInt();
        }
        scan.close();
        if(a[0]==0){
            k=0;
        }else{
            //6 2
            //3 0 0 0 0 0
            while(a[k-1]==0)k--;
            //non-incresing, next number from (k-1) must be the same (k).
            while(k<n && a[k-1]==a[k])k++;
        }
        System.out.println(k);
    }
}

NoteIn the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.In the second example nobody got a positive score.

Output the number of participants who advance to the next round.

"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round.

Input:
8 5
10 9 8 7 7 7 5 5

Output: 6

Input:
4 2
0 0 0 0

Output: 0

Input:
5 1
1 1 1 1 1

Output: 5

Input:
5 5
1 1 1 1 1

Output: 5

Input:
1 1
10

Output: 1

Input:
17 14
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Output: 14

Input:
5 5
3 2 1 0 0

Output: 3

Input:
8 6
10 9 8 7 7 7 5 5

Output: 6

Input:
8 7
10 9 8 7 7 7 5 5

Output: 8

Input:
8 4
10 9 8 7 7 7 5 5

Output: 6

Input:
8 3
10 9 8 7 7 7 5 5

Output: 3

Input:
8 1
10 9 8 7 7 7 5 5

Output: 1

Input:
8 2
10 9 8 7 7 7 5 5

Output: 2

Input:
1 1
100

Output: 1

Input:
1 1
0

Output: 0

Input:
50 25
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 50

Input:
50 25
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 25

Input:
50 25
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 26

Input:
50 25
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 50

Input:
11 5
100 99 98 97 96 95 94 93 92 91 90

Output: 5

Input:
10 4
100 81 70 69 64 43 34 29 15 3

Output: 4

Input:
11 6
87 71 62 52 46 46 43 35 32 25 12

Output: 6

Input:
17 12
99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2

Output: 12

Input:
20 3
98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2

Output: 3

Input:
36 12
90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5

Output: 12

Input:
49 8
99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1

Output: 9

Input:
49 29
100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0

Output: 29

Input:
49 34
99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4

Output: 34

Input:
50 44
100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4

Output: 44

Input:
50 13
99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3

Output: 13

Input:
50 30
100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3

Output: 30

Input:
2 1
10 10

Output: 2

Input:
2 2
10 10

Output: 2

Input:
2 2
10 0

Output: 1

Input:
2 2
10 1

Output: 2

Input:
2 1
10 0

Output: 1

Input:
2 1
10 2

Output: 1

Input:
50 13
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Output: 0

Input:
50 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Output: 0

Input:
50 50
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Output: 0

Input:
10 1
5 5 5 3 3 3 0 0 0 0

Output: 3

Input:
10 2
5 5 5 3 3 3 0 0 0 0

Output: 3

Input:
10 3
5 5 5 3 3 3 0 0 0 0

Output: 3

Input:
10 4
5 5 5 3 3 3 0 0 0 0

Output: 6

Input:
10 5
5 5 5 3 3 3 0 0 0 0

Output: 6

Input:
10 6
5 5 5 3 3 3 0 0 0 0

Output: 6

Input:
10 7
5 5 5 3 3 3 0 0 0 0

Output: 6

Input:
10 8
5 5 5 3 3 3 0 0 0 0

Output: 6

Input:
10 9
5 5 5 3 3 3 0 0 0 0

Output: 6

Input:
10 10
5 5 5 3 3 3 0 0 0 0

Output: 6


The first line contains three integers a, b, mod (0 ≤ a, b ≤ 109, 1 ≤ mod ≤ 107).

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

public class Game {
  public static void main(String[] args) throws IOException {
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String[] input = bf.readLine().split(" ");
    String answer = "";
    long a, b, mod, ans;
    boolean oneWin = false;
    a = Integer.parseInt(input[0]);
    b = Integer.parseInt(input[1]);
    mod = Integer.parseInt(input[2]);
    long limit = Math.min(a, mod);
    long res = 0;

    for (ans = 1; ans <= limit; ans++) {
      res = (((ans % mod) * (1000000000 % mod)) % mod);
      if ((mod - res)% mod > b) {
          oneWin = true;
          break;
      }
    }

    if (oneWin) {
      String temp = String.valueOf(ans);
      int digits = temp.length();
      for (int i = 0;i < 9 - digits; i++) {
        answer += "0";
      }
      answer += String.valueOf(ans);
      System.out.println("1 " + answer);
    } else {
      System.out.println(2);
    }
  }
}

NoteThe lexical comparison of strings is performed by the < operator in modern programming languages. String x is lexicographically less than string y if exists such i (1 ≤ i ≤ 9), that xi < yi, and for any j (1 ≤ j < i) xj = yj. These strings always have length 9.

If the first player wins, print "1" and the lexicographically minimum string s1 he has to write to win. If the second player wins, print the single number "2".

In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and writes a string s2, consisting of exactly nine digits and representing a number that does not exceed b. Here a and b are some given constants, s1 and s2 are chosen by the players. The strings are allowed to contain leading zeroes.If a number obtained by the concatenation (joining together) of strings s1 and s2 is divisible by mod, then the second player wins. Otherwise the first player wins. You are given numbers a, b, mod. Your task is to determine who wins if both players play in the optimal manner. If the first player wins, you are also required to find the lexicographically minimum winning move.

Input: 1 10 7

Output: 2

Input: 4 0 9

Output: 1 000000001

Input: 10 7 8

Output: 2

Input: 6 4 10

Output: 2

Input: 4 1 4

Output: 2

Input: 4 7 9

Output: 1 000000001

Input: 13 4 51

Output: 1 000000001

Input: 0 0 1

Output: 2

Input: 1 0 1

Output: 2

Input: 2 1 3

Output: 1 000000001

Input: 0 2 2

Output: 2

Input: 2 3 1

Output: 2

Input: 3 0 3

Output: 1 000000001

Input: 1 1 2

Output: 2

Input: 3 2 1

Output: 2

Input: 0 3 3

Output: 2

Input: 4 0 13

Output: 1 000000001

Input: 1 2 13

Output: 2

Input: 4 3 12

Output: 1 000000001

Input: 1 2 11

Output: 2

Input: 815 216 182

Output: 2

Input: 218 550 593

Output: 1 000000011

Input: 116482865 344094604 3271060

Output: 2

Input: 19749161 751031022 646204

Output: 2

Input: 70499104 10483793 5504995

Output: 2

Input: 1960930 562910 606828

Output: 1 000000011

Input: 8270979 4785512 9669629

Output: 1 000000001

Input: 9323791 4748006 5840080

Output: 1 000000005

Input: 972037745 4602117 5090186

Output: 1 000000011

Input: 585173560 4799128 5611727

Output: 1 000000036

Input: 22033548 813958 4874712

Output: 1 000000001

Input: 702034015 6007275 9777625

Output: 1 000000001

Input: 218556 828183 7799410

Output: 1 000000001

Input: 1167900 2709798 6800151

Output: 1 000000001

Input: 7004769 3114686 4659684

Output: 1 000000002

Input: 1000000000 1000000000 10000000

Output: 2

Input: 3631 1628 367377

Output: 1 000000009

Input: 3966 5002 273075

Output: 1 000000008

Input: 2388 2896 73888

Output: 1 000000016

Input: 0 1 1

Output: 2

Input: 1 1 1

Output: 2

Input: 1000000000 0 1

Output: 2

Input: 0 1000000000 1

Output: 2

Input: 1000000000 1000000000 1

Output: 2

Input: 1000000000 0 10000000

Output: 2

Input: 0 1000000000 10000000

Output: 2

Input: 0 0 10000000

Output: 2

Input: 0 999999999 10000000

Output: 2

Input: 999999999 0 10000000

Output: 2

Input: 999999999 999999999 10000000

Output: 2

Input: 999999999 1000000000 10000000

Output: 2

Input: 1000000000 999999999 10000000

Output: 2

Input: 1000000000 10000 10000000

Output: 2

Input: 1 1 1337

Output: 1 000000001

Input: 576694 1234562 1234567

Output: 2

Input: 12350 12000 12345

Output: 1 000000011

Input: 576695 1234562 1234567

Output: 1 000576695

Input: 0 0 11

Output: 2

Input: 999999999 999999999 9009009

Output: 2

Input: 1 0 7

Output: 1 000000001

Input: 1 1 7

Output: 2

Input: 1000000000 9999991 10000000

Output: 2

Input: 9902593 9902584 9902593

Output: 1 002490619

Input: 10000000 9999977 9999979

Output: 1 009909503

Input: 1000000000 1000000000 9999999

Output: 2

Input: 11 9 11

Output: 1 000000010

Input: 0 7 13

Output: 2

Input: 1 0 3

Output: 1 000000001

Input: 100 2 3

Output: 2

Input: 2 7 13

Output: 2

Input: 1 0 9

Output: 1 000000001

Input: 1000000000 9999995 10000000

Output: 2

Input: 1000000000 25 30

Output: 2

Input: 243 1001 1003

Output: 2

Input: 9 9 11

Output: 2

Input: 0 1 11

Output: 2

Input: 4 4 7

Output: 2

Input: 1000000000 1 10

Output: 2

Input: 1 0 11

Output: 1 000000001

Input: 0 0 3

Output: 2

Input: 10 12000 12345

Output: 2

Input: 1000000000 0 2

Output: 2

Input: 0 1 3

Output: 2

Input: 3 1 7

Output: 1 000000002

Input: 1000000000 2 1000000

Output: 2

Input: 23 0 23

Output: 1 000000001

Input: 123456789 1234561 1234567

Output: 1 000549636

Input: 11 10 13

Output: 1 000000011

Input: 138 11711 11829

Output: 2

Input: 1000000000 100050 1000001

Output: 1 000000101


The only line of the input contains integer n (0 ≤ n ≤ 1018) — the number of Ayrat's moves.

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

/**
 * CodeForces : 338
 *
 * @author vinaysaini E. Hexagons
 */
public class cf338e {

	static int dx[] = { 1, -1, -2, -1, 1, 2 };
	static int dy[] = { 2, 2, 0, -2, -2, 0 };

	public static void main(String[] args) {
		long x = 0, y = 0;

		long n = in.nextLong();
		long ringNumber = getRing(n);
		long stepsUpTo = 3 * ringNumber * ringNumber + 3 * ringNumber;
		x = 2 * ringNumber;
		long remainingSteps = n - stepsUpTo;
		if (remainingSteps > 0) {
			x = x + dx[0];
			y = y + dy[0];
			remainingSteps--;
		}
		if (remainingSteps >= ringNumber) {
			x += dx[1] * ringNumber;
			y += dy[1] * ringNumber;
			remainingSteps -= ringNumber;
		} else {
			x += dx[1] * remainingSteps;
			y += dy[1] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[2] * (ringNumber+1);
			y += dy[2] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[2] * remainingSteps;
			y += dy[2] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[3] * (ringNumber+1);
			y += dy[3] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[3] * remainingSteps;
			y += dy[3] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[4] * (ringNumber+1);
			y += dy[4] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[4] * remainingSteps;
			y += dy[4] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[5] * (ringNumber+1);
			y += dy[5] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[5] * remainingSteps;
			y += dy[5] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber) {
			x += dx[0] * ringNumber;
			y += dy[0] * ringNumber;
			remainingSteps -= ringNumber;
		} else {
			x += dx[0] * remainingSteps;
			y += dy[0] * remainingSteps;
			remainingSteps -= remainingSteps;
		}

		out.println(x + " " + y);
		out.close();
	}

	static long getRing(long n) {
		long l = 0;
		long r = (long) 1e9;
		while (l < r) {
			long m = (l + r) / 2;
			long sum = 3 * m * m + 3 * m;
			if (n < sum) {
				r = m;
			} else
				l = m + 1;
		}
		return l - 1;
	}

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

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			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;
		}
	} // --fast i/o ends here----//

}

Print two integers x and y — current coordinates of Ayrat coordinates.

Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined:   Ayrat is searching through the field. He started at point (0, 0) and is moving along the spiral (see second picture). Sometimes he forgets where he is now. Help Ayrat determine his location after n moves.

Output: -2 0

Output: 3 2

Output: 5 6

Output: -2 -4

Output: 8 8

Output: 8 0

Output: 8 0

Output: 7 -2

Output: 154 -492

Output: -33 806

Output: 13 -214

Output: -769 562

Output: -418284973 -1154700538

Output: 414 1068

Output: 458 -20

Output: -797 -222

Output: 21108 9228

Output: 27596 -17836

Output: 1516 17472

Output: 27776 16488

Output: 22704 -27064

Output: 4864 384

Output: 2815 18250

Output: 8695 33702

Output: -15591 -36122

Output: 31404 5384

Output: 11555 -17054

Output: 0 0

Output: 1 2

Output: -1 2

Output: -2 0

Output: -1 -2

Output: 1 -2

Output: 2 0

Output: 3 2

Output: 2 4

Output: 0 4

Output: -2 4

Output: -3 2

Output: -4 0

Output: -3 -2

Output: -2 -4

Output: 0 -4

Output: 2 -4

Output: 3 -2

Output: 4 0

Output: 5 2

Output: 4 4

Output: 3 6

Output: 1 6

Output: -1 6

Output: -3 6

Output: -4 4

Output: -5 2

Output: -6 0

Output: -5 -2

Output: -4 -4

Output: -3 -6

Output: -53995102 -586455096

Output: -438664202 297458800

Output: -252460838 -588330600

Output: -423141322 332249584

Output: -164822562 -590200144

Output: 439863347 302538706

Output: -378326148 -427475264

Output: 200309780 592993400

Output: 489196540 209450068

Output: -794841963 -444342246

Output: -623135314 -788838484

Output: -328249537 -1018095738

Output: -719067659 -599137942

Output: -637165825 764022826

Output: 559082192 -921270732

Output: 7343027 1020257594

Output: -707743686 626107308

Output: 797020774 -448632052

Output: 604133660 -835484644

Output: -264428508 -626474244

Output: -107643660 215287324

Output: -287379568 574759144

Output: 344296355 2

Output: 146851396 293702780

Output: 31620002 63239992

Output: -422711816 4

Output: -96124517 -192249026

Output: -275860421 551720850

Output: -911192665 10

Output: 357225613 714451226

Output: -483988434 8

Output: -421730125 843460258

Output: -306498737 -612997466

Output: -281201952 -562403896

Output: -331941110 4

Output: -691412929 6

Output: -25442382 -50884744

Output: 820421960 -4

Output: 179893783 -2

Output: -380112498 8

Output: 74824856 -149649712

Output: -509121532 4

Output: 868593352 0

Output: -114032591 -228065170

Output: 498801191 -997602386

Output: 178537107 357074206

Output: 358273010 -716546028

Output: 486083238 -4

Output: -422777531 845555062

Output: 45773778 4

Output: 407655496 -815310984

Output: 382358709 -764717418

Output: 534254630 0

Output: -446863220 893726452

Output: -331631832 663263664

Output: 306335045 612670094

Output: 191103653 382207306

Output: 370839563 741679126

Output: -255608161 511216338

Output: -355717526 711435056

Output: 240486136 480972264

Output: -430378693 10

Output: 99957958 199915904

Output: -279693865 559387730

Output: -459429777 -918859546

Output: -139165682 278331372

Output: 23934291 -47868582

Output: 203670197 -407340402

Output: -383406115 -766812218

Output: 852579099 -2

Output: -430378698 0

Output: -215189349 -430378698

Output: 1 2

Output: -1 2

Output: -1 -2

Output: 1 -2

Output: 2 0


The only line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^{15}$$$, $$$1 \leq k \leq 10^4$$$).

import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
class Node {
    long p;
    int a;
    public Node(long p,int a){
        this.p=p;
        this.a=a;
    }
}
    void solve() {
        long n=nl(); int k=ni();
        ArrayList<Node> vec=new ArrayList<>();
        for(long i=2;i*i<=n;i++){
             if(n%i==0){
                 int cc=0;
                 while(n%i==0){
                     n/=i;
                     cc++;
                 }
                 vec.add(new Node(i,cc));
             }
        }
        if(n>1) vec.add(new Node(n,1));
        long dp[][]=new long[51][k+1];
        long ans=1;
        long suf[]=new long[51];
        long curSuf[]=new long[51];
        long inv[]=new long[52];
        for(int i=0;i<52;i++) inv[i]=modInverse(i);

        for(Node P : vec){
            long p=P.p; int a=P.a;
            for(int i=0;i<=50;i++) Arrays.fill(dp[i],0);

            dp[a][0]=1;
            Arrays.fill(suf,inv[a+1]);

            for(int s=1;s<=k;s++){
                Arrays.fill(curSuf,0);
                for(int i=a;i>=0;i--){
                    dp[i][s]=suf[i];
                    curSuf[i]=mul(dp[i][s],inv[i+1]);
                    if(i+1<=a) curSuf[i]=add(curSuf[i],curSuf[i+1]);
                   // for(int j=i;j<=a;j++) dp[i][s]=add(dp[i][s],mul(dp[j][s-1],inv[j+1]));

                }
                for(int i=0;i<=a;i++) suf[i]=curSuf[i];
            }
            long ex=0;
            for(int i=0;i<=a;i++){
                ex=add(ex,mul(dp[i][k],modpow(p,i)));

            }
           // if(p==2) pw.println(dp[0][k]+" "+dp[1][k]+" "+modInverse(2)+" "+ex+" "+mul(3,modInverse(2)));
            ans=mul(ans,ex);

        }
        pw.println(ans);

    }
    long add(long x,long y){
        x+=y;
        if(x>=M) x-=M;
        return x;
    }
    long sub(long x,long y){
        x-=y;
        if(x<0) x+=M;
        return x;
    }
    long mul(long x,long y){
        x*=y;
        if(x>=M) x%=M;
        return x;
    }
    long modpow(long a, long b)
    {
        long r=1;
        while(b>0)
        {
            if((b&1)>0) r=mul(r,a);
            a=mul(a,a);
            b>>=1;
        }
        return r;
    }

    long modInverse(long A)
    {

        return modpow(A,M-2);
    }

    long M= (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");

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

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }

}

NoteIn the first example, after one step, the number written on the blackboard is $$$1$$$, $$$2$$$, $$$3$$$ or $$$6$$$ — each occurring with equal probability. Hence, the answer is $$$\frac{1+2+3+6}{4}=3$$$.In the second example, the answer is equal to $$$1 \cdot \frac{9}{16}+2 \cdot \frac{3}{16}+3 \cdot \frac{3}{16}+6 \cdot \frac{1}{16}=\frac{15}{8}$$$.

Print a single integer — the expected value of the number on the blackboard after $$$k$$$ steps as $$$P \cdot Q^{-1} \pmod{10^9+7}$$$ for $$$P$$$, $$$Q$$$ defined above.

Makoto has a big blackboard with a positive integer $$$n$$$ written on it. He will perform the following action exactly $$$k$$$ times:Suppose the number currently written on the blackboard is $$$v$$$. He will randomly pick one of the divisors of $$$v$$$ (possibly $$$1$$$ and $$$v$$$) and replace $$$v$$$ with this divisor. As Makoto uses his famous random number generator (RNG) and as he always uses $$$58$$$ as his generator seed, each divisor is guaranteed to be chosen with equal probability.He now wonders what is the expected value of the number written on the blackboard after $$$k$$$ steps.It can be shown that this value can be represented as $$$\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \not\equiv 0 \pmod{10^9+7}$$$. Print the value of $$$P \cdot Q^{-1}$$$ modulo $$$10^9+7$$$.

Input: 6 1

Output: 3

Input: 6 2

Output: 875000008

Input: 60 5

Output: 237178099

Input: 2 4

Output: 562500005

Input: 12 3

Output: 775462970

Input: 55 5

Output: 789062507

Input: 935 9

Output: 658825880

Input: 1 10000

Output: 1

Input: 120 1

Output: 500000026

Input: 1000000000000000 10000

Output: 215514159

Input: 671058194037157 8673

Output: 298638658

Input: 900018062553298 4801

Output: 345432320

Input: 128973636102142 5521

Output: 99152648

Input: 999999999999993 8123

Output: 868053217

Input: 260858031033600 9696

Output: 692221824

Input: 562949953421312 9779

Output: 98057767

Input: 357933504618282 1649

Output: 197730476

Input: 586884783199831 5073

Output: 883678085

Input: 187877211524483 8497

Output: 562808746

Input: 866421317361600 10000

Output: 82212846

Input: 782574093100800 9999

Output: 293217028

Input: 577614211574400 9998

Output: 681915605

Input: 65214507758400 9997

Output: 677959603

Input: 963761198400 9996

Output: 669401143

Input: 5587021440 9995

Output: 360750834

Input: 17297280 9994

Output: 94383698

Input: 7560 9993

Output: 412712546

Input: 120 9992

Output: 167656619

Input: 1 1

Output: 1

Input: 609359740010496 1337

Output: 263703037

Input: 912750790581630 9876

Output: 291557094

Input: 617673396283947 7777

Output: 488769014

Input: 890604418498560 9119

Output: 185509970

Input: 524288004718592 8888

Output: 851726115

Input: 999999999999989 8998

Output: 391873310

Input: 999999999999999 8123

Output: 41003922

Input: 817237005720659 4233

Output: 533017938

Input: 1000000007 1

Output: 500000004

Input: 1000000007 2

Output: 750000006

Input: 999999999999970 8998

Output: 939941657

Input: 900000060000001 8123

Output: 865356488

Input: 999011322032079 4233

Output: 546309400

Input: 999005327998113 9119

Output: 106270540

Input: 900000720000023 9876

Output: 511266473


The first line contains a single integer n (1 ≤ n ≤ 100) — the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≤ ai ≤ 600) — participants' scores. It's guaranteed that at least one participant has non-zero score.

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.TreeSet;
import java.util.Collections;

public class Hello
{
    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;
        }
    }

    public static void main(String[] args)
    {
        FastReader in=new FastReader();

        //start code here
        int n=in.nextInt();
        int res=0;
        ArrayList<Integer> al = new ArrayList<>();
        for(int i=0;i<n;++i)
        {
        	int x = in.nextInt();
        	if(x!=0&&!al.contains(x))
        	{
        		++res;
        		al.add(x);
        	}
        }
        System.out.print(res);
    }
}

NoteThere are three ways to choose a subset in sample case one.  Only participants with 3 points will get diplomas.  Participants with 2 or 3 points will get diplomas.  Everyone will get a diploma! The only option in sample case two is to award everyone.Note that in sample case three participants with zero scores cannot get anything.

Print a single integer — the desired number of ways.

The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:   At least one participant should get a diploma.  None of those with score equal to zero should get awarded.  When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas.

Input:
4
1 3 3 2

Output: 3

Input:
3
1 1 1

Output: 1

Input:
4
42 0 0 42

Output: 1

Input:
10
1 0 1 0 1 0 0 0 0 1

Output: 1

Input:
10
572 471 540 163 50 30 561 510 43 200

Output: 10

Input:
100
122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322 545 111 267 467 274 291 304 235 34 365 180 21 95 501 552 325 331 302 353 296 22 289 399 7 466 32 302 568 333 75 192 284 10 94 128 154 512 9 480 243 521 551 492 420 197 207 125 367 117 438 600

Output: 94

Input:
100
600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600

Output: 1

Input:
78
5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12

Output: 13

Input:
34
220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391

Output: 33

Input:
100
1 2 1 0 3 0 2 0 0 1 2 0 1 3 0 3 3 1 3 0 0 2 1 2 2 1 3 3 3 3 3 2 0 0 2 1 2 3 2 3 0 1 1 3 3 2 0 3 1 0 2 2 2 1 2 3 2 1 0 3 0 2 0 3 0 2 1 0 3 1 0 2 2 1 3 1 3 0 2 3 3 1 1 3 1 3 0 3 2 0 2 3 3 0 2 0 2 0 1 3

Output: 3

Input:
100
572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55

Output: 93

Input:
99
5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12 2 3 9 3 7 13 7 13 0 11 8 12 2 5 9 4 0 6 6 2 13

Output: 13

Input:
99
1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1

Output: 1

Input:
99
21 74 25 44 71 80 46 28 96 1 74 24 81 83 16 55 31 1 27 36 56 38 17 10 78 5 39 67 67 15 39 62 92 48 90 9 54 67 30 79 56 17 33 27 75 54 20 79 21 44 10 66 66 73 90 3 34 33 64 79 20 94 0 51 24 30 1 52 95 21 88 98 6 65 31 1 67 32 74 91 83 9 93 27 53 11 8 79 42 20 50 91 19 96 6 24 66 16 37

Output: 61

Input:
2
0 1

Output: 1

Input:
2
0 600

Output: 1

Input:
4
1 1 1 2

Output: 2

Input:
4
0 0 1 2

Output: 2

Input:
1
5

Output: 1

Input:
2
0 5

Output: 1

Input:
5
1 0 0 1 2

Output: 2


The first line contains integer $$$n$$$ $$$(3 \le n \le 100)$$$ — the length of the file name. The second line contains a string of length $$$n$$$ consisting of lowercase Latin letters only — the file name.

import java.util.*;
import java.lang.*;
import java.io.*;
public class A
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n,i,j,count,k;
        String t=br.readLine();
        n=Integer.parseInt(t);
        t=br.readLine();
        char[] s=t.toCharArray();
        k=0;
        for(i=0;i<n;)
        {
            if(s[i]=='x')
            {
                count=1;
                for(j=i+1;j<n;j++)
                {
                    if(s[j]=='x')
                    count=count+1;
                    else
                    break;
                }
                i=i+count;
                if(count!=1)
                k=k+(count-2);
            }
            else
            i=i+1;
        }
        System.out.println(k);
    }
}

NoteIn the first example Polycarp tried to send a file with name contains number $$$33$$$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.

Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.

You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx".You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $$$1$$$. For example, if you delete the character in the position $$$2$$$ from the string "exxxii", then the resulting string is "exxii".

Input:
6
xxxiii

Output: 1

Output: 1

Output: 1

Input:
5
xxoxx

Output: 0

Output: 0

Output: 0

Input:
10
xxxxxxxxxx

Output: 8

Output: 8

Output: 8

Input:
100
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Output: 98

Output: 98

Output: 98

Input:
99
xxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa

Output: 0

Output: 0

Output: 0

Input:
3
xxx

Output: 1

Output: 1

Output: 1

Input:
77
aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxyyyzzz

Output: 0

Output: 0

Output: 0

Input:
100
uxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxxxxmrx

Output: 41

Output: 41

Output: 41

Input:
100
xxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc

Output: 49

Output: 49

Output: 49

Input:
100
uxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx

Output: 41

Output: 41

Output: 41

Input:
34
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Output: 0

Output: 0

Output: 0

Input:
5
fcyju

Output: 0

Output: 0

Output: 0

Input:
100
ihygyvdvyeifomhxhkhdkimquvgallbqharcyriyqkidnwykozuhvkwdldlztpabgyuflikychqpdenwzgtlzotyumjgdsrbxxxx

Output: 2

Output: 2

Output: 2

[{'input': '100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx\r\n', 'output': ['41', '41\r\n', '41\n']}, {'input': '99\r\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '5\r\nfcyju\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '100\r\nxxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc\r\n', 'output': ['49', '49\n', '49\r\n']}, {'input': '6\r\nxxxiii\r\n', 'output': ['1\r\n', '1', '1\n']}]

[{'input': '100\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n', 'output': ['98', '98\n', '98\r\n']}, {'input': '5\r\nfcyju\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '34\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx\r\n', 'output': ['41', '41\r\n', '41\n']}, {'input': '3\r\nxxx\r\n', 'output': ['1\r\n', '1', '1\n']}]

[{'input': '100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx\r\n', 'output': ['41', '41\r\n', '41\n']}, {'input': '99\r\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '5\r\nfcyju\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '100\r\nxxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc\r\n', 'output': ['49', '49\n', '49\r\n']}, {'input': '100\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n', 'output': ['98', '98\n', '98\r\n']}]

[{'input': '100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx\r\n', 'output': ['41', '41\r\n', '41\n']}, {'input': '5\r\nxxoxx\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '10\r\nxxxxxxxxxx\r\n', 'output': ['8\n', '8', '8\r\n']}, {'input': '100\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n', 'output': ['98', '98\n', '98\r\n']}, {'input': '34\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['0\r\n', '0\n', '0']}]

[{'input': '100\r\nihygyvdvyeifomhxhkhdkimquvgallbqharcyriyqkidnwykozuhvkwdldlztpabgyuflikychqpdenwzgtlzotyumjgdsrbxxxx\r\n', 'output': ['2', '2\n', '2\r\n']}, {'input': '100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx\r\n', 'output': ['41', '41\r\n', '41\n']}, {'input': '5\r\nxxoxx\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '10\r\nxxxxxxxxxx\r\n', 'output': ['8\n', '8', '8\r\n']}, {'input': '3\r\nxxx\r\n', 'output': ['1\r\n', '1', '1\n']}]


The only line of input contains two integers r and g, separated by a single space — the number of available red and green blocks respectively (0 ≤ r, g ≤ 2·105, r + g ≥ 1).

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Abood2D {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int R = sc.nextInt();
		int G = sc.nextInt();

		int sum = G + R;
		int H = sum == 1? 1 : 0;
		while(sum >= H)
			sum -= H++;
		H--;

		int[] acc = new int[H + 1];

		for (int i = 1; i <= H; i++)
			acc[i] = acc[i - 1] + i;

		int[] last = new int[R + 1];
		Arrays.fill(last, 1);

		for (int i = H - 1; i >= 0; i--) {
			int[] cur = new int[R + 1];

			for (int j = 0; j < cur.length; j++) {
				int r = j;
				int g = G - (acc[i] - (R - r));

				if(g - i >= 1)
					cur[j] += last[j];
				if(r - i >= 1)
					cur[j] += last[j - (i + 1)];

				cur[j] %= (int) 1e9 + 7;
			}
			last = cur;
		}

		out.print(last[R]);

		out.flush();

	}

	static class Scanner

	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}

	}

}

NoteThe image in the problem statement shows all possible red-green towers for the first sample.

Output the only integer — the number of different possible red-green towers of height h modulo 109 + 7.

There are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next rules:  Red-green tower is consisting of some number of levels;  Let the red-green tower consist of n levels, then the first level of this tower should consist of n blocks, second level — of n - 1 blocks, the third one — of n - 2 blocks, and so on — the last level of such tower should consist of the one block. In other words, each successive level should contain one block less than the previous one;  Each level of the red-green tower should contain blocks of the same color.  Let h be the maximum possible number of levels of red-green tower, that can be built out of r red and g green blocks meeting the rules above. The task is to determine how many different red-green towers having h levels can be built out of the available blocks.Two red-green towers are considered different if there exists some level, that consists of red blocks in the one tower and consists of green blocks in the other tower.You are to write a program that will find the number of different red-green towers of height h modulo 109 + 7.

Input: 4 6

Output: 2

Input: 9 7

Output: 6

Input: 1 1

Output: 2

Input: 3 3

Output: 2

Input: 2 19

Output: 1

Input: 18 3

Output: 2

Input: 100000 1

Output: 2

Input: 1 100000

Output: 2

Input: 6 6

Output: 6

Input: 10 10

Output: 18

Input: 200000 200000

Output: 206874596

Input: 0 1

Output: 1

Input: 1 0

Output: 1

Input: 0 200000

Output: 1

Input: 200000 0

Output: 1

Input: 199396 0

Output: 1

Input: 199395 0

Output: 1

Input: 0 199397

Output: 1

Input: 121147 78249

Output: 64290784

Input: 78250 121147

Output: 981737243

Input: 121146 78249

Output: 832902708

Input: 199585 199586

Output: 438320405

Input: 199586 199586

Output: 876640810

Input: 199585 199585

Output: 199771918

Input: 107344 159729

Output: 849320920

Input: 2954 1977

Output: 835530858

Input: 25580 17318

Output: 263898876

Input: 89671 32487

Output: 654128709

Input: 38 36

Output: 612

Input: 136749 183300

Output: 906576609

Input: 10000 10000

Output: 885988055

Input: 200000 199999

Output: 396481680


The first and only line contains an integer $$$r$$$ ($$$1 \le r \le 10^{12}$$$).

//1184A1
import java.util.*;
public class heidiA1{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    long r=sc.nextLong();
    if(r%2==0||r<=3)
    System.out.println("NO");
    else{
      System.out.println("1"+" "+((r-3)/2));
    }
  }
}

Output integers $$$x, y$$$ such that $$$H(x,y) = r$$$ and $$$x$$$ is smallest possible, or "NO" if no such pair exists.

Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor.Heidi figured out that Madame Kovarian uses a very complicated hashing function in order to change the names of the babies she steals. In order to prevent this from happening to future Doctors, Heidi decided to prepare herself by learning some basic hashing techniques.The first hashing function she designed is as follows.Given two positive integers $$$(x, y)$$$ she defines $$$H(x,y):=x^2+2xy+x+1$$$.Now, Heidi wonders if the function is reversible. That is, given a positive integer $$$r$$$, can you find a pair $$$(x, y)$$$ (of positive integers) such that $$$H(x, y) = r$$$?If multiple such pairs exist, output the one with smallest possible $$$x$$$. If there is no such pair, output "NO".

Output: 1 8

Output: NO

Output: NO

Output: NO

Output: NO

Output: NO

Output: 1 1

Output: NO

Output: 1 2

Output: NO

Output: 1 3

Output: NO

Output: 1 4

Output: NO

Output: 1 5

Output: NO

Output: 1 6

Output: 1 7

Output: NO

Output: NO

Output: 1 9

Output: NO

Output: 1 125438957286

Output: NO

Output: 1 270012489721

Output: NO

Output: 1 481311845039

Output: 1 27216966722

Output: 1 8238095313

Output: 1 213131351747

Output: NO

Output: 1 326254668074

Output: 1 107641736080

Output: 1 14808958

Output: 1 3752647541

Output: 1 74945464857

Output: 1 92794535371

Output: 1 209725418

Output: 1 259698839699

Output: 1 471723986317

Output: 1 27168154584

Output: 1 344186525357

Output: 1 78115826635

Output: 1 11872249199

Output: 1 384203699087

Output: 1 481880599199

Output: 1 120470149799


The only line contains two integers $$$n$$$ and $$$p$$$ ($$$1 \leq n \leq 10^9$$$, $$$-1000 \leq p \leq 1000$$$).

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

public class TaskC {
    public static String doMain(Reader reader) throws IOException {
        MyReader in = new MyReader(reader);
        int n = in.nextInt();
        int p = in.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; n - i * p >= i; ++i) {
            int count = check(n - p * i);
            if (count > i){
                continue;
            }
            return i+"";
        }
        return "-1";
    }

    private static int check(int n) {
        int answer = 0;
        while (n > 0) {
            answer += n % 2;
            n /= 2;
        }
        return answer;
    }

    public static void main(String[] args) throws IOException {
        String result = doMain(new InputStreamReader(System.in));
        System.out.println(result);
    }

    static class MyReader {
        BufferedReader bf;

        StringTokenizer st;

        String last;

        MyReader(Reader reader) throws IOException {
            bf = new BufferedReader(reader);
            readNextLine();
        }

        String nextToken() throws IOException {
            while (!st.hasMoreTokens()) {
                readNextLine();
            }
            return st.nextToken();
        }

        void readNextLine() throws IOException {
            last = bf.readLine();
            if (last == null) last = "";
            st = new StringTokenizer(last);
        }

        String nextLine() throws IOException {
            String s = last;
            readNextLine();
            return s;
        }

        long nextLong() throws IOException {
            return Long.parseLong(nextToken());
        }

        int nextInt() throws IOException {
            return Integer.parseInt(nextToken());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(nextToken());
        }

        int[] readIntArray(int n) throws IOException {
            int[] answer = new int[n];
            for (int i = 0; i < n; ++i) {
                answer[i] = nextInt();
            }
            return answer;
        }

        long[] readLongArray(int n) throws IOException {
            long[] answer = new long[n];
            for (int i = 0; i < n; ++i) {
                answer[i] = nextLong();
            }
            return answer;
        }

        double[] readDoubleArray(int n) throws IOException {
            double[] answer = new double[n];
            for (int i = 0; i < n; ++i) {
                answer[i] = nextDouble();
            }
            return answer;
        }
    }
}

Note$$$0$$$-binary numbers are just regular binary powers, thus in the first sample case we can represent $$$24 = (2^4 + 0) + (2^3 + 0)$$$.In the second sample case, we can represent $$$24 = (2^4 + 1) + (2^2 + 1) + (2^0 + 1)$$$.In the third sample case, we can represent $$$24 = (2^4 - 1) + (2^2 - 1) + (2^2 - 1) + (2^2 - 1)$$$. Note that repeated summands are allowed.In the fourth sample case, we can represent $$$4 = (2^4 - 7) + (2^1 - 7)$$$. Note that the second summand is negative, which is allowed.In the fifth sample case, no representation is possible.

If it is impossible to represent $$$n$$$ as the sum of any number of $$$p$$$-binary numbers, print a single integer $$$-1$$$. Otherwise, print the smallest possible number of summands.

Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer $$$p$$$ (which may be positive, negative, or zero). To combine their tastes, they invented $$$p$$$-binary numbers of the form $$$2^x + p$$$, where $$$x$$$ is a non-negative integer.For example, some $$$-9$$$-binary ("minus nine" binary) numbers are: $$$-8$$$ (minus eight), $$$7$$$ and $$$1015$$$ ($$$-8=2^0-9$$$, $$$7=2^4-9$$$, $$$1015=2^{10}-9$$$).The boys now use $$$p$$$-binary numbers to represent everything. They now face a problem: given a positive integer $$$n$$$, what's the smallest number of $$$p$$$-binary numbers (not necessarily distinct) they need to represent $$$n$$$ as their sum? It may be possible that representation is impossible altogether. Help them solve this problem.For example, if $$$p=0$$$ we can represent $$$7$$$ as $$$2^0 + 2^1 + 2^2$$$.And if $$$p=-9$$$ we can represent $$$7$$$ as one number $$$(2^4-9)$$$.Note that negative $$$p$$$-binary numbers are allowed to be in the sum (see the Notes section for an example).

Input: 24 0

Output: 2

Input: 24 1

Output: 3

Input: 24 -1

Output: 4

Input: 4 -7

Output: 2

Input: 1 1

Output: -1

Input: 10 7

Output: -1

Input: 3 -179

Output: 5

Input: 12345678 -123

Output: 12

Input: 1000000000 1000

Output: 16

Input: 1 0

Output: 1

Input: 1 -1

Output: 1

Input: 536870912 0

Output: 1

Input: 536870911 0

Output: 29

Input: 1 -1000

Output: 8

Input: 100500 -179

Output: 8

Input: 1000000000 -1000

Output: 14

Input: 536870812 1

Output: 24

Input: 536870812 -1

Output: 26

Input: 1 1000

Output: -1

Input: 1001 1000

Output: 1

Input: 13 -987

Output: 7

Input: 101 50

Output: -1

Input: 1001 500

Output: -1

Input: 13 6

Output: -1

Input: 5 2

Output: -1

Input: 67108838 -1

Output: 26

Input: 11 5

Output: -1

Input: 19 6

Output: -1

Input: 21 10

Output: -1

Input: 2001 1000

Output: -1

Input: 17 8

Output: -1

Input: 3002 1000

Output: -1

Input: 332639425 -399

Output: 13

Input: 9 8

Output: 1

Input: 3 2

Output: 1

Input: 678 169

Output: -1

Input: 2 1

Output: 1

Input: 9 4

Output: -1

Input: 29 9

Output: -1

Input: 782 156

Output: -1

Input: 1999 999

Output: -1

Input: 47 23

Output: -1

Input: 3998 999

Output: -1

Input: 4 3

Output: 1

Input: 746 248

Output: -1

Input: 2 -1000

Output: 8

Input: 35 11

Output: -1

Input: 16777215 0

Output: 24


The only line contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$), denoting the required number of vertices.

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

public class E {

	static int[] tree;

	static void fill(int idx) {
		if (idx >= tree.length) return;
		fill(2 * idx);
		fill(2 * idx + 1);
		tree[idx] = 1;
		if (2 * idx < tree.length) tree[idx] += tree[2 * idx];
		if (2 * idx + 1 < tree.length) tree[idx] += tree[2 * idx + 1];
	}

	static boolean shouldAdd(int idx) {
		if (idx % 2 == 1) return true;
		while (idx % 2 == 0) {
			idx /= 2;
		}
		return tree[2 * idx] % 2 == 0;
	}

	static void add(int idx) {
		while (idx >= 1) {
			tree[idx]++;
			idx /= 2;
		}
	}

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int level = 0, got = 1;
		while (N >= got) {
			N -= got;
			level++;
			got *= 2;
		}
		tree = new int[1 << level];
		fill(1);
		for (int i = tree.length - 1; i > 1 << (level-1); i--) {
			if (shouldAdd(i)) {
				add(i);
				N--;
			}
		}

		out.println(N == 0 || N == 1 ? 1 : 0);

		out.flush();
	}

	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;

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

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

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

NoteIn the first example, this is the only tree that satisfies the conditions: In the second example, here are various trees that don't satisfy some condition:

Output the number of perfectly balanced striped binary search trees with $$$n$$$ vertices and distinct integer keys between $$$1$$$ and $$$n$$$, inclusive, modulo $$$998\,244\,353$$$.

Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than any key stored in the right subtree.The depth of a vertex is the number of edges on the simple path from the vertex to the root. In particular, the depth of the root is $$$0$$$.Let's call a binary search tree perfectly balanced if there doesn't exist a binary search tree with the same number of vertices that has a strictly smaller sum of depths of its vertices.Let's call a binary search tree with integer keys striped if both of the following conditions are satisfied for every vertex $$$v$$$:   If $$$v$$$ has a left subtree whose root is $$$u$$$, then the parity of the key of $$$v$$$ is different from the parity of the key of $$$u$$$.  If $$$v$$$ has a right subtree whose root is $$$w$$$, then the parity of the key of $$$v$$$ is the same as the parity of the key of $$$w$$$. You are given a single integer $$$n$$$. Find the number of perfectly balanced striped binary search trees with $$$n$$$ vertices that have distinct integer keys between $$$1$$$ and $$$n$$$, inclusive. Output this number modulo $$$998\,244\,353$$$.


The only line contains two integers a, b (1 ≤ a ≤ b ≤ 106) — the first and the last number typed by Max.

/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
import java.math.*;
public class S {
	public static void main (String[] args) {
	    Scanner in=new Scanner(System.in);
		int a=in.nextInt();
		int b=in.nextInt();
		Map<Character,Integer> m= new HashMap<>();
		m.put('0',6);m.put('1',2);m.put('2',5);m.put('3',5);m.put('4',4);m.put('5',5);m.put('6',6);m.put('7',3);
		m.put('8',7);m.put('9',6);
		int r=0;
		for(int i=a;i<=b;i++)
		{
		    String s=String.valueOf(i);
		    for(int j=0;j<s.length();j++)
		    {
		        r=r+m.get(s.charAt(j));
		    }
		}
		System.out.println(r);
	}
}

Print the only integer a — the total number of printed segments.

Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display).  Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.For example if a = 1 and b = 3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.

Input: 1 3

Output: 12

Input: 10 15

Output: 39

Input: 1 100

Output: 928

Input: 100 10000

Output: 188446

Input: 213 221442

Output: 5645356

Input: 1 1000000

Output: 28733372

Input: 1000000 1000000

Output: 38

Input: 222145 353252

Output: 3860750

Input: 2 1000000

Output: 28733370

Input: 1 999999

Output: 28733334

Input: 192 200

Output: 122


The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).

//package com.company;
import java.io.*;
public class Main {
    public static void main(String[] args)throws IOException{
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        String[] line = buffer.readLine().split(" ");
        int nodes = Integer.parseInt(line[0]);
        int height = Integer.parseInt(line[1]);
        int n = 36;
        long[][] dynamic = new long[n][n];

        //fill first column with 1s, creates buffer
        for(int i = 0 ; i < n; i++)
            dynamic[0][i] = 1;

        //count all the trees
        for(int i = 1; i < n; i++){
            for(int j = 1; j < n; j++){
                for(int k = 0; k < i ;k++)
                    dynamic[i][j] += dynamic[k][j - 1] * dynamic[i - k - 1][j - 1];
            }
        }
        //the amount of trees to jump
        System.out.println(dynamic[nodes][35] - dynamic[nodes][height - 1]);
    }
}

Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.

In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?

Input: 3 2

Output: 5

Input: 3 3

Output: 4

Input: 1 1

Output: 1

Input: 2 1

Output: 2

Input: 2 2

Output: 2

Input: 27 11

Output: 61162698256896

Input: 32 27

Output: 22643872890880

Input: 4 1

Output: 14

Input: 9 1

Output: 4862

Input: 33 4

Output: 212336130412243110

Input: 4 4

Output: 8

Input: 8 5

Output: 1336

Input: 12 8

Output: 127200

Input: 15 5

Output: 9694844

Input: 19 18

Output: 2424832

Input: 23 17

Output: 19649347584

Input: 27 15

Output: 25162319484928

Input: 29 14

Output: 577801978306560

Input: 33 18

Output: 54307238601375744

Input: 7 7

Output: 64

Input: 23 21

Output: 275251200

Input: 7 3

Output: 429

Input: 21 18

Output: 211156992

Input: 21 12

Output: 12153990144

Input: 35 13

Output: 2690352397519398400

Input: 19 2

Output: 1767263190

Input: 33 26

Output: 434871797284864

Input: 16 9

Output: 25607552

Input: 16 14

Output: 1032192

Input: 10 2

Output: 16796

Input: 33 17

Output: 75307983624118272

Input: 27 25

Output: 6081740800

Input: 20 14

Output: 1094473728

Input: 16 11

Output: 11819008

Input: 10 10

Output: 512

Input: 4 3

Output: 14

Input: 33 21

Output: 14830955929665536

Input: 24 20

Output: 8171945984

Input: 30 16

Output: 1375710400053248

Input: 9 4

Output: 4862

Input: 16 5

Output: 35357670

Input: 22 22

Output: 2097152

Input: 28 23

Output: 739948625920

Input: 34 1

Output: 812944042149730764

Input: 7 4

Output: 428

Input: 14 11

Output: 488448

Input: 35 1

Output: 3116285494907301262

Input: 35 35

Output: 17179869184


In the only line you are given two integers a, b (0 ≤ a, b ≤ 100) — the number of even and odd steps, accordingly.

import java.util.*;
public class A761 {
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m =sc.nextInt();
        if(Math.abs(m-n) == 1 || (m+n!=0  && m==n) )
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
    }

}

NoteIn the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5.

In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.

On her way to programming school tiger Dasha faced her first test — a huge staircase!  The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers. You need to check whether there is an interval of steps from the l-th to the r-th (1 ≤ l ≤ r), for which values that Dasha has found are correct.

Input: 2 3

Output: YES

Input: 3 1

Output: NO

Input: 5 4

Output: YES

Input: 9 9

Output: YES

Input: 85 95

Output: NO

Input: 0 1

Output: YES

Input: 89 25

Output: NO

Input: 74 73

Output: YES

Input: 62 39

Output: NO

Input: 57 57

Output: YES

Input: 100 99

Output: YES

Input: 0 0

Output: NO

Input: 98 100

Output: NO

Input: 99 100

Output: YES

Input: 1 0

Output: YES

Input: 100 0

Output: NO

Input: 0 100

Output: NO

Input: 100 98

Output: NO

Input: 100 100

Output: YES

Input: 0 5

Output: NO

Input: 2 2

Output: YES


The first line contains a non-empty string s — the sum Xenia needs to count. String s contains no spaces. It only contains digits and characters "+". Besides, string s is a correct sum of numbers 1, 2 and 3. String s is at most 100 characters long.

import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
 public static void main(String[] args) {
        Scanner lector = new Scanner(System.in);
        PriorityQueue<Integer> list = new PriorityQueue();
        String s = lector.next();
        int x;

        for(char c:s.toCharArray()){
            if(c!='+'){
                list.add(c-48);
            }
        }

        x = list.size();

        for (int i = 0; i < (x-1); i++) {
             System.out.print(list.poll()+"+");
        }
            System.out.println(list.poll());
    } }
// 1509316386944

Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.

Input: 2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1

Output: 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3

Input: 2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1

Output: 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3

Input: 2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2

Output: 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3

Input: 3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3

Output: 1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3


The first (and the only) line of input contains two integers n and k (1 ≤ n, k ≤ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.

import java.io.*;

 import java.util.*;

    public class Training {

      public static void main(String[] args) throws IOException {
        Scanner input = new Scanner(System.in);
        long n = input.nextLong(),k= input.nextLong();

         long a  = n/2/(k+1);
         long b = a *k  ;
          System.out.println(a +" "+b+" "+(n-a-b));

     }  // end main

    }

Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.

There are n students who have taken part in an olympiad. Now it's time to award the students.Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.

Input: 18 2

Output: 3 6 9

Input: 9 10

Output: 0 0 9

Input: 1000000000000 5

Output: 83333333333 416666666665 500000000002

Input: 1000000000000 499999999999

Output: 1 499999999999 500000000000

Input: 1 1

Output: 0 0 1

Input: 5 3

Output: 0 0 5

Input: 42 6

Output: 3 18 21

Input: 1000000000000 1000

Output: 499500499 499500499000 500000000501

Input: 999999999999 999999

Output: 499999 499998500001 500000999999

Input: 732577309725 132613

Output: 2762066 366285858458 366288689201

Input: 152326362626 15

Output: 4760198832 71402982480 76163181314

Input: 2 1

Output: 0 0 2

Input: 1000000000000 500000000000

Output: 0 0 1000000000000

Input: 100000000000 50000000011

Output: 0 0 100000000000

Input: 1000000000000 32416187567

Output: 15 486242813505 513757186480

Input: 1000000000000 7777777777

Output: 64 497777777728 502222222208

Input: 1000000000000 77777777777

Output: 6 466666666662 533333333332

Input: 100000000000 578485652

Output: 86 49749766072 50250233842

Input: 999999999999 10000000000

Output: 49 490000000000 509999999950

Input: 7 2

Output: 1 2 4

Input: 420506530901 752346673804

Output: 0 0 420506530901

Input: 960375521135 321688347872

Output: 1 321688347872 638687173262

Input: 1000000000000 1000000000000

Output: 0 0 1000000000000

Input: 99999999999 15253636363

Output: 3 45760909089 54239090907

Input: 19 2

Output: 3 6 10

Input: 999999999999 1000000000000

Output: 0 0 999999999999

Input: 1000000000000 5915587276

Output: 84 496909331184 503090668732

Input: 1000000000000 1000000006

Output: 499 499000002994 500999996507

Input: 549755813888 134217728

Output: 2047 274743689216 275012122625

Input: 99999999999 3333333

Output: 14999 49996661667 50003323333

Input: 9 1

Output: 2 2 5

Input: 1000000000000 250000000001

Output: 1 250000000001 749999999998

Input: 5 1

Output: 1 1 3

Input: 3107038133 596040207

Output: 2 1192080414 1914957717

Input: 1000000000000 73786977

Output: 6776 499980556152 500019437072

Input: 1000000000000 73786976

Output: 6776 499980549376 500019443848

Input: 1000000000000 25000000000

Output: 19 475000000000 524999999981

Input: 216929598879 768233755932

Output: 0 0 216929598879

Input: 1000000000000 250000000000

Output: 1 250000000000 749999999999

Input: 1000000000000 100000000001

Output: 4 400000000004 599999999992

Input: 100000000000 100000000001

Output: 0 0 100000000000

Input: 900000000000 100281800001

Output: 4 401127200004 498872799992

Input: 906028900004 109123020071

Output: 4 436492080284 469536819716

Input: 1000000000000 1

Output: 250000000000 250000000000 500000000000


The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend's house.

import java.util.Scanner;
public class Slonik {

     public static void main(String[] args){
            Scanner scan = new Scanner(System.in);
            int input = scan.nextInt();

            float min = input / 5f;
            System.out.println((int)Math.ceil(min));
        }
    }

NoteIn the first sample the elephant needs to make one step of length 5 to reach the point x.In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves.

Print the minimum number of steps that elephant needs to make to get from point 0 to point x.

An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.


The first line contains a single integer n (1 ≤ n ≤ 5). Next n lines contain four integers each, describing a single rectangle: x1, y1, x2, y2 (0 ≤ x1 < x2 ≤ 31400, 0 ≤ y1 < y2 ≤ 31400) — x1 and x2 are x-coordinates of the left and right edges of the rectangle, and y1 and y2 are y-coordinates of the bottom and top edges of the rectangle.  No two rectangles overlap (that is, there are no points that belong to the interior of more than one rectangle).

import java.util.Scanner;

public class Main {
    private static final int MAXN = 4000000;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] areas = new int[n];
        int left = MAXN, right = 0, top = MAXN, bottom = 0;
        for(int i = 0; i < n; i++) {
            int x1, y1, x2, y2;
            x1 = scanner.nextInt();
            y1 = scanner.nextInt();
            x2 = scanner.nextInt();
            y2 = scanner.nextInt();

            areas[i] = (x2 - x1) * (y2 - y1);
            left = Math.min(x1, left);
            right = Math.max(x2, right);
            top = Math.min(y1, top);
            bottom = Math.max(y2, bottom);
        }

        int total = (right - left) * (bottom - top);
        int result = 0;
        for(int i = 0; i < n; i++) {
           result += areas[i];
        }

        if((total == result) && ((right - left)  == (bottom - top))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

In a single line print "YES", if the given rectangles form a square, or "NO" otherwise.

You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Your task is to determine if the rectangles form a square. In other words, determine if the set of points inside or on the border of at least one rectangle is precisely equal to the set of points inside or on the border of some square.

Input:
5
0 0 2 3
0 3 3 5
2 0 5 2
3 2 5 5
2 2 3 3

Output: YES

Input:
4
0 0 2 3
0 3 3 5
2 0 5 2
3 2 5 5

Output: NO

Input:
5
0 0 10000 20000
10000 0 15000 19999
10000 19999 14999 20000
0 20000 15000 31400
15000 0 31400 31400

Output: NO

Input:
5
0 0 10000 20000
10000 0 15000 19999
10000 19999 15000 20000
0 20000 15000 31400
15000 0 31400 31400

Output: YES

Input:
5
10359 859 28918 4384
2895 26520 28918 26882
2895 26424 28918 26520
2895 859 10359 4384
2895 4384 28918 26424

Output: YES

Input:
5
12750 0 25688 1
1094 0 12750 1
0 0 956 1
956 0 1094 1
25688 0 31400 1

Output: NO

Input:
4
18006 16484 25725 31400
0 0 31400 16484
29563 16484 31400 31400
25725 16484 29563 31400

Output: NO

Input:
1
0 0 31400 31400

Output: YES

Input:
2
0 0 31400 13313
0 13313 31400 31400

Output: YES

Input:
3
0 9388 31400 31400
26020 0 31400 9388
0 0 26020 9388

Output: YES

Input:
5
15164 0 19356 3925
0 0 15164 31400
15164 3925 31400 31400
19356 3278 31400 3925
19356 0 31400 3278

Output: YES

Input:
5
20421 5189 23141 12511
16414 10436 17880 12511
17880 10436 20421 12511
15819 10436 16414 12511
15819 5189 20421 10436

Output: YES

Input:
1
15819 5189 23141 12511

Output: YES

Input:
3
12052 12345 12343 18147
12343 12345 12345 18147
6543 12345 12052 18147

Output: YES

Input:
5
12750 0 25688 1
1094 0 12750 1
0 0 956 1
956 0 1094 1
25688 0 31400 1

Output: NO

Input:
5
0 7098 1 7460
0 7460 1 15218
0 15218 1 31400
0 4974 1 7098
0 0 1 4974

Output: NO

Input:
1
0 0 31400 1

Output: NO

Input:
1
0 0 1 31400

Output: NO

Input:
5
0 25169 1 27914
0 0 1 1366
0 10763 1 25169
0 1366 1 10138
0 27914 1 31400

Output: NO

Input:
1
0 0 10575 1

Output: NO

Input:
1
0 3006 1 17592

Output: NO

Input:
1
123 4819 5819 29511

Output: NO

Input:
3
123 4819 5819 6612
123 6612 5819 12692
123 12692 5819 29511

Output: NO

Input:
5
3091 4819 5743 13222
123 13222 5819 29511
5743 4819 5819 13222
123 4819 2215 13222
2215 4819 3091 13222

Output: NO

Input:
5
8030 7681 8491 7682
8491 7681 8961 7682
7666 7681 7963 7682
7963 7681 8030 7682
678 7681 7666 7682

Output: NO

Input:
5
1234 1234 1235 1235
1238 1234 1239 1235
1235 1234 1236 1235
1237 1234 1238 1235
1236 1234 1237 1235

Output: NO

Input:
5
20812 5661 27208 5898
20812 581 29415 5661
27539 5661 29415 5898
18961 581 20812 5898
27208 5661 27539 5898

Output: NO

Input:
1
31399 31399 31400 31400

Output: YES

Input:
1
20499 0 31400 22815

Output: NO

Input:
2
0 1273 26470 9100
0 16615 31400 31400

Output: NO

Input:
3
25784 0 31400 20408
0 20408 31400 20582
15802 0 18106 20408

Output: NO

Input:
4
18006 16484 25725 31400
0 0 31400 16484
29563 16484 31400 31400
25725 16484 29563 31400

Output: NO

Input:
5
26466 0 26474 6206
10906 0 17073 6321
19720 0 26356 31400
0 0 10906 7852
0 21437 18466 31400

Output: NO

Input:
5
1338 31399 1525 31400
1525 31399 2595 31400
961 31399 1338 31400
2956 31399 31400 31400
2595 31399 2956 31400

Output: NO

Input:
5
1349 0 1391 3766
1234 0 1238 417
1391 0 5000 3766
1234 417 1238 3766
1238 0 1349 3766

Output: YES

Input:
5
0 0 100 30000
100 0 31400 5000
100 5000 20000 30000
0 30000 20000 31400
20000 5000 31400 31400

Output: YES

Input:
5
0 0 100 30000
100 0 31400 5000
100 5000 20000 30000
0 30000 20000 31000
20000 5000 31400 31000

Output: NO

Input:
5
8591 1234 9517 19512
696 19512 9517 31400
696 696 8591 19512
8591 696 31400 1234
9517 1234 31400 31400

Output: YES

Input:
5
0 0 1 1
0 3 1 4
0 1 1 2
0 2 1 3
0 4 1 5

Output: NO

Input:
4
0 0 1 2
0 3 1 4
0 4 1 5
0 2 1 3

Output: NO

Input:
3
0 1 1 3
0 3 1 5
0 0 1 1

Output: NO

Input:
1
0 0 1 5

Output: NO

Input:
4
0 0 2 1
2 0 3 2
0 1 1 3
1 2 3 3

Output: NO

Input:
5
0 0 2 1
2 0 3 2
0 1 1 3
1 2 3 3
1 1 2 2

Output: YES

Input:
1
0 0 1 1

Output: YES

Input:
1
0 0 31400 31400

Output: YES

Input:
2
0 0 10000 31400
10000 0 31400 31400

Output: YES

Input:
2
0 0 10000 31400
10000 0 31400 31399

Output: NO

Input:
2
0 0 1 18
5 0 6 18

Output: NO

Input:
1
0 0 1 4

Output: NO

Input:
2
0 0 2 6
2 2 4 4

Output: NO

Input:
2
2 2 3 3
4 4 6 7

Output: NO

Input:
2
0 0 1 1
1 0 2 1

Output: NO

Input:
2
0 0 1 1
2 2 3 3

Output: NO

Input:
4
0 0 1 1
5 5 6 6
10 10 11 11
13 13 14 14

Output: NO

Input:
5
1 1 3 5
3 3 5 5
4 1 5 3
3 1 4 2
2 5 3 6

Output: NO

Input:
4
10 10 11 11
11 11 12 12
11 10 12 11
9 12 10 13

Output: NO

Input:
2
0 0 2 4
10 0 12 4

Output: NO

Input:
4
0 0 1 1
0 1 1 2
0 2 1 3
0 3 1 4

Output: NO

Input:
2
0 0 1 1
3 3 4 4

Output: NO

Input:
2
0 0 3 1
0 2 3 3

Output: NO

Input:
2
1 1 5 5
1 5 5 7

Output: NO

Input:
3
0 0 1 1
1 0 3 3
0 2 1 4

Output: NO

Input:
4
0 0 10 10
10 10 20 20
10 0 20 10
10 20 11 120

Output: NO

Input:
1
0 0 1 7

Output: NO

Input:
4
0 0 4 2
0 2 3 6
3 4 6 6
4 0 6 4

Output: NO

Input:
2
0 0 1 1
1 1 2 2

Output: NO

Input:
2
1 1 2 2
3 3 4 4

Output: NO


The first line contains three integers n, m, s (1 ≤ n, m, s ≤ 106) — length of the board, width of the board and length of the flea's jump.

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

public class practice {
	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;
        }
    }
	static class Print
	{
	    private final BufferedWriter bw;
	    public Print()
	    {
	        bw=new BufferedWriter(new OutputStreamWriter(System.out));
	    }
	    public void print(String str)throws IOException
	    {
	        bw.append(str);
	    }
	    public void println(String str)throws IOException
	    {
	        print(str);
	        bw.append("\n");
	    }
	    public void close()throws IOException
	    {
	        bw.close();
	    }}
		public static void main(String[] args) throws IOException {
			FastReader scn=new FastReader();
			Print p=new Print();
			long n=scn.nextLong(),m=scn.nextLong(),s=scn.nextLong();
			long ans=((n-1)/s+1)*((m-1)/s+1)*((n-1)%s+1)*((m-1)%s+1);
			p.println(Long.toString(ans));

			p.close();

		}
}

Output the only integer — the number of the required starting positions of the flea.

It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (each cell is 1 × 1 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. The only restriction is that she cannot jump out of the board.The flea can count the amount of cells that she can reach from the starting position (x, y). Let's denote this amount by dx, y. Your task is to find the number of such starting positions (x, y), which have the maximum possible value of dx, y.

Input: 2 3 1000000

Output: 6

Input: 3 3 2

Output: 4

Input: 1 2 3

Output: 2

Input: 4 5 6

Output: 20

Input: 9 8 7

Output: 8

Input: 1000 1000 1000

Output: 1000000

Input: 1 1 1

Output: 1

Input: 1 1 2

Output: 1

Input: 1 1 1000000

Output: 1

Input: 1000000 1000000 1

Output: 1000000000000

Input: 1000000 1000000 2

Output: 1000000000000

Input: 1000000 1000000 999999

Output: 4

Input: 1000000 1000000 12345

Output: 20340100

Input: 1000000 1000000 123456

Output: 12358324224

Input: 43496 179847 327622

Output: 7822625112

Input: 105126 379125 460772

Output: 39855894750

Input: 999463 261665 981183

Output: 9566472400

Input: 836832 336228 50

Output: 100850467200

Input: 303307 400683 999941

Output: 121529958681

Input: 40224 890892 54

Output: 31858297920

Input: 109785 447109 990618

Output: 49085861565

Input: 228385 744978 699604

Output: 20725481980

Input: 694117 431924 737

Output: 13934440800

Input: 923179 799988 998430

Output: 738532121852

Input: 61043 55049 998379

Output: 3360356107

Input: 402841 635488 997633

Output: 256000621408

Input: 213927 672636 865

Output: 27867287808

Input: 391814 220151 3756

Output: 16977831150

Input: 313667 778854 999813

Output: 244300797618

Input: 933241 558702 1

Output: 521403613182

Input: 38614 941895 999986

Output: 36370333530

Input: 242366 216591 4

Output: 19685613696

Input: 282798 941695 999998

Output: 266309462610

Input: 43054 191 1

Output: 8223314


The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$).

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Scanner;

public class Main {

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

         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         long n=Long.parseLong(br.readLine());
         System.out.println((int)Math.ceil(1.0*(n+1)/2));

    }
}

NoteIn the first sample, there are following possible weights of splits of $$$7$$$:Weight 1: [$$$\textbf 7$$$] Weight 2: [$$$\textbf 3$$$, $$$\textbf 3$$$, 1] Weight 3: [$$$\textbf 2$$$, $$$\textbf 2$$$, $$$\textbf 2$$$, 1] Weight 7: [$$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$]

Output one integer — the answer to the problem.

Let's define a split of $$$n$$$ as a nonincreasing sequence of positive integers, the sum of which is $$$n$$$. For example, the following sequences are splits of $$$8$$$: $$$[4, 4]$$$, $$$[3, 3, 2]$$$, $$$[2, 2, 1, 1, 1, 1]$$$, $$$[5, 2, 1]$$$.The following sequences aren't splits of $$$8$$$: $$$[1, 7]$$$, $$$[5, 4]$$$, $$$[11, -3]$$$, $$$[1, 1, 4, 1, 1]$$$.The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $$$[1, 1, 1, 1, 1]$$$ is $$$5$$$, the weight of the split $$$[5, 5, 3, 3, 3]$$$ is $$$2$$$ and the weight of the split $$$[9]$$$ equals $$$1$$$.For a given $$$n$$$, find out the number of different weights of its splits.


The only input line contains the integer $$$n$$$ ($$$1 \le n \le 2\cdot10^9$$$).

import java.util.Scanner;

public class Nirvana {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		Nirvana obj = new Nirvana();
		System.out.println(obj.maxMultiply(n));

		in.close();
	}
	int maxMultiply(int n) {
		if(n == 0)
			return 1;
		int nextNum = n/10;
		int digit = n%10;
		if(digit == 9) {
			// No need to borrow
			return 9*maxMultiply(nextNum);
		}
		int result9 = -1;
		int resultNormal = -1;
		if(nextNum>0) {
			// Can borrow
			result9 = 9*maxMultiply(nextNum-1);
		}
		resultNormal = digit*maxMultiply(nextNum);
		return Math.max(result9, resultNormal);
	}

}

NoteIn the first example the maximum product is achieved for $$$389$$$ (the product of digits is $$$3\cdot8\cdot9=216$$$).In the second example the maximum product is achieved for $$$7$$$ (the product of digits is $$$7$$$).In the third example the maximum product is achieved for $$$999999999$$$ (the product of digits is $$$9^9=387420489$$$).

Print the maximum product of digits among all integers from $$$1$$$ to $$$n$$$.

Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.Help Kurt find the maximum possible product of digits among all integers from $$$1$$$ to $$$n$$$.


The only line contains two integers $$$n$$$ and $$$m$$$ ($$$0 \le n,m \le 2\,000$$$).

/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1204E
   {
      static long MOD = 998244853L;
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         fac = new long[4001];
         invfac = new long[4001];
         fac[0] = invfac[0] = 1L;
         for(int i=1; i <= 4000; i++)
         {
            fac[i] = (fac[i-1]*i)%MOD;
            invfac[i] = power(fac[i], MOD-2, MOD);
         }
         long[][] zero = new long[N+1][M+1];
         Arrays.fill(zero[0], 1L);
         for(int a=1; a <= N; a++)
            for(int b=a; b <= M; b++)
               zero[a][b] = (zero[a-1][b]+zero[a][b-1])%MOD;
         long[][] dp = new long[N+1][M+1];
         for(int a=0; a <= N; a++)
            dp[a][0] = a;
         for(int a=1; a <= N; a++)
            for(int b=1; b <= M; b++)
            {
               long temp = (dp[a-1][b]+dp[a][b-1])%MOD;
               temp = (temp+cnt(a-1,b)-cnt(a,b-1)+MOD)%MOD;
               dp[a][b] = (temp+zero[a][b-1])%MOD;
            }
         System.out.println(dp[N][M]);
      }
      static long fac[];
      static long invfac[];
      public static long cnt(int a, int b)
      {
         long val = fac[a+b];
         val = (val*invfac[a])%MOD;
         return (val*invfac[b])%MOD;
      }
      public static long power(long x, long y, long p)
      {
          long res = 1L;
          x = x % p;
          while (y > 0)
          {
              if((y & 1)==1)
                  res = (res * x) % p;
              y = y >> 1;
              x = (x * x) % p;
          }
          return res;
      }
   }

Output the answer to the problem modulo $$$998\: 244\: 853$$$.

Natasha's favourite numbers are $$$n$$$ and $$$1$$$, and Sasha's favourite numbers are $$$m$$$ and $$$-1$$$. One day Natasha and Sasha met and wrote down every possible array of length $$$n+m$$$ such that some $$$n$$$ of its elements are equal to $$$1$$$ and another $$$m$$$ elements are equal to $$$-1$$$. For each such array they counted its maximal prefix sum, probably an empty one which is equal to $$$0$$$ (in another words, if every nonempty prefix sum is less to zero, then it is considered equal to zero). Formally, denote as $$$f(a)$$$ the maximal prefix sum of an array $$$a_{1, \ldots ,l}$$$ of length $$$l \geq 0$$$. Then: $$$$$$f(a) = \max (0, \smash{\displaystyle\max_{1 \leq i \leq l}} \sum_{j=1}^{i} a_j )$$$$$$Now they want to count the sum of maximal prefix sums for each such an array and they are asking you to help. As this sum can be very large, output it modulo $$$998\: 244\: 853$$$.

Input: 0 2

Output: 0

Input: 2 0

Output: 2

Input: 2 2

Output: 5

Input: 2000 2000

Output: 674532367

Input: 0 0

Output: 0

Input: 11 2

Output: 716

Input: 1 4

Output: 1

Input: 5 13

Output: 4048

Input: 60 59

Output: 271173738

Input: 27 16

Output: 886006554

Input: 1134 1092

Output: 134680101

Input: 756 1061

Output: 72270489

Input: 953 1797

Output: 557692333

Input: 76 850

Output: 103566263

Input: 24 1508

Output: 540543518

Input: 1087 1050

Output: 973930225

Input: 149 821

Output: 64450770

Input: 983 666

Output: 917123830

Input: 45 1323

Output: 357852234

Input: 1994 1981

Output: 596939902

Input: 1942 1523

Output: 89088577

Input: 1891 1294

Output: 696966158

Input: 1132 1727

Output: 878164775

Input: 1080 383

Output: 161999131

Input: 1028 1040

Output: 119840364

Input: 976 1698

Output: 621383232

Input: 38 656

Output: 814958661

Input: 872 1313

Output: 261808476

Input: 1935 856

Output: 707458926

Input: 1883 1513

Output: 265215482

Input: 0 2000

Output: 0

Input: 2000 0

Output: 2000

Input: 1991 1992

Output: 518738831

Input: 1935 1977

Output: 16604630

Input: 1990 2000

Output: 516468539

Input: 1915 1915

Output: 534527105


The single line contains the positive integer n (1 ≤ n ≤ 1015).

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class _486A_CalculatingFunction {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BigInteger n = new BigInteger(br.readLine());

		if (n.remainder(new BigInteger("2")).equals(new BigInteger("0"))) {
			System.out.println(n.divide(new BigInteger("2")));
		} else {
			System.out.println(n.divide(new BigInteger("2")).add(new BigInteger("1")).multiply(new BigInteger("-1")));
		}

		br.close();
	}

}

Notef(4) =  - 1 + 2 - 3 + 4 = 2f(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3

For a positive integer n let's define a function f:f(n) =  - 1 + 2 - 3 + .. + ( - 1)nn Your task is to calculate f(n) for a given integer n.