import java.util.Scanner;

class Main{
  public static void main(String[] args){
  	Scanner scanner = new Scanner(System.in);
    int count=0;
	int num1= scanner.nextInt();
    int num2= scanner.nextInt();

    int[][] a = new int[2][num1];
    for(int i=0;i<num1;i++) for(int k=0;k<2;k++) a[i][k] =scanner.nextInt();
    scanner.close();

    for(int i=0;i<num1;i++) if(Math.sqrt( Math.pow(a[i][0],2) + Math.pow(a[i][1],2) ) >= num2) count++;
    System.out.println(count);
  }
}

Score : 200 points

Problem Statement

We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).

Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?

We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.

Constraints

1 \leq N \leq 2\times 10^5

0 \leq D \leq 2\times 10^5

|X_i|,|Y_i| \leq 2\times 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D
X_1 Y_1
\vdots
X_N Y_N

Output

Print an integer representing the number of points such that the distance from the origin is at most D.

Sample Input 1

4 5
0 5
-2 4
3 4
4 -4

Sample Output 1

3

The distance between the origin and each of the given points is as follows:

\sqrt{0^2+5^2}=5

\sqrt{(-2)^2+4^2}=4.472\ldots

\sqrt{3^2+4^2}=5

\sqrt{4^2+(-4)^2}=5.656\ldots

Thus, we have three points such that the distance from the origin is at most 5.

Sample Input 2

12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

Sample Output 2

7

Multiple points may exist at the same coordinates.

Sample Input 3

20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669

Sample Output 3

6


import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Random;
import java.util.Scanner;

class BIT {
	long bit[] = new long[0];
	int N = 0;

	BIT(int n) {
		bit = new long[n + 1];
		N = n;
	}

	void add(int a, long w) {
		for (int x = a; x < N; x += (x & -x))
			bit[x] += w;
	}

	long sum(int a) {
		long ret = 0;
		for (int x = a; x > 0; x -= x & -x)
			ret += bit[x];
		return ret;
	}

	long modsum(int a, int mod) {
		long ret = 0;
		for (int x = a; x > 0; x -= x & -x) {
			ret += bit[x];
			ret %= mod;
		}
		return ret;
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

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

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

	public char nextchar() {
		return next().charAt(0);
	}
}

class UnionFind {
	int Parent[];

	UnionFind(int n) {// Initialize by -1
		Parent = new int[n];
		Arrays.fill(Parent, -1);
	}

	int root(int A) {// In which tree is A?
		if (Parent[A] < 0)
			return A;
		return Parent[A] = root(Parent[A]);
	}

	int size(int A) {// size of tree which is include A
		return -Parent[root(A)];
	}

	boolean connect(int A, int B) {// Connect A and B
		A = root(A);
		B = root(B);
		if (A == B)
			return false;
		if (size(A) < size(B)) {
			int C = 0;
			C = B;
			B = A;
			A = C;
		} // SWAP
		Parent[A] += Parent[B];
		Parent[B] = A;
		return true;
	}
}

class Pair<T, E> {
	public T first;
	public E second;

	void set(T x, E y) {
		first = x;
		second = y;
	}
}

class Pint {
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Pint) {
			Pint other = (Pint) obj;
			return other.first == this.first && other.second == this.second;
		}
		return false;
	}

	@Override
	public int hashCode() {
		return Objects.hash(this.first, this.second);
	}

	public int first;
	public int second;

	Pint(int x, int y) {
		first = x;
		second = y;
	}

	void set(int x, int y) {
		first = x;
		second = y;
	}
}

class Tpair {
	public int first;
	public int second;
	public long third;

	Tpair(int x, int y, long z) {
		first = x;
		second = y;
		third = z;
	}

	void set(int x, int y, long z) {
		first = x;
		second = y;
		third = z;
	}
}

public class Main {
	static FastScanner scan = new FastScanner();
	static Scanner scanner = new Scanner(System.in);
	static Random rand = new Random();
	static long mod = 1000000007;
	static double eps = 1.0E-14;
	static int big = Integer.MAX_VALUE;
	static double PI = 3.141592653589793;

	static long modlcm(long a, long b) {
		return a * b * modinv(GCD(a, b), mod);
	}

	static long GCD(long a, long b) {
		return b > 0 ? GCD(b, a % b) : a;
	}

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

	static int min(int a, int b) {
		return a < b ? a : b;
	}

	static long factorial(int i) {
		return i == 1 ? 1 : i * factorial(i - 1);
	}

	static int max(int... i) {
		int x = i[0];
		for (int e : i)
			x = Math.max(x, e);
		return x;
	}

	static int min(int... i) {
		int x = i[0];
		for (int e : i)
			x = Math.min(x, e);
		return x;
	}

	static long gcd(long... i) {
		long x = i[0];
		for (long e : i)
			x = GCD(x, e);
		return x;
	}

	static long lmax(long... i) {
		long x = i[0];
		for (long e : i)
			x = Math.max(x, e);
		return x;
	}

	static long lmin(long... i) {
		long x = i[0];
		for (long e : i)
			x = Math.min(x, e);
		return x;
	}

	static long nCr(long n, long r, long m) {
		long ans = 1;
		for (long i = 0; i < r; i++) {
			ans *= (n - i);
			ans %= m;
		}
		for (long i = 0; i <= r; i++) {
			ans *= modinv(i, m);
			ans %= mod;
		}
		return ans;
	}

	static int lower_bound(long[] b, long cost) {
		int ok = b.length;
		int ng = -1;
		while (Math.abs(ok - ng) > 1) {
			int mid = (ok + ng) / 2;
			if (b[mid] >= cost)
				ok = mid;
			else
				ng = mid;
		}
		return ok;
	}

	static int upper_bound(int[] b, int cost) {
		int ok = b.length;
		int ng = -1;
		while (Math.abs(ok - ng) > 1) {
			int mid = (ok + ng) / 2;
			if (b[mid] > cost)
				ok = mid;
			else
				ng = mid;
		}
		return ok;
	}

	static boolean isPrime(long n) {
		if (n == 2)
			return true;
		if (n < 2 || n % 2 == 0)
			return false;
		double d = Math.sqrt(n);
		for (int i = 3; i <= d; i += 2)
			if (n % i == 0) {
				return false;
			}
		return true;
	}

	static int upper_division(int a, int b) {
		if (a % b == 0) {
			return a / b;
		} else {
			return a / b + 1;
		}
	}

	static long lupper_division(long a, long b) {
		if (a % b == 0) {
			return a / b;
		} else {
			return a / b + 1;
		}
	}

	static int[] setArray(int a) {
		int b[] = new int[a];
		for (int i = 0; i < a; i++) {
			b[i] = scan.nextInt();
		}
		return b;
	}

	static long[] lsetArray(int a) {
		long b[] = new long[a];
		for (int i = 0; i < a; i++) {
			b[i] = scan.nextLong();
		}
		return b;
	}

	static String reverse(String str) {
		char ch[] = new char[str.length()];
		char chch[] = str.toCharArray();
		int a = str.length();
		for (int i = 0; i < upper_division(a, 2); i++) {
			ch[i] = chch[ch.length - i - 1];
			ch[ch.length - 1 - i] = chch[i];
		}
		return String.valueOf(ch);
	}

	public static void printArray(int[] que) {
		for (int i = 0; i < que.length - 1; i++) {
			System.out.print(que[i] + " ");
		}
		System.out.println(que[que.length - 1]);
	}

	public static void lprintArray(long[] que) {
		for (int i = 0; i < que.length - 1; i++) {
			System.out.print(que[i] + " ");
		}
		System.out.println(que[que.length - 1]);
	}

	public static int[][] doublesort(int[][] a) {
		Arrays.sort(a, (x, y) -> Integer.compare(x[0], y[0]));
		return a;
	}

	public static long[][] ldoublesort(long[][] a) {
		Arrays.sort(a, (x, y) -> Long.compare(x[0], y[0]));
		return a;
	}

	static long modpow(long x, long n, long mo) {
		long sum = 1;
		while (n > 0) {
			if ((n & 1) == 1) {
				sum = sum * x % mo;
			}
			x = x * x % mo;
			n >>= 1;
		}
		return sum;
	}

	public static char[] revch(char ch[]) {
		char ret[] = new char[ch.length];
		for (int i = ch.length - 1, j = 0; i >= 0; i--, j++) {
			ret[j] = ch[i];
		}
		return ret;
	}

	public static int[] revint(int ch[]) {
		int ret[] = new int[ch.length];
		for (int i = ch.length - 1, j = 0; i >= 0; i--, j++) {
			ret[j] = ch[i];
		}
		return ret;
	}

	public static void warshall_floyd(long v[][]) {
		int n = v[0].length;
		for (int k = 0; k < n; k++)
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					v[i][j] = lmin(v[i][j], v[i][k] + v[k][j]);
	}

	public static long modinv(long a, long m) {
		long b = m, u = 1, v = 0;
		while (b != 0) {
			long t = a / b;
			a -= t * b;
			long x = a;
			a = b;
			b = x;
			u -= t * v;
			x = u;
			u = v;
			v = x;
		}
		u %= m;
		if (u < 0)
			u += m;
		return u;
	}

	public static long lmod(long i, long j) {
		return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0);
	}

	public static int next_combination(int sub) {
		int x = sub & -sub, y = sub + x;
		return (((sub & ~y) / x) >> 1) | y;
	}

	public static void main(String[] $) throws IOException {
		int k=scan.nextInt();
		int now=7;
		for(int i=1;i<=k+10;i++) {
			if(now%k==0) {
				System.out.println(i);
				return;
			}
			now*=10;
			now+=7;
			now%=k;
		}
		System.out.println(-1);
	}
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 300 points

Problem Statement

Takahashi loves the number 7 and multiples of K.

Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.)

If the sequence contains no multiples of K, print -1 instead.

Constraints

1 \leq K \leq 10^6

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.)

Sample Input 1

101

Sample Output 1

4

None of 7, 77, and 777 is a multiple of 101, but 7777 is.

Sample Input 2

2

Sample Output 2

-1

All elements in the sequence are odd numbers; there are no multiples of 2.

Sample Input 3

999983

Sample Output 3

999982

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


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

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solution sol = new Solution();
		sol.solve(in, out);
		out.close();
	}

	private static class Solution {
		private void solve(InputReader in, PrintWriter out) {
			int n=in.ni(), ans=0;
			char[] stones=in.n().toCharArray();
			int l=0, r=n-1;
			while (l < r) {
				while (stones[l] == 'R') l++;
				while (stones[r] == 'W') r--;
				if (l < r) {
					++ans; ++l; --r;
				}
			}
			out.println(ans);
		}
	}

	private static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		private InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

		private int ni() {
			return Integer.parseInt(n());
		}
	}
}

Score : 400 points

Problem Statement

An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; R stands for red and W stands for white.

You can do the following two kinds of operations any number of times in any order:

Choose two stones (not necessarily adjacent) and swap them.

Choose one stone and change its color (from red to white and vice versa).

According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Constraints

2 \leq N \leq 200000

c_i is R or W.

Input

Input is given from Standard Input in the following format:

N
c_{1}c_{2}...c_{N}

Output

Print an integer representing the minimum number of operations needed.

Sample Input 1

4
WWRR

Sample Output 1

2

For example, the two operations below will achieve the objective.

Swap the 1-st and 3-rd stones from the left, resulting in RWWR.

Change the color of the 4-th stone from the left, resulting in RWWW.

Sample Input 2

2
RR

Sample Output 2

0

It can be the case that no operation is needed.

Sample Input 3

8
WRWWRWRR

Sample Output 3

3


import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		LinkedList<Integer> list = new LinkedList<>();
		for (int i = 0; i < N; i++) {
			list.add(sc.nextInt());
		}
		Collections.sort(list);

		for (int i = 0; i < K; i++) {
			int a = list.removeLast();
			int j = 2;
			//System.out.println(a);
			for (;i < K-1; j++) {
				if (a/j < list.getLast() || a/(j+1) > list.getLast()) {
					break;
				}
				i++;
			}
			int aa = a;
			for (int k = 0; k < j-1; k++) {
				list.add(a/j);
				aa -= a/j;
			}
			list.add(aa);
			Collections.sort(list);
		}
		System.out.println(list.getLast());
	}
}

Score : 500 points

Problem Statement

We have N logs of lengths A_1,A_2,\cdots A_N.

We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t.

Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq K \leq 10^9

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_N

Output

Print an integer representing the answer.

Sample Input 1

2 3
7 9

Sample Output 1

4

First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.

Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.

Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.

In this case, the longest length of a log will be 3.5, which is the shortest possible result. After rounding up to an integer, the output should be 4.

Sample Input 2

3 0
3 4 5

Sample Output 2

5

Sample Input 3

10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202

Sample Output 3

292638192


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

public class Main {
    public static void main(String[] args) throws IOException {
        MyScanner scn = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        // Solution Start
        int t = scn.nextInt();
        if (t >= 1800) out.println("1");
        else if (t >= 1600) out.println("2");
        else if (t >= 1400) out.println("3");
        else if (t >= 1200) out.println("4");
        else if (t >= 1000) out.println("5");
        else if (t >= 800) out.println("6");
        else if (t >= 600) out.println("7");
        else out.println("8");
        //Solution end
        out.close();
    }

    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

    }
    //--------------------------------------------------------
}

Score: 100 points

Problem Statement

M-kun is a competitor in AtCoder, whose highest rating is X.

In this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given:

From 400 through 599: 8-kyu

From 600 through 799: 7-kyu

From 800 through 999: 6-kyu

From 1000 through 1199: 5-kyu

From 1200 through 1399: 4-kyu

From 1400 through 1599: 3-kyu

From 1600 through 1799: 2-kyu

From 1800 through 1999: 1-kyu

What kyu does M-kun have?

Constraints

400 \leq X \leq 1999

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the kyu M-kun has, as an integer.
For example, if he has 8-kyu, print 8.

Sample Input 1

725

Sample Output 1

7

M-kun's highest rating is 725, which corresponds to 7-kyu.

Thus, 7 is the correct output.

Sample Input 2

1600

Sample Output 2

2

M-kun's highest rating is 1600, which corresponds to 2-kyu.

Thus, 2 is the correct output.


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

public class Main {
	static final int INF = (int) (1e9 + 10);
	static final long MOD = (int) (1e9 + 7);
	static final int N = (int) (4e5 + 5);
	// static ArrayList<Integer>[] graph;
	// static boolean visited[];
	// static long size[];

	public static void main(String[] args) throws NumberFormatException, IOException {
		FastReader sc = new FastReader();
		PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// Scanner scn = new Scanner(System.in);
		//
		int x=sc.nextInt();
		if(x<600)
			pr.println("8");
		else if(x<800)
			pr.println("7");
		else if(x<1000)
			pr.println("6");

		else if(x<1200)
			pr.println("5");
		else if(x<1400)
			pr.println("4");
		else if(x<1600)
			pr.println("3");
		else if(x<1800)
			pr.println("2");
		else
			pr.println("1");
		//
		// Coded to Perfection by Rohan Mukhija

		pr.flush();
		pr.close();

	}

	/*
	 * Template From Here
	 */
	private static boolean possible(long[] arr, long mid, long k, long t) {
		long c = 1;
		long tot = 0;
		for (int i = 0; i < arr.length; i++) {
			tot += (arr[i]);
			if (tot > mid) {
				tot = arr[i];
				c++;
			}
		}
		// System.out.println(mid+" "+c);
		if (c <= k)
			return true;
		return false;
	}

	public static class Pair implements Comparable<Pair> {
		int u;
		int v;

		Pair(int u, int v) {
			this.u = u;
			this.v = v;

		}

		public int compareTo(Pair compareEdge) {
			return Long.compare(this.v, compareEdge.v);
		}
	};

	static void sort(long[] a) {
		ArrayList<Long> l = new ArrayList<>();
		for (long i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	public static int lowerBound(ArrayList<Integer> array, int length, long value) {
		int low = 0;
		int high = length;
		while (low < high) {
			final int mid = (low + high) / 2;
			if (value <= array.get(mid)) {
				high = mid;
			} else {
				low = mid + 1;
			}
		}
		return low;
	}

	public static long mul(long a, long b) {
		return (a * b) % MOD;
	}

	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 int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}

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

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

	public static void sortbyColumn(int[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<int[]>() {

			@Override
			// Compare values according to columns
			public int compare(final int[] entry1, final int[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Integer(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	public static void sortbyColumn(double[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<double[]>() {

			@Override
			// Compare values according to columns
			public int compare(final double[] entry1, final double[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Double(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	static class pair {
		int V, I;

		pair(int v, int i) {
			V = v;
			I = i;
		}
	}

	public static int[] swap(int data[], int left, int right) {
		int temp = data[left];
		data[left] = data[right];
		data[right] = temp;
		return data;
	}

	public static int[] reverse(int data[], int left, int right) {
		while (left < right) {
			int temp = data[left];
			data[left++] = data[right];
			data[right--] = temp;
		}
		return data;
	}

	public static boolean findNextPermutation(int data[]) {
		if (data.length <= 1)
			return false;

		int last = data.length - 2;
		while (last >= 0) {
			if (data[last] < data[last + 1]) {
				break;
			}
			last--;
		}
		if (last < 0)
			return false;

		int nextGreater = data.length - 1;
		for (int i = data.length - 1; i > last; i--) {
			if (data[i] > data[last]) {
				nextGreater = i;
				break;
			}
		}
		data = swap(data, nextGreater, last);
		data = reverse(data, last + 1, data.length - 1);
		return true;
	}

	static long ncr(long a, long b) {
		if (b > a - b)
			return ncr(a, a - b);
		long ansMul = 1;
		long ansDiv = 1;
		for (int i = 0; i < b; i++) {
			ansMul *= (a - i);
			ansDiv *= (i + 1);
			ansMul %= MOD;
			ansDiv %= MOD;
		}

		long ans = ansMul * power(ansDiv, MOD - 2, MOD) % MOD;

		return ans;
	}

	static long __gcd(long n1, long n2) {
		long gcd = 1;

		for (int i = 1; i <= n1 && i <= n2; ++i) {
			// Checks if i is factor of both integers
			if (n1 % i == 0 && n2 % i == 0) {
				gcd = i;
			}
		}
		return gcd;
	}

	static long power(long prev, long n2, long mod2) {
		long res = 1;

		prev = prev % mod2;

		if (prev == 0)
			return 0;
		while (n2 > 0) {

			if ((n2 & 1) == 1)
				res = (res * prev) % mod2;

			n2 = n2 >> 1;
			prev = (prev * prev) % mod2;
		}
		return res;
	}

	static long modInverse(long fac2, int p) {
		return power(fac2, p - 2, p);
	}

	static boolean isPrime(int n) {
		// Corner cases
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;

		// This is checked so that we can skip
		// middle five numbers in below loop
		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}

	public static BigInteger lcmm(String a, String b) {
		BigInteger s = new BigInteger(a);
		BigInteger s1 = new BigInteger(b);
		BigInteger mul = s.multiply(s1);
		BigInteger gcd = s.gcd(s1);
		BigInteger lcm = mul.divide(gcd);
		return lcm;
	}
	/*
	 * static boolean prime[] = new boolean[10000007]; static int spf[] = new
	 * int[10000007];
	 *
	 * public static void sieveOfEratosthenes(int n) { for (int i = 2; i < n;
	 * i++) prime[i] = true; for (int p = 2; p * p <= n; p++) {
	 *
	 * if (prime[p] == true) {
	 *
	 * for (int i = p * p; i <= n; i += p) { prime[i] = false; spf[i] = p; } } }
	 * }
	 */
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt(); //red
		int b = scan.nextInt(); //green
		int c = scan.nextInt(); //blue
		int k = scan.nextInt();

		for(int i = 1; i <= k; i++) {
			if(a > b || a == b) {
				b = 2 * b;
				k = k - 1;
			}

		}

	 if(k != 0) {
			for(int j =
					0; j < k; j++) {
				if(b > c || b == c) {
					c = 2 * c;
				}
			}
		}
		if(a < b && b < c) {
			System.out.println("Yes");

		}else {
			System.out.println("No");
		}
	}

}

Score: 200 points

Problem Statement

M-kun has the following three cards:

A red card with the integer A.

A green card with the integer B.

A blue card with the integer C.

He is a genius magician who can do the following operation at most K times:

Choose one of the three cards and multiply the written integer by 2.

His magic is successful if both of the following conditions are satisfied after the operations:

The integer on the green card is strictly greater than the integer on the red card.

The integer on the blue card is strictly greater than the integer on the green card.

Determine whether the magic can be successful.

Constraints

1 \leq A, B, C \leq 7

1 \leq K \leq 7

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C
K

Output

If the magic can be successful, print Yes; otherwise, print No.

Sample Input 1

7 2 5
3

Sample Output 1

Yes

The magic will be successful if, for example, he does the following operations:

First, choose the blue card. The integers on the red, green, and blue cards are now 7, 2, and 10, respectively.

Second, choose the green card. The integers on the red, green, and blue cards are now 7, 4, and 10, respectively.

Third, choose the green card. The integers on the red, green, and blue cards are now 7, 8, and 10, respectively.

Sample Input 2

7 4 2
3

Sample Output 2

No

He has no way to succeed in the magic with at most three operations.


import java.util.Scanner;

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int k = stdIn.nextInt();

        for(int i=0; i<k+2-1; i++){
            for(int j=i+1; j<k+2; j++){
                if(a * pow(2, i) < b * pow(2, j-i-1) && b * pow(2, j-i-1) < c * pow(2, k+1-j)){
                    System.out.println("Yes");
                    return;
                }
            }
        }

        System.out.println("No");
    }

    static int pow(int a, int b){
        int x = 1;
        for(int i=0; i<b; i++){
            x *= a;
        }
        return x;
    }
}


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

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();

    for (int i = 0; i < k; i++) {
      if (a>b) {
        b*=2;
      } else if (b>c) {
        c*=2;
      }
      if(a<b && b<c) {
        System.out.println("Yes");
        return;
      }
    }

    System.out.println("No");

  }

}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author New User
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        BMagic2 solver = new BMagic2();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMagic2 {
        public void solve(int testNumber, InputReader c, OutputWriter w) {
            int a = c.readInt(), b = c.readInt(), cc = c.readInt();

            int k = c.readInt();
            int res = 0;
            while (b <= a) {
                res++;
                b *= 2;
            }

            while (cc <= b) {
                res++;
                cc *= 2;
            }
            if (res <= k) {
                w.printLine("Yes");
            } else {
                w.printLine("No");
            }

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

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

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }
}


import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();
		for(int i = 0; i <= K; i++) {
			for(int j = 0; j <= K - i; j++) {
				if(A < B * Math.pow(2, i) && B * Math.pow(2, i) < C * Math.pow(2, j)) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main{
	static BufferedReader br;
	static int in() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        int[] ar=split();
        int n=ar[0];
        int k=ar[1];
        int[] arr=split();
        for(int i=k;i<n;i++)
        {
        	if(arr[i]>arr[i-k])
        		System.out.println("Yes");
        	else
        		System.out.println("No");
        }
    }
}

Score: 300 points

Problem Statement

M-kun is a student in Aoki High School, where a year is divided into N terms.

There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:

For the first through (K-1)-th terms: not given.

For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.

M-kun scored A_i in the exam at the end of the i-th term.

For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is strictly greater than the grade for the (i-1)-th term.

Constraints

2 \leq N \leq 200000

1 \leq K \leq N-1

1 \leq A_i \leq 10^{9}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 A_3 \ldots A_N

Output

Print the answer in N-K lines.

The i-th line should contain Yes if the grade for the (K+i)-th term is greater than the grade for the (K+i-1)-th term, and No otherwise.

Sample Input 1

5 3
96 98 95 100 20

Sample Output 1

Yes
No

His grade for each term is computed as follows:

3-rd term: (96 \times 98 \times 95) = 893760

4-th term: (98 \times 95 \times 100) = 931000

5-th term: (95 \times 100 \times 20) = 190000

Sample Input 2

3 2
1001 869120 1001

Sample Output 2

No

Note that the output should be No if the grade for the 3-rd term is equal to the grade for the 2-nd term.

Sample Input 3

15 7
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9

Sample Output 3

Yes
Yes
No
Yes
Yes
No
Yes
Yes


import java.util.*;

public class Main {

  private static void solve(int L, int R, int d) {
    int res = 0;
    for (int i = L; i <= R; i++) {
      if (i % d == 0) {
        res++;
      }
    }
    System.out.println(res);
  }

  public static void main(String[] args) {
    int L = scanner.nextInt();
    int R = scanner.nextInt();
    int d = scanner.nextInt();
    solve(L, R, d);
  }

  private static final Scanner scanner = new Scanner(System.in);
}

Score : 100 points

Problem Statement

How many multiples of d are there among the integers between L and R (inclusive)?

Constraints

All values in input are integers.

1 \leq L \leq R \leq 100

1 \leq d \leq 100

Input

Input is given from Standard Input in the following format:

L R d

Output

Print the number of multiples of d among the integers between L and R (inclusive).

Sample Input 1

5 10 2

Sample Output 1

3

Among the integers between 5 and 10, there are three multiples of 2: 6, 8, and 10.

Sample Input 2

6 20 7

Sample Output 2

2

Among the integers between 6 and 20, there are two multiples of 7: 7 and 14.

Sample Input 3

1 100 1

Sample Output 3

100


import java.util.*;
public class Main {

	public static void main(String[] args) {

Scanner sc=new Scanner(System.in);
int l=sc.nextInt();
int r=sc.nextInt();
int d=sc.nextInt();
int a[]=new int [101];
for(int i=d;i<101;i+=d) {
	a[i]++;
}
int count=0;
for(int i=l;i<=r;i++) {
	if(a[i]>=1) {
		count++;
	}
}
System.out.println(count);
	}

}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long c = Long.parseLong(str[2]);

		int ans = 0;
		for (long i = a; i <= b; i++) {
			if (i % c == 0) {
				ans++;
			}
		}

		System.out.println(ans);
	}
}


import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=1; i<=n; i++) {
            int ans = 0;
            for(int x=1; x<=1000; x++) {
                int x1 = (int) Math.pow(x, 2);
                int y1 = (int) Math.pow(1, 2);
                int z1 = (int) Math.pow(1, 2);
                int xy1 = x * 1;
                int yz1 = 1 * 1;
                int zx1 = 1 * x;
                int sum1 = x1 + y1 + z1 + xy1 + yz1 + zx1;
                if(i < sum1)break;
                for(int y=1; y<=1000; y++) {
                    int x2 = (int) Math.pow(x, 2);
                    int y2 = (int) Math.pow(y, 2);
                    int z2 = (int) Math.pow(1, 2);
                    int xy2 = x * y;
                    int yz2 = y * 1;
                    int zx2 = 1 * x;
                    int sum2 = x2 + y2 + z2 + xy2 + yz2 + zx2;
                    if(i < sum2)break;
                    for(int z=1; z<=1000; z++) {
                        int x3 = (int) Math.pow(x, 2);
                        int y3 = (int) Math.pow(y, 2);
                        int z3 = (int) Math.pow(z, 2);
                        int xy3 = x * y;
                        int yz3 = y * z;
                        int zx3 = z * x;
                        int sum3 = x3 + y3 + z3 + xy3 + yz3 + zx3;
                        if(i == sum3) ans++;
                        if(i < sum3)break;
                    }
                }
            }
            System.out.println(ans);
        }
    }
}

Score : 300 points

Problem Statement

Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:

1 \leq x,y,z

x^2 + y^2 + z^2 + xy + yz + zx = n

Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).

Constraints

All values in input are integers.

1 \leq N \leq 10^4

Input

Input is given from Standard Input in the following format:

N

Output

Print N lines. The i-th line should contain the value f(i).

Sample Input 1

20

Sample Output 1

0
0
0
0
0
1
0
0
0
0
3
0
0
0
0
0
3
3
0
0

For n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.

For n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.

For n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.

For n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.


import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();

      	Integer a[] = new Integer[N+1];
        for (int i=1; i<=N; i++) {
            a[i] = 0;
        }
        for (int i=1; i<=N; i++) {
        	for(int x = 1; x<=20;x++){
            	for(int y = x; y<=100;y++){
                 	 for(int z = y; z<=100;z++){
                       if((x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x) == i){
                         if(x == y && y == z){
                         a[i] += 1;
                         } else {
                           a[i] += 3;
                         }
                       }
        		    }
            	}
            }
        }

      	for (int i=1; i<=N; i++) {
            System.out.println(a[i]);
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  private static int powmod(int a, int n, int mod) {
    if (n == 0) return 1;
    int half = powmod(a, n / 2, mod) % mod;
    if (n % 2 == 0) return (half * half) % mod;
    return (a * ((half * half) % mod)) % mod;
  }

  private static int mod(String bin, int mod) {
    int val = 0;
    for (int i = bin.length() - 1; i >= 0; i--) {
      if (bin.charAt(i) == '0') continue;
      int n = bin.length() - 1 - i;
      val += powmod(2, n, mod);
      val %= mod;
    }
    return val;
  }

  private static int getF(String bin, int mod, Map<String, Integer> f) {
    if (f.containsKey(bin)) return f.get(bin);
    if (mod == 0) {
      f.put(bin, 0);
      return f.get(bin);
    }
    int m = mod(bin, mod);
    String mbin = Integer.toString(m, 2);
    int count = 0;
    for (int i = 0; i < mbin.length(); i++) {
      if (mbin.charAt(i) == '1') count++;
    }
    f.put(bin, 1 + getF(mbin, count, f));
    return f.get(bin);
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    String x = sc.next();
    int ones = 0;
    for (int i = 0; i < n; i++) {
      if (x.charAt(i) == '1') ones++;
    }
    Map<String, Integer> f = new HashMap<>();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < n; i++) {
      if (sb.length() > 0) sb.append("\n");
      String xi;
      int m;
      if (x.charAt(i) == '0') {
        m = ones + 1;
        xi = x.substring(0, i) + '1' + x.substring(i + 1);
      } else {
        m = ones - 1;
        xi = x.substring(0, i) + '0' + x.substring(i + 1);
      }
      int count = getF(xi, m, f);
      sb.append(count);
    }
    System.out.println(sb.toString());
  }
}

Score : 400 points

Problem Statement

Let \mathrm{popcount}(n) be the number of 1s in the binary representation of n.
For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0.

Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)

For example, when n=7, it becomes 0 after two operations, as follows:

\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.

\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.

You are given an integer X with N digits in binary.
For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted.
Find f(X_1), f(X_2), \ldots, f(X_N).

Constraints

1 \leq N \leq 2 \times 10^5

X is an integer with N digits in binary, possibly with leading zeros.

Input

Input is given from Standard Input in the following format:

N
X

Output

Print N lines. The i-th line should contain the value f(X_i).

Sample Input 1

3
011

Sample Output 1

2
1
1

X_1 = 7, which will change as follows: 7 \rightarrow 1 \rightarrow 0. Thus, f(7) = 2.

X_2 = 1, which will change as follows: 1 \rightarrow 0. Thus, f(1) = 1.

X_3 = 2, which will change as follows: 2 \rightarrow 0. Thus, f(2) = 1.

Sample Input 2

23
00110111001011011001110

Sample Output 2

2
1
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
3


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();//データ数
      	String[] result=new String[n];
      	int count_Ac=0;
      	int count_Wc=0;
      	int count_Tle=0;
      	int count_Re=0;

    	for(int i=0;i<n;i++){
			result[i]=sc.next();

            if(result[i].equals("AC")){
            	count_Ac+=1;
            }
         	if(result[i].equals("WC")){
            	count_Wc+=1;
            }
            if(result[i].equals("TLE")){
            	count_Tle+=1;
            }
         	if(result[i].equals("RE")){
            	count_Re+=1;
            }

      	}

        System.out.println("AC x "+count_Ac);
        System.out.println("WC x "+count_Wc);
        System.out.println("TLE x "+count_Tle);
        System.out.println("RE x "+count_Re);
    }
}

Score : 200 points

Problem Statement

Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.

The problem has N test cases.

For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively.

See the Output section for the output format.

Constraints

1 \leq N \leq 10^5

S_i is AC, WA, TLE, or RE.

Input

Input is given from Standard Input in the following format:

N
S_1
\vdots
S_N

Output

Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively. Print the following:

AC x C_0
WA x C_1
TLE x C_2
RE x C_3

Sample Input 1

6
AC
TLE
AC
AC
WA
TLE

Sample Output 1

AC x 3
WA x 1
TLE x 2
RE x 0

We have 3, 1, 2, and 0 test case(s) for which the verdict is AC, WA, TLE, and RE, respectively.

Sample Input 2

10
AC
AC
AC
AC
AC
AC
AC
AC
AC
AC

Sample Output 2

AC x 10
WA x 0
TLE x 0
RE x 0


import java.util.*;
class Main
{
    public static void main(String args[])
    {
        long n;
        Scanner sc=new Scanner(System.in);
        n=sc.nextLong();
        String arr[]=new String[100000];
        int ac=0,wa=0,tle=0,re=0;
        for(int i=0;i<=n;i++)
        {
            arr[i]=sc.nextLine();
            if(arr[i].equals("AC"))
            {
                ac++;
            }
            else if(arr[i].equals("WA"))
            {
                wa++;
            }
            else if(arr[i].equals("TLE"))
            {
                tle++;
            }
            else if(arr[i].equals("RE"))
            {
                re++;
            }
        }
        System.out.println("AC x "+ac);
        System.out.println("WA x "+wa);
        System.out.println("TLE x "+tle);
        System.out.println("RE x "+re);

    }
}


import java.util.*;

public class Main{
    public static void main(String[]args){

	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	Integer A[]= new Integer[N];
	int a[]= new int[N];
	int front=0,rear=N-1;
	boolean flag=true;
	int com=0;

	for(int i=0; i<N; i++){
	    A[i]=sc.nextInt();
	}
	Arrays.sort(A, Comparator.reverseOrder());
	for(int i=0; i<N; i++){
	    if(i!=0 && A[i]==A[i-1] && flag){
		a[rear]=A[i];
		if(rear!=N-1){
		    com=com+a[rear+1];
		}else{
		    com=com+a[front-1];
		}
		rear=rear-1;
		flag=false;
	    }else{
		a[front]=A[i];
		if(front==0){
		    com=0;
		}else{
		    com=com+a[front-1];
		}
		front++;
		flag=true;
	    }
	}
	System.out.println(com);

    }
}

Score: 400 points

Problem Statement

Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.

The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.

When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.

What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the maximum total comfort the N players can get.

Sample Input 1

4
2 2 1 3

Sample Output 1

7

By arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.

They cannot get the total comfort greater than 7, so the answer is 7.

Sample Input 2

7
1 1 1 1 1 1 1

Sample Output 2

6


import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    long MOD = (long)Math.pow(10, 9) + 7;
    ArrayList<Long> list1 = new ArrayList<Long>();
    ArrayList<Long> list2 = new ArrayList<Long>();
    for(int i = 0; i < n; i++) {
      long a = sc.nextLong();
      if(a >= 0) {
        list1.add(a);
      } else {
        list2.add(a);
      }
    }
    Collections.sort(list1);
    Collections.sort(list2);
    long ans = 1;
    int p1 = list1.size() - 1;
    int p2 = 0;
    if(list1.size() == 0) {
      if((k % 2) == 1) {
        for(int i = list2.size() - 1; i >= list2.size() - k; i--) {
          long d = list2.get(i);
          d += MOD;
          ans = (ans * d) % MOD;
        }
      } else {
        for(int i = 0; i < k; i++) {
          long d = list2.get(i);
          d += MOD;
          ans = (ans * d) % MOD;
        }
      }
    } else if(list2.size() == 0) {
      for(int i = list1.size() - 1; i >= list1.size() - k; i--) {
        ans = (ans * list1.get(i)) % MOD;
      }
    } else {

    for(int i = 0; i < k; i++) {
      if(p2 < list2.size() - 1) {
        long s1 = list1.get(p1);
        if(p1 > 0) s1 *= list1.get(p1 - 1);
      //  long s2 = list2.get(p2) * list2.get(p2 + 1);
        long s2 = 1;
        if((s1 >= s2) || (i == (k - 1))) {
          ans = (ans * list1.get(p1)) % MOD;
          p1--;
        } else {
          s2 = (s2 % MOD);
          ans = (ans * s2) % MOD;
          i++;
          p2 += 2;
        }
      } else {
        if(p1 >= 0) {
          long d = list1.get(p1);
          ans = (ans * d) % MOD;
          p1--;
        } else {
          long d = list2.get(p2);
          d += MOD;
          ans = (ans * d) % MOD;
          p2++;
        }
      }
    }
    }
    System.out.println(ans);
  }
}

Score : 500 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

We will choose exactly K of these elements. Find the maximum possible product of the chosen elements.

Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

Constraints

1 \leq K \leq N \leq 2\times 10^5

|A_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N K
A_1 \ldots A_N

Output

Print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

Sample Input 1

4 2
1 2 -3 -4

Sample Output 1

12

The possible products of the two chosen elements are 2, -3, -4, -6, -8, and 12, so the maximum product is 12.

Sample Input 2

4 3
-1 -2 -3 -4

Sample Output 2

1000000001

The possible products of the three chosen elements are -24, -12, -8, and -6, so the maximum product is -6.

We print this value modulo (10^9+7), that is, 1000000001.

Sample Input 3

2 1
-1 1000000000

Sample Output 3

1000000000

The possible products of the one chosen element are -1 and 1000000000, so the maximum product is 1000000000.

Sample Input 4

10 10
1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1

Sample Output 4

999983200

Be sure to print the product modulo (10^9+7).


import java.util.Scanner;

public class Main {
  public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      // 文字列の入力1
      String str1 = sc.nextLine();
      // 文字列の入力1
      String str2 = sc.nextLine();
      if(!str1.equals(str2)) {
        int count = 0;
        for(int i = 0;i<str1.length();i++) {
          if(str1.charAt(i)!= str2.charAt(i)) {
            count++;
          }
        }
        System.out.println(count);
      }else {
        System.out.println(0);
      }
  }
}

Score : 200 points

Problem Statement

Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.

Operation: Choose one character of S and replace it with a different character.

Constraints

S and T have lengths between 1 and 2\times 10^5 (inclusive).

S and T consists of lowercase English letters.

S and T have equal lengths.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print the answer.

Sample Input 1

cupofcoffee
cupofhottea

Sample Output 1

4

We can achieve the objective in four operations, such as the following:

First, replace the sixth character c with h.

Second, replace the eighth character f with t.

Third, replace the ninth character f with t.

Fourth, replace the eleventh character e with a.

Sample Input 2

abcde
bcdea

Sample Output 2

5

Sample Input 3

apple
apple

Sample Output 3

0

No operations may be needed to achieve the objective.


import java.util.*;
public class Main
{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    char val = sc.nextLine().charAt(0);
	    if(Character.isUpperCase(val)){
	        System.out.println('A');
	    }else{
	        System.out.println('a');
	    }
	}
}

Score : 100 points

Problem Statement

An uppercase or lowercase English letter \alpha will be given as input.
If \alpha is uppercase, print A; if it is lowercase, print a.

Constraints

\alpha is an uppercase (A - Z) or lowercase (a - z) English letter.

Input

Input is given from Standard Input in the following format:

α

Output

If \alpha is uppercase, print A; if it is lowercase, print a.

Sample Input 1

B

Sample Output 1

A

B is uppercase, so we should print A.

Sample Input 2

a

Sample Output 2

a

a is lowercase, so we should print a.


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char c = sc.next().toCharArray()[0];
		if (c>='A'&&c<='Z') {
			System.out.println("A");
		} else {
			System.out.println("a");
		}
	}
}


import java.util.*;
import java.io.*;
import java.util.Scanner;
import java.util.HashMap;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		long sum = 0;
		HashMap<Integer, Integer> map= new HashMap<>();
		for(int i=0;i<n;i++)
		{
			arr[i] = sc.nextInt();
			if(map.containsKey(arr[i]))
			{
				int a = map.get(arr[i]);
				a++;
				map.replace(arr[i],a);
			}
			else
			{
				map.put(arr[i],1);
			}
			sum = sum + (long)arr[i];
		}
		int q = sc.nextInt();
		int[] b = new int[q];
		int[] c = new int[q];
		for(int i=0;i<q;i++)
		{
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
			if(map.containsKey(b[i]))
			{
			int s = map.get(b[i]);
			sum = sum+(long)(s*(c[i]-b[i]));
			System.out.println(sum);
			if(map.containsKey(c[i]))
			{
				int a = map.get(c[i]);
				a = a+s;
				map.replace(c[i],a);
			}
			else
			{
				map.put(c[i],s);
			}
			map.remove(b[i]);
		}
		else
		{
			System.out.println(sum);
		}
		}
	}
}

Score : 400 points

Problem Statement

You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.

You will now successively do the following Q operations:

In the i-th operation, you replace every element whose value is B_{i} with C_{i}.

For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Constraints

All values in input are integers.

1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}

B_{i} \neq C_{i}

Input

Input is given from Standard Input in the following format:

N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}

Output

Print Q integers S_{i} to Standard Output in the following format:

S_{1}
S_{2}
\vdots
S_{Q}

Note that S_{i} may not fit into a 32-bit integer.

Sample Input 1

4
1 2 3 4
3
1 2
3 4
2 4

Sample Output 1

11
12
16

Initially, the sequence A is 1,2,3,4.

After each operation, it becomes the following:

2, 2, 3, 4

2, 2, 4, 4

4, 4, 4, 4

Sample Input 2

4
1 1 1 1
3
1 2
2 1
3 5

Sample Output 2

8
4
4

Note that the sequence A may not contain an element whose value is B_{i}.

Sample Input 3

2
1 2
3
1 100
2 100
100 1000

Sample Output 3

102
200
2000


import java.io.*;
import java.util.*;
public class Main{
	static void main() throws Exception{
		int maxn=(int)1e5;
		int[]occ=new int[maxn+1];
		int n=sc.nextInt();
		long sum=0;
		for(int i=0;i<n;i++) {
			int x=sc.nextInt();
			sum+=x;
			occ[x]++;
		}
		int q=sc.nextInt();
		while(q-->0) {
			int b=sc.nextInt(),c=sc.nextInt();
			int cnt=occ[b];
			occ[c]+=cnt;
			occ[b]=0;
			sum+=(1l*cnt*c);
			sum-=(1l*cnt*b);
			pw.println(sum);
		}
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
		int tc=1;
//		tc=sc.nextInt();
		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

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

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int[] A = in.Int(N);

            long sum = IntStream.of(A).sum();
            Map<Integer, Integer> map = new HashMap<>();
            for (int a : A) {
                map.put(a, map.getOrDefault(a, 0) + 1);
            }

            int Q = in.Int();
            for (int i = 0; i < Q; i++) {
                int B = in.Int();
                int C = in.Int();
                if (map.containsKey(B)) {
                    int cnt = map.get(B);
                    if (cnt > 0) {
                        sum += ((long) C * cnt) - ((long) B * cnt);
                        map.put(C, map.getOrDefault(C, 0) + cnt);
                        map.put(B, 0);
                    }
                }
                out.println(sum);
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

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

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner s = new Scanner(System.in)) {
            int n = Integer.parseInt(s.nextLine());
            int[] a = Arrays.stream(s.nextLine().split(" "))
                        .mapToInt(Integer::parseInt)
                        .toArray();
            int[] b = new int[n];
            int x = 0;
            for (int i = 1; i < n; i++) {
                b[i] = a[0] ^ a[i];
                x ^= b[i];
            }

            int flag = a[0] ^ x;
            for (int i = 0; i < n; i++) {
                b[i] ^= flag;
            }
            System.out.print(a[0]);
            for (int i = 1; i < n; i++) {
                System.out.print(" " + b[i]);
            }
            System.out.println();
        }
    }
}

Score : 500 points

Problem Statement

There are N Snuke Cats numbered 1, 2, \ldots, N, where N is even.

Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.

Recently, they learned the operation called xor (exclusive OR).

What is xor?

For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:

When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3~\textrm{xor}~5 = 6.

They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.

We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i.
Using this information, restore the integer written on the scarf of each Snuke Cat.

Constraints

All values in input are integers.

2 \leq N \leq 200000

N is even.

0 \leq a_i \leq 10^9

There exists a combination of integers on the scarfs that is consistent with the given information.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_N

Output

Print a line containing N integers separated with space.

The i-th of the integers from the left should represent the integer written on the scarf of Snuke Cat i.

If there are multiple possible solutions, you may print any of them.

Sample Input 1

4
20 11 9 24

Sample Output 1

26 5 7 22

5~\textrm{xor}~7~\textrm{xor}~22 = 20

26~\textrm{xor}~7~\textrm{xor}~22 = 11

26~\textrm{xor}~5~\textrm{xor}~22 = 9

26~\textrm{xor}~5~\textrm{xor}~7 = 24

Thus, this output is consistent with the given information.


import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    Map<Long, BigInteger> a = new HashMap<>();
    BigInteger xor = BigInteger.ZERO;
    for (long i = 0; i < n; i++) {
      BigInteger ai = new BigInteger(sc.next());
      xor = xor.xor(ai);
      a.put(i, ai);
    }
    for (long i = 0; i < n; i++) {
      BigInteger bigInteger = a.get(i);
      System.out.print(bigInteger.xor(xor));
      if (i != n - 1) {
        System.out.print(" ");
      }
    }
    System.out.println();
  }
}


import java.util.*;
class Main{

	public static void main (String[] args) throws java.lang.Exception{
       Scanner scan =  new Scanner(System.in);
        int x = scan.nextInt();
        if(360%x!=0) return;
       else
           System.out.println(360/x);}
}

Score : 200 points

Problem Statement

Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the following action K times:

Go one meter in the direction he is facing. Then, turn X degrees counter-clockwise.

Constraints

1 \leq X \leq 179

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the number of times Takahashi will do the action before he is at the starting position again.

Sample Input 1

90

Sample Output 1

4

Takahashi's path is a square.

Sample Input 2

1

Sample Output 2

360


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

class Main {
  public static void main(String [] args) {
    Reader in = new Reader();
    char [] s = in.next().toCharArray();
    StringProcessor solver = new StringProcessor(s);
    System.out.println(solver.countWays());
  }
}
class StringProcessor {
  char [] s;
  int n;
  final int mod = 998244353;
  boolean [][][] vis;
  int [][][] mem;
  int [] cnt;
  int [][] opt;

  StringProcessor(char [] s) {
    this.s = s.clone();
    this.n = this.s.length;
    vis = new boolean [this.n + 1][this.n + 1][this.n + 1];
    cnt = new int [this.n + 1];
    opt = new int [this.n + 1][this.n + 1];
    mem = new int [this.n + 1][this.n + 1][this.n + 1];
    cnt[n] = 0;
    for(int i = n - 1; i >= 0; i--) {
      cnt[i] = cnt[i + 1];
      if(s[i] == '1') cnt[i] = cnt[i] + 1;
    }
    for(int i = 0; i <= n; i++) {
      for(int j = 0; j <= n; j++) {
        for(int k = 0; k <= n; k++) {
          mem[i][j][k] = -1;
          vis[i][j][k] = false;
        }
        opt[i][j] = -1;
      }
    }
  }
  void dfs(int cur, int cntMove, int cntOne) {
    if(vis[cur][cntMove][cntOne]) return ;
    vis[cur][cntMove][cntOne] = true;
    opt[cntMove][cntOne + cnt[cur]] = Math.max(opt[cntMove][cntOne + cnt[cur]], cur);
    int cntZero = cur - cntMove - cntOne;
    if(cntOne >= 2) {
      dfs(cur, cntMove + 1, cntOne - 1);
    }
    if(cntZero >= 2) {
      dfs(cur, cntMove + 1, cntOne);
    }
    if(cntOne >= 1 && cntZero >= 1) {
      dfs(cur, cntMove + 1, cntOne - 1);
      dfs(cur, cntMove + 1, cntOne);
    }
    if(cur + 2 <= n) {
      if(s[cur] == '0' || s[cur + 1] == '0') {
        dfs(cur + 2, cntMove + 1, cntOne);
      }
      if(s[cur] == '1' || s[cur + 1] == '1') {
        dfs(cur + 2, cntMove + 1, cntOne + 1);
      }
    }
    if(cur + 1 <= n) {
      if(s[cur] == '0') {
        if(cntOne > 0) dfs(cur + 1, cntMove + 1, cntOne - 1);
        if(cntZero > 0) dfs(cur + 1, cntMove + 1, cntOne);
      } else {
        if(cntZero > 0) dfs(cur + 1, cntMove + 1, cntOne + 1);
        if(cntOne > 0) dfs(cur + 1, cntMove + 1, cntOne);
      }
    }
  }
  int dp(int cur, int cntOne, int cntZero) {
    if(cntOne == 0 && cntZero == 0) {
      return (cur == n) ? 1 : 0;
    }
    if(mem[cur][cntOne][cntZero] != -1) {
      return mem[cur][cntOne][cntZero];
    }
    int ans = 0;
    if(cur < n) {
      if(s[cur] == '0') {
        if(cntZero > 0) ans += dp(cur + 1, cntOne, cntZero - 1);
        if(cntOne > 0) ans += dp(cur, cntOne - 1, cntZero);
      } else {
        if(cntOne > 0) ans += dp(cur + 1, cntOne - 1, cntZero);
        if(cntZero > 0) ans += dp(cur, cntOne, cntZero - 1);
      }
      ans %= mod;
    } else {
      if(cntOne > 0) {
        ans += dp(cur, cntOne - 1, cntZero);
      }
      if(cntZero > 0) {
        ans += dp(cur, cntOne, cntZero - 1);
      }
      ans %= mod;
    }
    return mem[cur][cntOne][cntZero] = ans;
  }
  int countWays() {
    dfs(0, 0, 0);
    int ans = 1;
    for(int i = 1; i <= n; i++) {
      for(int j = 0; j <= n; j++) {
        int idx = opt[i][j];
        if(idx < 0) continue;
        ans += dp(idx, j, n - i - j);
        ans %= mod;
      }
    }
    return ans;
  }
}

class Reader {
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  StringTokenizer s = new StringTokenizer("");
  Reader () {}
  String nextLine() {
    try {
      return in.readLine();
    } catch (Exception e) {
      e.printStackTrace();
      return "Error";
    }
  }
  String next() {
    while(!s.hasMoreTokens()) {
      s = new StringTokenizer(nextLine());
    }
    return s.nextToken();
  }
  int nextInt() {
    return Integer.parseInt(next());
  }
}

Score : 1100 points

Problem Statement

Given is a string S consisting of 0 and 1. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times:

Remove the two characters at the beginning of S, erase one of them, and reinsert the other somewhere in S. This operation can be applied only when S has two or more characters.

Constraints

1 \leq |S| \leq 300

S consists of 0 and 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of strings, modulo 998244353, that can result from applying the operation on S zero or more times.

Sample Input 1

0001

Sample Output 1

8

Eight strings, 0001, 001, 010, 00, 01, 10, 0, and 1, can result.

Sample Input 2

110001

Sample Output 2

24

Sample Input 3

11101111011111000000000110000001111100011111000000001111111110000000111111111

Sample Output 3

697354558


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < 5; i++) {
            if(scanner.nextInt() == 0){
                System.out.println(i + 1);
                break;
            }
        }
    }
}

Score : 100 points

Problem Statement

We have five variables x_1, x_2, x_3, x_4, and x_5.

The variable x_i was initially assigned a value of i.

Snuke chose one of these variables and assigned it 0.

You are given the values of the five variables after this assignment.

Find out which variable Snuke assigned 0.

Constraints

The values of x_1, x_2, x_3, x_4, and x_5 given as input are a possible outcome of the assignment by Snuke.

Input

Input is given from Standard Input in the following format:

x_1 x_2 x_3 x_4 x_5

Output

If the variable Snuke assigned 0 was x_i, print the integer i.

Sample Input 1

0 2 3 4 5

Sample Output 1

1

In this case, Snuke assigned 0 to x_1, so we should print 1.

Sample Input 2

1 2 0 4 5

Sample Output 2

3


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int answer = IntStream.rangeClosed(1, 5)
            .mapToObj(i -> scanner.nextInt())
            .collect(Collectors.toList())
            .indexOf(0) + 1;
        System.out.println(answer);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

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

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

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        if((x * 2 <= y) && (y <= x * 4) && (y % 2 == 0)) {
		System.out.println("Yes");
		}else{
		System.out.println("No");
		}
    }
}

Score : 200 points

Problem Statement

There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.

Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.

Constraints

1 \leq X \leq 100

1 \leq Y \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

If there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes; otherwise, print No.

Sample Input 1

3 8

Sample Output 1

Yes

The statement "there are 3 animals in total in the garden, and they have 8 legs in total" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.

Sample Input 2

2 100

Sample Output 2

No

There is no combination of numbers of cranes and turtles in which this statement is correct.

Sample Input 3

1 2

Sample Output 3

Yes

We also consider the case in which there are only cranes or only turtles.


import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int k=in.nextInt();
		for(int i=1;i<=n;i++)
		{
			if((k-(i*2))%4==0)
			{
				System.out.println("YES");
				System.exit(0);
			}
		}
		System.out.println("NO");
	}

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//スキャナー
		Scanner s = new Scanner(System.in);

		int numx = s.nextInt();
		int numy = s.nextInt();

		s.close();

		//true=Yes
		boolean ans = true;

		if(numy % 2 == 1) {
			ans = false;
		}
		if(numy < numx * 2 || numy > numx * 4 ) {
			ans = false;
		}

		if(ans) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
      int X = sc.nextInt();
      int Y = sc.nextInt();
      String ans = "No";
      if(X < 51){
        for(int i = 0; i <= X; i++){
          int j = X - i;
            int leg = 2 * i + 4 * j;
      System.out.println(leg);
            if(leg == Y) ans = "Yes";
        }
      }
      System.out.println(ans);
    }
}


import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int x = sc.nextInt();//头数量
        int y = sc.nextInt();//脚数量
        boolean flag = false;
        for(int i = 0; i <= x; i++){
            if ((x-i)*4+i*2==y) {
                flag = true;
                break;
            }
        }

        System.out.println(flag?"Yes":"No");
    }
}


import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		int X = Integer.parseInt(tokens[0]);
		int Y = Integer.parseInt(tokens[1]);

		int temp = Y - (X * 2);
		if (temp % 2 != 0) {
			System.out.println("No");
		} else {
			temp /= 2;
			if (temp <= X) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}

	void calc() {
	}

	void showResult() {
	}
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int n = sc.nextInt();
		int p;

		ArrayList<Integer> array = new ArrayList<Integer>();
		for(int i=0 ; i<100 ; i++) {
			array.add(i+1);
		}

		for(int i=0; i<n; i++) {
			p = sc.nextInt();
			array.set(p-1, 0);
			//array.remove(p-1);
		}
		sc.close();

		if(n == 0) {
			System.out.println(x);
			return;
		}

		Collections.sort(array);

		for(int i=0 ; i<array.size()-1 ; i++) {
			int a = Math.abs(x - array.get(i));
			int b = Math.abs(x - array.get(i + 1));
			if(array.get(i+1)==0) {b = -1;}
			if(a < b){
				System.out.println(array.get(i));
				break;
			}
			if(a == b && a !=0) {
				System.out.println(array.get(i));
				break;
			}

		}

	}

}

Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.


import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    int X, N;
    List<Integer> del_list;

    AtCoder(FastScanner sc) {
        X = sc.nextInt();
        N = sc.nextInt();
        if (N != 0) {
            del_list = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                del_list.add(sc.nextInt());
            }
        }
    }

    void solve(PrintWriter out) {
        if (N == 0) {
            out.println(X);
            return;
        }
        List<Integer> list = new ArrayList<>();
        for (int i = -10000; i <= 10000; i++) {
            list.add(i);
        }
        list.removeAll(del_list);
        int min = Integer.MAX_VALUE;
        int ans = 0;
        for (int i : list) {
            int abs = Math.abs(X - i);
//            out.println(i + " " + abs);
            if (min > abs) {
                min = abs;
                ans = i;
            }
        }
        out.println(ans);
    }

}

class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

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

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

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

    public int[] arrayInt(int N) {
        int[] array = new int[N];
        for (int i = 0; i < N; i++) {
            array[i] = nextInt();
        }
        return array;
    }

    public long[] arrayLong(int N) {
        long[] array = new long[N];
        for (int i = 0; i < N; i++) {
            array[i] = nextLong();
        }
        return array;
    }

    public double[] arrayDouble(int N) {
        double[] array = new double[N];
        for (int i = 0; i < N; i++) {
            array[i] = nextDouble();
        }
        return array;
    }

    public String[] arrayString(int N) {
        String[] array = new String[N];
        for (int i = 0; i < N; i++) {
            array[i] = next();
        }
        return array;
    }
}

class My {

    static void ans(boolean b) {
        System.out.println(b ? "Yes" : "No");
    }

    static void ANS(boolean b) {
        System.out.println(b ? "YES" : "NO");
    }

    static String sort(String s) {
        char[] ch = s.toCharArray();
        Arrays.sort(ch);
        return String.valueOf(ch);
    }

    static String reverse(String s) {
        return new StringBuilder(s).reverse().toString();
    }

    static int[] reverse(int[] array) {
        for (int i = 0; i < array.length / 2; i++) {
            int temp = array[i];
            array[i] = array[array.length - 1 - i];
            array[array.length - 1 - i] = temp;
        }
        return array;
    }

    static long[] reverse(long[] array) {
        for (int i = 0; i < array.length / 2; i++) {
            long temp = array[i];
            array[i] = array[array.length - 1 - i];
            array[array.length - 1 - i] = temp;
        }
        return array;
    }

    static double[] reverse(double[] array) {
        for (int i = 0; i < array.length / 2; i++) {
            double temp = array[i];
            array[i] = array[array.length - 1 - i];
            array[array.length - 1 - i] = temp;
        }
        return array;
    }

    static String[] reverse(String[] array) {
        for (int i = 0; i < array.length / 2; i++) {
            String temp = array[i];
            array[i] = array[array.length - 1 - i];
            array[array.length - 1 - i] = temp;
        }
        return array;
    }

    static char[] reverse(char[] array) {
        for (int i = 0; i < array.length / 2; i++) {
            char temp = array[i];
            array[i] = array[array.length - 1 - i];
            array[array.length - 1 - i] = temp;
        }
        return array;
    }

    static long min(long... numbers) {
        Arrays.sort(numbers);
        return numbers[0];
    }

    static int min(int... numbers) {
        Arrays.sort(numbers);
        return numbers[0];
    }

    static double min(double... numbers) {
        Arrays.sort(numbers);
        return numbers[0];
    }

    static long max(long... numbers) {
        Arrays.sort(numbers);
        return numbers[numbers.length - 1];
    }

    static int max(int... numbers) {
        Arrays.sort(numbers);
        return numbers[numbers.length - 1];
    }

    static double max(double... numbers) {
        Arrays.sort(numbers);
        return numbers[numbers.length - 1];
    }

    static int sum(long number) {
        int sum = 0;
        while (number > 0) {
            sum += number % 10;
            number /= 10;
        }
        return sum;
    }

    static Map<Integer, Integer> tally(int[] array) {
        Map<Integer, Integer> map = new TreeMap<>();
        for (int k : array) {
            int v = map.getOrDefault(k, 0);
            map.put(k, ++v);
        }
        return map;
    }

    static Map<Long, Integer> tally(long[] array) {
        Map<Long, Integer> map = new TreeMap<>();
        for (long k : array) {
            int v = map.getOrDefault(k, 0);
            map.put(k, ++v);
        }
        return map;
    }

    static Map<Double, Integer> tally(double[] array) {
        Map<Double, Integer> map = new TreeMap<>();
        for (double k : array) {
            int v = map.getOrDefault(k, 0);
            map.put(k, ++v);
        }
        return map;
    }

    static Map<String, Integer> tally(String[] array) {
        Map<String, Integer> map = new TreeMap<>();
        for (String k : array) {
            int v = map.getOrDefault(k, 0);
            map.put(k, ++v);
        }
        return map;
    }

    static Map<Character, Integer> tally(char[] array) {
        Map<Character, Integer> map = new TreeMap<>();
        for (char k : array) {
            int v = map.getOrDefault(k, 0);
            map.put(k, ++v);
        }
        return map;
    }

}


import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sn = new Scanner(System.in);
        int X = sn.nextInt();
        int N = sn.nextInt();
        List<Integer> pList = new ArrayList<>();

        if(N == 0) System.out.println(X);
        else{
            for(int i=0; i<N; i++){
                pList.add(sn.nextInt());
                }

            Arrays.asList(pList);
            int u_i = X;
            int d_i = X;

            while(true){
                if(!pList.contains(u_i) && !pList.contains(d_i)){
                    System.out.println(d_i);
                    break;
                }
                else if(!pList.contains(u_i)){
                    System.out.println(u_i);
                    break;
                }
                else if(!pList.contains(d_i)){
                    System.out.println(d_i);
                    break;
                }

                u_i++;
                d_i--;
            }
        }
    }
}