Question:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	static final long MOD = 1000000007;
	static long modpow(long n, long y){
		if(y == 0){
			return 1;
		}else if(y == 1){
			return n % MOD;
		}else{
			if(y % 2 == 0){
				long r = modpow(n , y / 2);
				return (r * r) % MOD;
			}else{
				long r = modpow(n , y / 2);
				long r2 = (r * r) % MOD;
				return (r2 * n) % MOD;
			}
		}
	}
	static long modinv(long n){
		return modpow(n , MOD - 2);
	}
	static long comb(int N , int R, long fact[]){
		long ret = fact[N];
		ret = (ret * modinv(fact[R])) % MOD;
		ret = (ret * modinv(fact[N - R])) % MOD;
		return ret;
	}
	static class Edge{
		int src;
		int dst;
		int idx;
		public Edge(int src , int dst , int idx) {
			this.src = src;
			this.dst = dst;
			this.idx = idx;
		}
	}
	static class Vertex{
		List<Edge> adj;
		public Vertex() {
			adj = new ArrayList<Edge>();
		}
	}
	static long[] rec(int cur , Vertex[] vs , long memo[] , long memoSize[] , int parent){
		long size = 1;
		long pattern = 1;
		for(Edge e : vs[cur].adj){
			if(e.dst == parent){
				continue;
			}
			if(memo[e.idx] < 0){
				long r[] = rec(e.dst , vs , memo , memoSize , cur);
				memoSize[e.idx] = r[0];
				memo[e.idx] = r[1];
			}
			size += memoSize[e.idx];
		}
		int S = (int)size - 1;
		for(Edge e : vs[cur].adj){
			if(e.dst == parent){
				continue;
			}
			int s = (int)memoSize[e.idx];
			pattern = (pattern * comb(S, s, fact)) % MOD;
			pattern = (pattern * memo[e.idx]) % MOD;
			S -= s;
		}
		long ret[] = {size, pattern};
		return ret;
	}
	static long[] fact;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		fact = new long[N + 1];
		fact[0] = 1;
		fact[1] = 1;
		for(int i = 2 ; i < fact.length ; ++i){
			fact[i] = ((long)(i) * fact[i - 1]) % MOD;
		}
		Vertex vs[] = new Vertex[N];
		for(int i = 0 ; i < N ; ++i){
			vs[i] = new Vertex();
		}
		int E = N - 1;
		for(int i = 0 ; i< N -1 ; ++i){
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			Edge e0 = new Edge(a, b, 2 * i);
			Edge e1 = new Edge(b, a, 2 * i + 1);
			vs[a].adj.add(e0);
			vs[b].adj.add(e1);
		}
		long memo[] = new long[E * 2];
		Arrays.fill(memo, -1);
		long memoSize[] = new long[E * 2];
		Arrays.fill(memoSize, -1);
		for(int i = 0 ; i < N ; ++i){
			rec(i , vs, memo, memoSize, i);
		}
		for(int i = 0 ; i < memo.length ; ++i){
//			System.out.println(i+" "+memo[i]+" "+memoSize[i]);
		}
		for(int i = 0 ; i < N ; ++i){
			Vertex v = vs[i];
			long pattern = 1;
			int S = (int)N - 1;
			for(Edge e : v.adj){
				int s = (int)memoSize[e.idx];
				pattern = (pattern * comb(S, s, fact)) % MOD;
				pattern = (pattern * memo[e.idx]) % MOD;
				S -= s;
			}
			System.out.println(pattern);
		}
	}
}

Choices:
- Time Limit Exceeded
- No abnormally found
- Compile Error
- Memory Limit Exceeded


Question:
import java.util.Scanner;

public class Main {
	static final long MOD = 1000000007;
	static long modpow(long n, long y){
		if(y == 0){
			return 1;
		}else if(y == 1){
			return n % MOD;
		}else{
			if(y % 2 == 0){
				long r = modpow(n , y / 2);
				return (r * r) % MOD;
			}else{
				long r = modpow(n , y / 2);
				long r2 = (r * r) % MOD;
				return (r2 * n) % MOD;
			}
		}
	}
	static long modinv(long n){
		return modpow(n , MOD - 2);
	}
	static long comb(int N , int R, long fact[]){
		long ret = fact[N];
		ret = (ret * modinv(fact[R])) % MOD;
		ret = (ret * modinv(fact[N - R])) % MOD;
		return ret;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long fact[] = new long[2 * n];
		fact[0] = 1;
		fact[1] = 1;
		for(int i = 2 ; i < fact.length ; ++i){
			fact[i] = ((long)(i) * fact[i - 1]) % MOD;
		}
		if(k > n){
			System.out.println(comb(2 * n - 1 , n, fact));
			return ;
		}
		long S = 1;
		for(int i = 1 ; i <= k ; ++i){
			long x = comb(n, i, fact);
			long y = comb(n - 1 , i, fact);
			S += (x * y) % MOD;
			S = S % MOD;
		}
		System.out.println(S);

	}
}

Choices:
- Compile Error
- Runtime Error
- Internal error
- Time Limit Exceeded


Question:
import java.util.Scanner;

public class Main {
	static final long MOD = 1000000007;
	static long modpow(long n, long y){
		if(y == 0){
			return 1;
		}else if(y == 1){
			return n % MOD;
		}else{
			if(y % 2 == 0){
				long r = modpow(n , y / 2);
				return (r * r) % MOD;
			}else{
				long r = modpow(n , y / 2);
				long r2 = (r * r) % MOD;
				return (r2 * n) % MOD;
			}
		}
	}
	static long modinv(long n){
		return modpow(n , MOD - 2);
	}
	static long comb(int N , int R){
		long ret = 1;
		for(long v = N - R + 1 ; v <= N ; ++v){
			ret = (ret * v) % MOD;
		}
		for(long v = 2 ; v <= R ; ++v){
			ret = (ret * modinv(v)) % MOD;
		}
		return ret;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		if(k > n){
			System.out.println(comb(2 * n - 1 , n));
			return ;
		}
		long S = 1;
		for(int i = 1 ; i <= k ; ++i){
			long x = comb(n, i);
			// n - i i
			long y = comb(n - 1 , i);
			S += (x * y) % MOD;
			S = S % MOD;
//			System.out.println(S+" "+all+" "+(all - S));
		}
		System.out.println(S);
		// k <= n <= 20000
		// a_1 + a_2 + a_3 = n
		// | a_1 - 1 | + | a_2 - 1 | + | a_3 - 1 | > k

	}
}

Choices:
- Compile Error
- Time Limit Exceeded
- No abnormally found
- Internal error


Question:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	static class Pair implements Comparable<Pair>{
		long left;
		long right;
		public Pair(long l , long r) {
			left = l;
			right = r;
		}
		@Override
		public int compareTo(Pair o) {
			if(left == o.left) {
				return Long.compare(right, o.right);
			}
			return Long.compare(left, o.left);
		}
		@Override
		public String toString() {
			return left + " " + right + " " + (right - left + 1);
		}
	}
	static long len(List<Pair> ps) {
		if(ps.size() == 0) {
			return 0;
		}
		Pair p = ps.get(0);
		long l = p.left;
		long r = p.right;
		for(Pair pp : ps) {
			l = Math.max(l, pp.left);
			r = Math.min(r, pp.right);
		}
		if(l > r) {
			return 0;
		}
		return r - l + 1;
	}
	static long solve(long L[] , long R[]) {
		int N = L.length;
		if(N == 2) {
			return R[1] + R[0] - L[1] - L[0] + 2;
		}
		Pair ps[] = new Pair[N];
		for(int i = 0 ; i < N ; ++i) {
			ps[i] = new Pair(L[i] , R[i]);
		}
		long ret = 0;
		{
			List<Pair> l1 = new ArrayList<>();
			List<Pair> l2 = new ArrayList<>();
			l1.add(ps[0]);
			for(int i = 1 ; i < N ; ++i) {
				l2.add(ps[i]);
			}
			long ll = len(l1) + len(l2);
			ret = Math.max(ll, ret);
		}
		for(int i = 0 ; i < N ; ++i) {
			for(int j = 0 ; j < N ; ++j) {
				long l = L[i];
				long r = R[j];
				List<Pair> l1 = new ArrayList<>();
				List<Pair> l2 = new ArrayList<>();
				for(Pair p : ps) {
					if(p.left <= l && r <= p.right) {
						l1.add(p);
					}else {
						l2.add(p);
					}
				}
				long ll = len(l1) + len(l2);
				ret = Math.max(ll, ret);
			}
		}
		return ret;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long L[] = new long[N];
		long R[] = new long[N];
		for(int i = 0 ; i < N ; ++i) {
			L[i] = sc.nextLong();
			R[i] = sc.nextLong();
		}
		System.out.println(solve(L, R));
	}
}

Choices:
- Memory Limit Exceeded
- Time Limit Exceeded
- Internal error
- Compile Error


Question:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 2 => 2 1 => 1
		// 3 => 2 3 1 => 3
		// 4 => 2 3 4 1 => 6
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long ret = 0;
		for(int i = 1 ; i < N ; ++i){
			ret += i % (i + 1);
//			System.out.println(i % (i + 1));
		}
		System.out.println(ret);
	}
}

Choices:
- Internal error
- Memory Limit Exceeded
- Time Limit Exceeded
- Runtime Error


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

	int N;
	int[] memo;
	Map<Integer, Integer>[] primes;

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		memo = new int[N + 1];
		Arrays.fill(memo, 0);
		memo[1] = 1;
		memo[2] = 2;
		memo[3] = 2;
		primes = new Map[N + 1];
		for (int i = 0; i <= N; ++i) {
			primes[i] = new HashMap<>();
		}
		primes[2].put(2, 1);
		primes[3].put(3, 1);
	}

	void sub(int val) {
		if (val <= 3) {
			return;
		}

		int divVal = -1;
		for (int i = 2; i <= Math.sqrt(val) + 1; ++i) {
			if (val % i == 0) {
				divVal = i;
				break;
			}
		}

		if (divVal < 0) {
			primes[val].put(val, 1);
			memo[val] = 2;
			return;
		} else {
			int remain = val / divVal;
			for (Integer key : primes[remain].keySet()) {
				primes[val].put(key, primes[remain].get(key));
			}
			for (Integer key : primes[divVal].keySet()) {
				if (primes[val].containsKey(key)) {
					primes[val].put(key, primes[val].get(key) + primes[divVal].get(key));
				} else {
					primes[val].put(key, primes[divVal].get(key));
				}
			}

			int count = 1;
			for (Integer key : primes[val].keySet()) {
				count *= primes[val].get(key) + 1;
			}
			memo[val] = count;
		}

	}

	void calc() {
		for (int i = 4; i <= N; ++i) {
			sub(i);
		}
		long result = 0L;
		for (int i = 1; i <= N; ++i) {
			result += (long) i * (long) memo[i];
		}
		System.out.println(result);
	}

	void showResult() {
	}
}

Choices:
- Internal error
- Runtime Error
- Compile Error
- Time Limit Exceeded


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

public class Main {
	int N, M;
	int[] s, c;
	int[] buf;
	boolean enable = true;

	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(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
		s = new int[M];
		c = new int[M];
		for (int i = 0; i < M; ++i) {
			tokens = in.readLine().split(" ");
			s[i] = Integer.parseInt(tokens[0]) - 1;
			c[i] = Integer.parseInt(tokens[1]);
		}
		this.buf = new int[N];
		Arrays.fill(buf, -1);
	}

	void calc() {
		for (int i = 0; i < M; ++i) {
			if (buf[s[i]] == -1) {
				// 未初期化，埋められる
				buf[s[i]] = c[i];
			} else if (buf[s[i]] != c[i]) {
				// 同じの場合OK
				enable = false;
				break;
			}
		}
		if (!enable) {
			return;
		}
		// 残りを埋める
		if (buf[0] == 0) {
			if (N != 1) {
				enable = false;
			}
			return;
		}
		buf[0] = buf[0] < 0 ? 1 : buf[0];
		for (int i = 1; i < M; ++i) {
			if (buf[i] < 0) {
				buf[i] = 0;
			}
		}
	}

	void showResult() {
		if (enable) {
			StringBuilder strBuilder = new StringBuilder();
			for (int i = 0; i < N; ++i) {
				strBuilder.append(Integer.toString(buf[i]));
			}
			System.out.println(strBuilder.toString());
		} else {
			System.out.println(-1);
		}
	}

}

Choices:
- Runtime Error
- Internal error
- No abnormally found
- Compile Error


Question:
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	static class Node {
		int id;
		List<Edge> edges = new ArrayList<>();
		/*
		 * Queue<Edge> edges = new PriorityQueue<>(new Comparator<Edge>() {
		 *
		 * @Override public int compare(Edge o1, Edge o2) { return -1 *
		 * Integer.compare(o1.length, o2.length); } });
		 */
		Set<Edge> passedEdges = new HashSet<>();
		int dist = Integer.MIN_VALUE / 2;

		Node(int id) {
			this.id = id;
		}
	}

	static class Edge {
		int src, dst, length;

		Edge(int src, int dst, int length) {
			this.src = src;
			this.dst = dst;
			this.length = length;
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int M = Integer.parseInt(tokens[1]);
		int P = Integer.parseInt(tokens[2]);

		Node[] graph = new Node[N];
		for (int i = 0; i < N; ++i) {
			graph[i] = new Node(i);
		}
		List<Edge> edges = new ArrayList<>(M);
		for (int i = 0; i < M; ++i) {
			tokens = in.readLine().split(" ");
			int a = Integer.parseInt(tokens[0]);
			int b = Integer.parseInt(tokens[1]);
			int c = Integer.parseInt(tokens[2]);
			Edge edge = new Edge(a - 1, b - 1, c - P);
			graph[a - 1].edges.add(edge);
			edges.add(edge);
		}
		// 開始ノードの距離は0
		graph[0].dist = 0;

		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < edges.size(); ++j) {
				Edge edge = edges.get(j);
				if (graph[edge.dst].dist < graph[edge.src].dist + edge.length) {
					graph[edge.dst].dist = graph[edge.src].dist + edge.length;
					graph[edge.dst].passedEdges.addAll(graph[edge.src].passedEdges);
					graph[edge.dst].passedEdges.add(edge);
				}
			}
		}

		// 閉路チェック
		boolean hasNegativeLoop = false;
		for (Edge edge : graph[graph.length - 1].passedEdges) {
			if (graph[edge.src].dist + edge.length > graph[edge.dst].dist) {
				hasNegativeLoop = true;
				break;
			}
		}
		if (hasNegativeLoop) {
			System.out.println("-1");
		} else {
			int result = Math.max(0, graph[graph.length - 1].dist);
			System.out.println(result);
		}
	}
}

Choices:
- No abnormally found
- Internal error
- Time Limit Exceeded
- Runtime Error


Question:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int X = Integer.parseInt(tokens[1]);
		List<Integer> points = new ArrayList<>();
		points.add(X);
		tokens = in.nextLine().split(" ");
		for (int i = 0; i < N; ++i) {
			points.add(Integer.parseInt(tokens[i]));
		}
		Collections.sort(points);
		Queue<Integer> queue = new PriorityQueue<Integer>(N + 1, new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				if (o1 > o2) {
					return -1;
				} else if (o1 < o2) {
					return 1;
				} else {
					return 0;
				}
			}
		});
		for (int i = 1; i < points.size(); ++i) {
			queue.add(points.get(i) - points.get(i - 1));
		}

		while (true) {
			if (queue.size() == 1) {
				break;
			}
			Integer a = queue.poll();
			Integer b = queue.poll();
			if (a == b) {
				queue.add(a);
			} else {
				queue.add(gcd(a, b));
			}
		}
		System.out.println(queue.poll());

		in.close();
	}

	private static int gcd(int large, int small) {
		if (small > large) {
			return gcd(small, large);
		}
		if (small == large) {
			return small;
		}
		return gcd(small, large - small);
	}

}

Choices:
- Runtime Error
- Compile Error
- Internal error
- Memory Limit Exceeded


Question:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int M = Integer.parseInt(tokens[1]);
		int Q = Integer.parseInt(tokens[2]);
		int[][] ranges = new int[N][N];
		for (int i = 0; i < M; ++i) {
			tokens = in.nextLine().split(" ");
			int l = Integer.parseInt(tokens[0]);
			int r = Integer.parseInt(tokens[1]);
			ranges[l - 1][r - 1]++;
		}
		int[] p = new int[Q];
		int[] q = new int[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.nextLine().split(" ");
			p[i] = Integer.parseInt(tokens[0]);
			q[i] = Integer.parseInt(tokens[1]);
		}
		for (int i = 0; i < Q; ++i) {
			int left = p[i];
			int right = q[i];
			System.out.println(calcSimple(left, right, ranges));
		}
		in.close();
	}

	private static int calcSimple(int p, int q, int[][] ranges) {
		int result = 0;
		for (int i = p - 1; i <= q - 1; ++i) {
			for (int j = p - 1; j <= q - 1; ++j) {
				result += ranges[i][j];
			}
		}
		return result;
	}
}

Choices:
- Internal error
- Time Limit Exceeded
- Memory Limit Exceeded
- Runtime Error


Question:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());
        int s = Integer.parseInt(sc.next());
        int p = Integer.parseInt(sc.next());
        String t = sc.next();

        char[] c = t.toCharArray();
        for(int i = 0; i < n; i++){
            if(c[i] == 'r'){
                c[i] = 'p';
            }else if(c[i] == 's'){
                c[i] = 'r';
            }else if(c[i] == 'p'){
                c[i] = 's';
            }
        }

        boolean[] b = new boolean[n];
        Arrays.fill(b, true);
        for(int i = k; i < n-k; i++){
            if(c[i] == c[i-k]){
                b[i] = false;
                if(c[i] == 'r'){
                    if(c[i+k] == 's'){
                        c[i] = 'p';
                    }else{
                        c[i] = 's';
                    }
                }else if(c[i] == 's'){
                    if(c[i+k] == 'p'){
                        c[i] = 'r';
                    }else{
                        c[i] = 'p';
                    }
                }else if(c[i] == 'p'){
                    if(c[i+k] == 'r'){
                        c[i] = 's';
                    }else{
                        c[i] = 'r';
                    }
                }
            }
        }

        for(int i = n-k; i < n; i++){
            if(c[i] == c[i-k]){
                b[i] = false;
            }
        }

        int ans = 0;
        for(int i = 0; i < n; i++){
            if(b[i]){
                if(c[i] == 'r'){
                    ans += r;
                }else if(c[i] == 's'){
                    ans += s;
                }else if(c[i] == 'p'){
                    ans += p;
                }
            }
        }
        System.out.println(ans);
    }
}

Choices:
- Internal error
- Runtime Error
- Memory Limit Exceeded
- No abnormally found


Question:
import java.io.*;
import java.util.*;

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

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

    void solve(){

        long[] a = new long[1001];
        long t = 0;

        for(int i = 1; i < 1001; i++){
            t += i;
            a[i] = t;
        }

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p = new int[1001];

        for(int i = 0; i < n; i++){
            p[i] = sc.nextInt();
        }

        int l = 0;
        int r = k;
        double s = 0;
        double max = 0;

        for(int i = 0; i < r; i++){
            s += (double)a[p[i]] / p[i];
        }

        max = s;

        while(r < n){
            s -= (double)a[p[l]] / p[l];
            l++;
            r++;
            s += (double)a[p[r - 1]] / p[r - 1];
            max = Math.max(s, max);
        }

        System.out.println(String.format("%.12f", max));

    }

    long mod_pow(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

    long mod_inv(long a){ // return aの逆元 (mod MOD)
        return mod_pow(a, MOD - 2);
    }

    long fact(long n){ // return n!
        if(n == 0){
            return 1;
        }
        return n * fact(n - 1);
    }

    long mod_fact(long n){ // retur n! (mod MOD)
        if(n == 0){
            return 1;
        }
        return n * mod_fact(n - 1) % MOD;
    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    boolean is_prime(long a){ // aの素数判定
        if(a <= 1) return false;
        for(int i = 2; i * i <= a; i++){
            if(a % i == 0) return false;
        }
        return true;
    }

    String nextPermutation(String s){ // return sの次の順列
        ArrayList<Character> list = new ArrayList<>();
        for(int i = 0; i < s.length(); i++) list.add(s.charAt(i));

        int pivotPos = -1;
        char pivot = 0;
        for(int i = list.size() - 2; i >= 0; i--){
            if(list.get(i) < list.get(i+1)){
    			pivotPos = i;
    			pivot = list.get(i);
    			break;
    		}
    	}

        if(pivotPos == -1 && pivot == 0) return null;

        int L = pivotPos + 1;
        int R = list.size() - 1;
    	int minPos = -1;
    	char min = Character.MAX_VALUE;
    	for(int i = R; i >= L; i--){
    		if(pivot < list.get(i)){
    			if(list.get(i) < min){
    				min = list.get(i);
    				minPos = i;
    			}
    		}
    	}

    	Collections.swap(list, pivotPos, minPos);
    	Collections.sort(list.subList(L, R + 1));

    	StringBuilder sb = new StringBuilder();
    	for(int i=0; i<list.size(); i++) sb.append(list.get(i));

    	return sb.toString();
    }

}

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

class Pair implements Comparable<Pair>{
    long a, b;
    public Pair(long i, long j){
        a = i;
        b = j;
    }

    @Override
    public int compareTo(Pair p){
        if(this.b < p.b) return -1;
        else if(this.b > p.b) return 1;
        else return 0;
    }
}

Choices:
- Internal error
- No abnormally found
- Time Limit Exceeded
- Runtime Error


Question:
import java.io.*;
import java.util.*;

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

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

    void solve(){

        long[] a = new long[1001];
        long t = 0;

        for(int i = 1; i < 1001; i++){
            t += i;
            a[i] = t;
        }

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p = new int[1001];

        for(int i = 0; i < n; i++){
            p[i] = sc.nextInt();
        }

        int l = 0;
        int r = k;
        double s = 0;
        double max = 0;

        for(int i = 0; i < r; i++){
            s += (double)a[p[i]] / p[i];
            System.out.println(s);
        }

        max = s;

        while(r < n){
            s -= (double)a[p[l]] / p[l];
            l++;
            r++;
            s += (double)a[p[r - 1]] / p[r - 1];
            max = Math.max(s, max);
        }

        System.out.println(String.format("%.12f", max));

    }

    long mod_pow(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

    long mod_inv(long a){ // return aの逆元 (mod MOD)
        return mod_pow(a, MOD - 2);
    }

    long fact(long n){ // return n!
        if(n == 0){
            return 1;
        }
        return n * fact(n - 1);
    }

    long mod_fact(long n){ // retur n! (mod MOD)
        if(n == 0){
            return 1;
        }
        return n * mod_fact(n - 1) % MOD;
    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    boolean is_prime(long a){ // aの素数判定
        if(a <= 1) return false;
        for(int i = 2; i * i <= a; i++){
            if(a % i == 0) return false;
        }
        return true;
    }

    String nextPermutation(String s){ // return sの次の順列
        ArrayList<Character> list = new ArrayList<>();
        for(int i = 0; i < s.length(); i++) list.add(s.charAt(i));

        int pivotPos = -1;
        char pivot = 0;
        for(int i = list.size() - 2; i >= 0; i--){
            if(list.get(i) < list.get(i+1)){
    			pivotPos = i;
    			pivot = list.get(i);
    			break;
    		}
    	}

        if(pivotPos == -1 && pivot == 0) return null;

        int L = pivotPos + 1;
        int R = list.size() - 1;
    	int minPos = -1;
    	char min = Character.MAX_VALUE;
    	for(int i = R; i >= L; i--){
    		if(pivot < list.get(i)){
    			if(list.get(i) < min){
    				min = list.get(i);
    				minPos = i;
    			}
    		}
    	}

    	Collections.swap(list, pivotPos, minPos);
    	Collections.sort(list.subList(L, R + 1));

    	StringBuilder sb = new StringBuilder();
    	for(int i=0; i<list.size(); i++) sb.append(list.get(i));

    	return sb.toString();
    }

}

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

class Pair implements Comparable<Pair>{
    long a, b;
    public Pair(long i, long j){
        a = i;
        b = j;
    }

    @Override
    public int compareTo(Pair p){
        if(this.b < p.b) return -1;
        else if(this.b > p.b) return 1;
        else return 0;
    }
}

Choices:
- Time Limit Exceeded
- Runtime Error
- Internal error
- Memory Limit Exceeded


Question:
import java.io.*;
import java.util.*;

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

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

    void solve(){

        long[] a = new long[1001];
        long t = 0;

        for(int i = 1; i < 1001; i++){
            t += i;
            a[i] = t;
        }

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p = new int[1001];

        for(int i = 0; i < n; i++){
            p[i] = sc.nextInt();
        }

        int l = 0;
        int r = k;
        double s = 0;
        double max = 0;

        for(int i = 0; i < r; i++){
            s += (double)a[p[i]] / p[i];
            System.out.println(s);
        }

        max = s;

        while(r < n){
            s -= (double)a[p[l]] / p[l];
            l++;
            r++;
            s += (double)a[p[r - 1]] / p[r - 1];
            max = Math.max(s, max);
        }

        System.out.println(String.format("%.7f", max));

    }

    long mod_pow(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

    long mod_inv(long a){ // return aの逆元 (mod MOD)
        return mod_pow(a, MOD - 2);
    }

    long fact(long n){ // return n!
        if(n == 0){
            return 1;
        }
        return n * fact(n - 1);
    }

    long mod_fact(long n){ // retur n! (mod MOD)
        if(n == 0){
            return 1;
        }
        return n * mod_fact(n - 1) % MOD;
    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    boolean is_prime(long a){ // aの素数判定
        if(a <= 1) return false;
        for(int i = 2; i * i <= a; i++){
            if(a % i == 0) return false;
        }
        return true;
    }

    String nextPermutation(String s){ // return sの次の順列
        ArrayList<Character> list = new ArrayList<>();
        for(int i = 0; i < s.length(); i++) list.add(s.charAt(i));

        int pivotPos = -1;
        char pivot = 0;
        for(int i = list.size() - 2; i >= 0; i--){
            if(list.get(i) < list.get(i+1)){
    			pivotPos = i;
    			pivot = list.get(i);
    			break;
    		}
    	}

        if(pivotPos == -1 && pivot == 0) return null;

        int L = pivotPos + 1;
        int R = list.size() - 1;
    	int minPos = -1;
    	char min = Character.MAX_VALUE;
    	for(int i = R; i >= L; i--){
    		if(pivot < list.get(i)){
    			if(list.get(i) < min){
    				min = list.get(i);
    				minPos = i;
    			}
    		}
    	}

    	Collections.swap(list, pivotPos, minPos);
    	Collections.sort(list.subList(L, R + 1));

    	StringBuilder sb = new StringBuilder();
    	for(int i=0; i<list.size(); i++) sb.append(list.get(i));

    	return sb.toString();
    }

}

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

class Pair implements Comparable<Pair>{
    long a, b;
    public Pair(long i, long j){
        a = i;
        b = j;
    }

    @Override
    public int compareTo(Pair p){
        if(this.b < p.b) return -1;
        else if(this.b > p.b) return 1;
        else return 0;
    }
}

Choices:
- Memory Limit Exceeded
- Compile Error
- Runtime Error
- Internal error


Question:
import java.util.*;

public class Main{

    static int gcd(int a, int b) {//最大公約数を求める
        if(b == 0) return a;
        return gcd(b, a%b);
    }

    public static void main(String args[]){
        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int n = sc.nextInt();
        int[] a = new int[n];
        //int min = Integer.MAX_VALUE;
        //int num;//最大公約数
        a[0] = sc.nextInt();
        a[1] = sc.nextInt();
        /*int tmp;
        int x;
        int y;*/
        /*while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        num = y;*/
        //System.out.println(num);
        for(int i = 2; i < n; i++){
            a[i] = sc.nextInt();
            /*x = Math.max(num, a[i]);
            y = Math.min(num, a[i]);
            //min = Math.min(a[i], min);
            while ((tmp = x % y) != 0) {
                x = y;
                y = tmp;
            }
            num = y;*/
        }
        //System.out.println(num);
        int ans = 0;
        //boolean b = true;
        /*for(int i = 1; i < min + 1; i++){
            for(int j = 0;j < n; j++){
                if(a[j] % i != 0) b = false;
            }
            if(b) ans = Math.max(i, ans);
            b = true;
        }*/
        /*for(int i = 0; i < n; i++){
            for(int j = 1; j < num + 1; j++){
                for(int k = 0; k < n; k++){
                    if(k != i && a[k] % j != 0){
                        b = false;
                        break;
                    }
                }
                if(b) ans = Math.max(j, ans);
                b = true;
            }
        }*/
        int l = 0;
        for(int i = 0; i < Math.min(n, 50000); i++){
            boolean flag = false;
            if(n == 2){
                ans = Math.max(a[0], a[1]);
                break;
            }
            if(i != 0 && i != 1){
                /*x = Math.max(a[0], a[1]);
                y = Math.min(a[0], a[1]);
                while ((tmp = x % y) != 0) {
                    x = y;
                    y = tmp;
                }
                l = y;*/
                if(gcd(a[0], a[1]) == 1 && !flag){
                    flag = true;
                }
                l = gcd(a[0], a[1]);
            }else if(i == 0){
                /*x = Math.max(a[2], a[1]);
                y = Math.min(a[2], a[1]);
                while ((tmp = x % y) != 0) {
                    x = y;
                    y = tmp;
                }
                l = y;*/
                if(gcd(a[2], a[1]) == 1 && !flag){
                    flag = true;
                }
                l = gcd(a[2], a[1]);
            }else if(i == 1){
                /*x = Math.max(a[0], a[2]);
                y = Math.min(a[0], a[2]);
                while ((tmp = x % y) != 0) {
                    x = y;
                    y = tmp;
                }
                l = y;*/
                if(gcd(a[0], a[2]) == 1 && !flag){
                    flag = true;
                }
                l = gcd(a[0], a[2]);
            }
            //for(int j = 2; j < n; j++){
            for(int j = 0; j < n; j++){
                if(i != j){
                    /*x = Math.max(l, a[j]);
                    y = Math.min(l, a[j]);
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    l = y;*/
                    if(gcd(l, a[j]) == 1 && !flag){
                        flag = true;
                    }else if(gcd(l, a[j]) == 1 && flag){
                        break;
                    }
                    l = gcd(l, a[j]);
                }
            }
            ans = Math.max(l, ans);
        }

        // 出力
        System.out.println(ans);

    }

}

Choices:
- No abnormally found
- Runtime Error
- Memory Limit Exceeded
- Time Limit Exceeded


Question:
import java.util.*;

public class ABC125_C{

    static int gcd(int a, int b) {//最大公約数を求める
        if(b == 0) return a;
        return gcd(b, a%b);
    }

    public static void main(String args[]){

        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int n = sc.nextInt();
        int[] a = new int[n];
        //int min = Integer.MAX_VALUE;
        //int num;//最大公約数
        a[0] = sc.nextInt();
        a[1] = sc.nextInt();
        /*int tmp;
        int x;
        int y;*/
        /*while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        num = y;*/
        //System.out.println(num);
        for(int i = 2; i < n; i++){
            a[i] = sc.nextInt();
            /*x = Math.max(num, a[i]);
            y = Math.min(num, a[i]);
            //min = Math.min(a[i], min);
            while ((tmp = x % y) != 0) {
                x = y;
                y = tmp;
            }
            num = y;*/
        }
        //System.out.println(num);
        int ans = 0;
        //boolean b = true;
        /*for(int i = 1; i < min + 1; i++){
            for(int j = 0;j < n; j++){
                if(a[j] % i != 0) b = false;
            }
            if(b) ans = Math.max(i, ans);
            b = true;
        }*/
        /*for(int i = 0; i < n; i++){
            for(int j = 1; j < num + 1; j++){
                for(int k = 0; k < n; k++){
                    if(k != i && a[k] % j != 0){
                        b = false;
                        break;
                    }
                }
                if(b) ans = Math.max(j, ans);
                b = true;
            }
        }*/
        int l = 0;
        for(int i = 0; i < n; i++){
            boolean flag = false;
            if(n == 2){
                ans = Math.max(a[0], a[1]);
                break;
            }
            if(i != 0 && i != 1){
                /*x = Math.max(a[0], a[1]);
                y = Math.min(a[0], a[1]);
                while ((tmp = x % y) != 0) {
                    x = y;
                    y = tmp;
                }
                l = y;*/
                l = gcd(a[0], a[1]);
                if(gcd(a[0], a[1]) == 1 && !flag){
                    flag = true;
                }
            }else if(i == 0){
                /*x = Math.max(a[2], a[1]);
                y = Math.min(a[2], a[1]);
                while ((tmp = x % y) != 0) {
                    x = y;
                    y = tmp;
                }
                l = y;*/
                l = gcd(a[2], a[1]);
                if(gcd(a[2], a[1]) == 1 && !flag){
                    flag = true;
                }
            }else if(i == 1){
                /*x = Math.max(a[0], a[2]);
                y = Math.min(a[0], a[2]);
                while ((tmp = x % y) != 0) {
                    x = y;
                    y = tmp;
                }
                l = y;*/
                l = gcd(a[0], a[2]);
                if(gcd(a[0], a[0]) == 1 && !flag){
                    flag = true;
                }
            }
            //for(int j = 2; j < n; j++){
            for(int j = 0; j < n; j++){
                if(i != j){
                    /*x = Math.max(l, a[j]);
                    y = Math.min(l, a[j]);
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    l = y;*/
                    l = gcd(l, a[j]);
                    if(gcd(a[0], a[1]) == 1 && !flag){
                        flag = true;
                    }else if(gcd(a[0], a[1]) == 1 && flag){
                        break;
                    }
                }
            }
            ans = Math.max(l, ans);
        }

        // 出力
        System.out.println(ans);

    }

}

Choices:
- Compile Error
- Internal error
- Runtime Error
- Memory Limit Exceeded


Question:
import java.util.*;

public class Main{

    public static void main(String args[]){

        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int n = sc.nextInt();
        int[] a = new int[n];
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
            min = Math.min(a[i], min);
        }
        int ans = 0;
        /*for(int i = 1; i < min + 1; i++){
            for(int j = 0;j < n; j++){
                if(a[j] % i != 0) b = false;
            }
            if(b) ans = Math.max(i, ans);
            b = true;
        }*/
        for(int i = 0; i < n; i++){
            for(int j = 1; j < min + 1; j++){
                for(int k = 0; k < n; k++){
                    if(k != i && a[k] % j != 0){
                        ans = Math.max(j, ans);
                        break;
                    }
                }
            }
        }

        // 出力
        System.out.println(ans);

    }

}

Choices:
- No abnormally found
- Runtime Error
- Time Limit Exceeded
- Internal error


Question:
import java.util.*;

public class Main{

    public static void main(String args[]){

        int[] num = new int[100];
        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int a = sc.nextInt();
        // スペース区切りの整数の入力
        int b = sc.nextInt();
        int k = sc.nextInt();
        int n = 0;
        for(int i = 1; i < Math.min(a, b); i++){
            if(a % i == 0 && b % i == 0){
                num[n] = i;
                n++;
            }
        }
        // 出力
        System.out.println(num[n - k]);

    }

}

Choices:
- No abnormally found
- Runtime Error
- Memory Limit Exceeded
- Compile Error


Question:
import java.util.*;
import java.io.PrintWriter;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int h = sc.nextInt();
        int w = sc.nextInt();

        // 問題:
        // 1. (H+1)*Wのboardがある
        // 2. 最初(0,0)(0,1)...(0,W)に人がいる
        // 3. 右or下に進める
        // 4. i行目には区間[L,R]の壁があり下には行けない

        // ans[i]: i行目に到達する人のうち、最小の歩数

        // map(now, from): 最初from列にいて、今now列にいる人らの集合
        SortedMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
        for (int i = 0; i < w; i++) {
            map.put(i, i);
        }

        // gaps: mapの(now-from)の集合
        TreeMap<Integer, Integer> gaps = new TreeMap<Integer, Integer>();
        for (Integer key : map.keySet()) {
            int val = map.get(key);
            int gap = key-val;

            int cnt = gaps.getOrDefault(gap, 0);
            gaps.put(gap, ++cnt);
        }

        for (int i = 1; i <= h; i++) {
            int L = sc.nextInt()-1;
            int R = sc.nextInt()-1;

            // submap: 壁で下に行けない人の集合(R+1列目のまっすぐ行ける人も含む)
            // (submapは区間[l,r)なので、[L,R+1]は[l,r+2))
            SortedMap<Integer, Integer> submap = map.subMap(L, R+2);

            // (次の行,R+1)に最小で行ける人は、submapの一番右の人なので、
            // それ以外は削除する
            if (!submap.isEmpty()) {
                int val = 0;
                int now_r = submap.lastKey();
                int from_r = submap.get(now_r);

                // gapsの削除
                for (Integer key : submap.keySet()) {
                    val = map.get(key);
                    int gap = key-val;

                    int cnt = gaps.get(gap);
                    if (cnt == 1) {
                        gaps.remove(gap);
                    } else {
                        gaps.put(gap, --cnt);
                    }
                }

                // mapの削除
                submap.clear();

                // map(now, from)のnowの更新
                now_r = R+1;
                if (now_r < w) {
                    map.put(now_r, from_r);
                }

                // gapsの追加
                if (now_r < w) {
                    val = gaps.getOrDefault(now_r - from_r, 0);
                    gaps.put(now_r - from_r, ++val);
                }
                // System.out.println(map.toString());
                // System.out.println(gaps.toString());
                // System.out.println(now-right);
            }

            // ans: 縦移動+横移動
            int ans = -1;
            if (!gaps.isEmpty()) {
                ans = i + gaps.firstKey();
            }
            out.println(ans);
        }
        out.flush();
    }
}

Choices:
- Memory Limit Exceeded
- No abnormally found
- Time Limit Exceeded
- Internal error


Question:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();

        // 問題:
        // 1. (H+1)*Wのboardがある
        // 2. 最初(0,0)(0,1)...(0,W)に人がいる
        // 3. 右or下に進める
        // 4. i行目には区間[L,R]の壁があり下には行けない

        // ans[i]: i行目に到達する人のうち、最小の歩数

        // map(now, from): 最初from列にいて、今now列にいる人らの集合
        SortedMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
        for (int i = 0; i < w; i++) {
            map.put(i, i);
        }

        // gaps: mapの(now-from)の集合
        TreeMap<Integer, Integer> gaps = new TreeMap<Integer, Integer>();
        for (Integer key : map.keySet()) {
            int val = map.get(key);
            int gap = key-val;

            int cnt = gaps.getOrDefault(gap, 0);
            gaps.put(gap, ++cnt);
        }

        for (int i = 1; i <= h; i++) {
            int L = sc.nextInt()-1;
            int R = sc.nextInt()-1;

            // submap: 壁で下に行けない人の集合(R+1列目のまっすぐ行ける人も含む)
            // (submapは区間[l,r)なので、[L,R+1]は[l,r+2))
            SortedMap<Integer, Integer> submap = map.subMap(L, R+2);

            // (次の行,R+1)に最小で行ける人は、submapの一番右の人なので、
            // それ以外は削除する
            if (!submap.isEmpty()) {
                int val = 0;
                int now_r = submap.lastKey();
                int from_r = submap.get(now_r);

                // gapsの削除
                for (Integer key : submap.keySet()) {
                    val = map.get(key);
                    int gap = key-val;

                    int cnt = gaps.get(gap);
                    if (cnt == 1) {
                        gaps.remove(gap);
                    } else {
                        gaps.put(gap, --cnt);
                    }
                }

                // mapの削除
                submap.clear();

                // map(now, from)のnowの更新
                now_r = R+1;
                if (now_r < w) {
                    map.put(now_r, from_r);
                }

                // gapsの追加
                if (now_r < w) {
                    val = gaps.getOrDefault(now_r - from_r, 0);
                    gaps.put(now_r - from_r, ++val);
                }
                // System.out.println(map.toString());
                // System.out.println(gaps.toString());
                // System.out.println(now-right);
            }

            // ans: 縦移動+横移動
            int ans = -1;
            if (!gaps.isEmpty()) {
                ans = i + gaps.firstKey();
            }
            System.out.println(ans);
        }
    }
}

Choices:
- Time Limit Exceeded
- Internal error
- Runtime Error
- Memory Limit Exceeded


Question:
import java.util.*;

public class Main {
    static long MOD = 998244353;

    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int s = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        // ans: f(T)の全パターンの和
        // f(T): 集合Tの部分集合であって、和がsになるパターン数
        long ans = 0;

        // ans: [x^s] (f{1}+f{2}+f{3}+f{1,2}+f{1,3}+f{2,3}+f{1,2,3})
        // ex. f{1,2,3}: f1f2f3
        // ex. f{1,2}: f1f2
        // (空集合は含まないので-1すべきだが、s>=1なので-1は無視してOK)

        // ex. n = 3, s = 4, array[] = {2, 2, 4}
        // -> f{3}に1個、f{1,2}に1個、f{1,3}に1個、f{2,3}に1個、f{1,2,3}に2個 -> ans = 6
        // F1: f1
        // F2: F1f2 + f2 = f1f2 + f2
        // F3: F1~2f3 + f3 = f1f3 + f1f2f3 + f2f3 + f3
        // Fn: F1~n-1fn + fn
        // -> ans: [x^s] (F1 + F2 + ... + Fn)

        // dp[i][s]: [x^s] (Fi)
        long[][] dp = new long[n+1][s+1];
        for (int i = 0; i < n; i++) {
            int offset = array[i];

            // Fi+1 = F1~ifi + fi

            // F1~i
            long[] sum = new long[s+1];
            for (int j = 0; j < i+1; j++) {
                for (int k = 0; k <= s; k++) {
                    sum[k] += dp[j][k];
                }
            }

            // F1~ifi (選ぶ)
            for (int j = s; j - offset >= 0; j--) {
                dp[i+1][j] += sum[j-offset];
                dp[i+1][j] %= MOD;
            }
            // F1~ifi (選ばない)
            for (int j = 0; j <= s; j++) {
                dp[i+1][j] += sum[j];
                dp[i+1][j] %= MOD;
            }

            // fi (選ぶ)
            if (offset <= s) {
                dp[i+1][offset]++;
                dp[i+1][offset] %= MOD;
            }
            // fi (選ばない)
            dp[i+1][0]++;
            dp[i+1][0] %= MOD;

            ans += dp[i+1][s];
            ans %= MOD;
        }
        // for (int i = 0; i <= n; i++) {
            // System.out.println(Arrays.toString(dp[i]));
        // }

        System.out.println(ans);
    }
}

Choices:
- Runtime Error
- No abnormally found
- Compile Error
- Time Limit Exceeded


Question:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        String str = sc.next();
        char array[] = str.toCharArray();

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

        int idx = n;
        int k = 0;
        while (true) {
            boolean ok = false;
            for (int j = idx - m; j <= idx; j++) {
                if (j < 0) continue;
                if (array[j] == '0') {
                    ans.add(idx - j);
                    idx = j;
                    k++;
                    ok = true;
                    break;
                }
            }

            if (idx == 0) break;

            if (!ok) {
                System.out.println(-1);
                return;
            }
        }

        for (int i = k - 1; i >= 0; i--) {
            System.out.print(ans.get(i));

            if (i != 0) {
                System.out.print(" ");
            } else {
                System.out.println();
            }
        }
    }
}

Choices:
- Internal error
- Time Limit Exceeded
- Runtime Error
- Compile Error


Question:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = n;
        int w = n;

        // board[i][j]: 迷路
        char[][] board = new char[h][w];
        for (int i = 0; i < h; i++) {
            String str = sc.next();
            for (int j = 0; j < w; j++) {
                board[i][j] = str.charAt(j);
            }
        }

        // to: 隣接リスト
        List<Integer>[] to = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (board[i][j] == '1') {
                    to[i].add(j);
                    to[j].add(i);
                }
            }
        }

        int ans = 0;
        for (int i = 0; i < n; i++) {
            // visited: 当該点を既に通ったか否か
            boolean[] visited = new boolean[n];
            visited[i] = true;

            // max: iから最も遠い点との距離
            int max = 0;
            int[] dist = new int[n];
            // 頂点0から順に、親から子へ初期値を配り最終値を求める
            Queue<int[]> que = new ArrayDeque<int[]>();
            que.add(new int[]{i, 0});
            while (!que.isEmpty()) {
                int[] cur = que.poll();
                int p = cur[0];
                int dis = cur[1];

                visited[p] = true;
                for (Integer q : to[p]) {
                    if (visited[q]) continue;

                    if (dist[q] != 0 && dist[q] != dis + 1) {
                        System.out.println(-1);
                        return;
                    }

                    dist[q] = dis + 1;
                    que.add(new int[]{q, dist[q]});
                    max = Math.max(max, dist[q]);
                }
            }

            ans = Math.max(ans, max);
        }

        System.out.println(ans+1);
    }
}

Choices:
- Time Limit Exceeded
- Compile Error
- No abnormally found
- Runtime Error


Question:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] array = new int[m][13];

        for (int i = 0; i < m; i++) {
            array[i][0] = sc.nextInt();

            int k = sc.nextInt();
            for (int j = 0; j < k; j++) {
                array[i][sc.nextInt()] = 1;
            }
        }
        Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));

        long cost = 0;
        boolean[] ok = new boolean[13];
        for (int i = 1; i <= 12; i++) {
            if (ok[i]) continue;

            for (int j = 0; j < m; j++) {
                if (array[j][i] == 1) {
                    cost += array[j][0];
                    for (int l = 1; l <= 12; l++) {
                        if (array[j][l] == 1) {
                            ok[l] = true;
                        }
                    }
                    break;
                }
            }
        }

        for (int i = 1; i <= 12; i++) {
            if (!ok) {
                System.out.println(-1);
                return;
            }
        }

        System.out.println(cost);
    }
}

Choices:
- Runtime Error
- Compile Error
- Time Limit Exceeded
- Memory Limit Exceeded


Question:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String str = sc.next();
        char c[] = str.toCharArray();
        char dir = c[0];

        int begin = -1;
        int end = -1;
        int flag = 0;
        for (int i = 0; i < n; i++) {
            if (dir != c[i]) {
                if (flag == 0) {
                    begin = i;
                    if (dir == 'L') {
                        dir = 'R';
                    } else {
                        dir = 'L';
                    }
                    flag = 1;
                } else {
                    end = i;
                    dir = c[i];
                    for (int j = begin; j < end; j++) {
                        c[j] = dir;
                    }
                    begin = i;
                    end = -1;
                    k--;
                    flag = 0;
                }
            }

            if (k == 0) {
                break;
            }
        }

        if (k > 0) {
            if (dir == 'L') {
                dir = 'R';
            } else {
                dir = 'L';
            }

            for (int i = begin; i < n; i++) {
                c[i] = dir;
            }
        }

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (c[i] == 'L') {
                if (i == 0) continue;
                if (c[i - 1] == c[i]) {
                    count++;
                }
            } else {
                if (i == n - 1) continue;
                if (c[i + 1] == c[i]) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
}

Choices:
- Compile Error
- Internal error
- No abnormally found
- Runtime Error


Question:
import java.util.*;

public class Main {
    static int INF = 1001001009;

    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int start = 0;
        int goal = n - 1;

        // ans: 点0から点Nに行くまでの最小コスト

        // to: 隣接リスト(有向)(自己ループ有)
        // rto: 逆向きの矢印
        List<int[]>[] to = new List[n];
        List<Integer>[] rto = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<int[]>();
            rto[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < m; i++) {
            int p = sc.nextInt() - 1;
            int q = sc.nextInt() - 1;
            int dis = sc.nextInt();
            dis = -(dis - k);

            to[p].add(new int[]{q, dis});
            rto[q].add(p);
        }

        // ベルマンフォード法: 負の辺も行ける最短経路問題の解法
        // (特定の2点間の最短距離だけを求められる)
        // (startから各点までだとTLE)

        // froms: startから行ける点か否か
        boolean[] froms = new boolean[n];
        Queue<Integer> que = new ArrayDeque<Integer>();
        que.add(start);
        while (!que.isEmpty()) {
            int p = que.poll();

            // 出現1回目のpだけに配らせる
            if (froms[p]) continue;
            froms[p] = true;

            // fromsであると知らなかった点だけキューに入れる
            for (Integer q : to[p]) {
                if (!froms[q]) {
                    que.add(q);
                }
            }
        }

        // tog: goalへ行ける点か否か
        boolean[] tog = new boolean[n];
        que = new ArrayDeque<Integer>();
        que.add(goal);
        while (!que.isEmpty()) {
            int p = que.poll();

            // 出現1回目のpだけに配らせる
            if (tog[p]) continue;
            tog[p] = true;

            // togであると知らなかった点だけキューに入れる
            for (Integer q : rto[p]) {
                if (!tog[q]) {
                    que.add(q);
                }
            }
        }

        // dist: startからの最短距離
        int[] dist = new int[n];
        Arrays.fill(dist, INF);
        dist[start] = 0;

        // 頂点数-1回のループを回せば2点間の最短距離が確定する
        // (負の閉路から行ける頂点以外は除く)
        boolean negativeLoop = false;
        for (int i = 0; i < n; i++) {
            for (int p = 0; p < n; p++) {
                // start-goal上にない点は無視
                if (!froms[p]) continue;
                if (!tog[p]) continue;

                for (int[] qData : to[p]) {
                    int q = qData[0];
                    int PtoQ = qData[1];

                    // 最短距離が更新されるか？
                    if (dist[p] + PtoQ < dist[q]) {
                        // System.out.println(p + " " + q);
                        dist[q] = dist[p] + PtoQ;

                        // n回目でも更新される点があれば
                        // 道中に必ず負の閉路がある
                        if (i == n - 1) {
                            negativeLoop = true;
                        }
                    }
                }
            }
        }

        // System.out.println(Arrays.toString(dist));

        if (negativeLoop) {
            System.out.println(-1);
        } else {
            if (-dist[goal] < 0) {
                System.out.println(0);
            } else {
                System.out.println(-dist[goal]);
            }
        }
    }
}

Choices:
- Memory Limit Exceeded
- Runtime Error
- Compile Error
- No abnormally found


Question:
import java.util.*;

public class Main {
    static int INF = 1001001009;

    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int start = 0;
        int goal = n - 1;

        // ans:

        // to: 隣接リスト(有向)(自己ループ有)
        // rto: 逆向きの矢印
        List<int[]>[] to = new List[n];
        List<Integer>[] rto = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<int[]>();
            rto[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < m; i++) {
            int p = sc.nextInt() - 1;
            int q = sc.nextInt() - 1;
            int dis = sc.nextInt();
            dis = -(dis - k);

            to[p].add(new int[]{q, dis});
            rto[q].add(p);
        }

        // dist: startからの最短距離
        int[] dist = new int[n];
        Arrays.fill(dist, INF);
        dist[start] = 0;

        // ベルマンフォード法: 負の辺も行ける最短経路問題の解法
        // (特定の2点間の最短距離だけを求められる)
        // (startから各点までだとTLE)

        // froms: startから行ける点か否か
        // finished: 既にpから配ったか否か
        boolean[] froms = new boolean[n];
        boolean[] finished = new boolean[n];
        Queue<Integer> que = new ArrayDeque<Integer>();
        que.add(start);
        while (!que.isEmpty()) {
            int p = que.poll();
            if (finished[p]) continue;

            froms[p] = true;
            for (int[] qData : to[p]) {
                int q = qData[0];
                if (!froms[q]) {
                    que.add(q);
                }
            }
            finished[p] = true;
        }
        // tog: goalへ行ける点か否か
        boolean[] tog = new boolean[n];
        visited = new boolean[n];
        que = new ArrayDeque<Integer>();
        que.add(goal);
        while (!que.isEmpty()) {
            int p = que.poll();
            if (tog[p]) continue;
            tog[p] = true;

            for (Integer q : rto[p]) {
                if (!tog[q]) {
                    que.add(q);
                }
            }
        }

        // 頂点数-1回のループを回せば最短距離が確定する
        // (負の閉路から行ける頂点以外は除く)
        boolean negativeLoop = false;
        for (int i = 0; i < n; i++) {
            for (int p = 0; p < n; p++) {
                // start-goal上にない点は無視
                if (!froms[p]) continue;
                if (!tog[p]) continue;

                for (int[] qData : to[p]) {
                    int q = qData[0];
                    int PtoQ = qData[1];

                    // 最短距離が更新されるか？
                    if (dist[p] + PtoQ < dist[q]) {
                        // System.out.println(p + " " + q);
                        dist[q] = dist[p] + PtoQ;

                        // n回目でも更新される点があれば
                        // 道中に必ず負の閉路がある
                        if (i == n - 1) {
                            negativeLoop = true;
                        }
                    }
                }
            }
        }

        // System.out.println(Arrays.toString(dist));

        if (negativeLoop) {
            System.out.println(-1);
        } else {
            if (-dist[goal] < 0) {
                System.out.println(0);
            } else {
                System.out.println(-dist[goal]);
            }
        }
    }
}

Choices:
- Internal error
- Runtime Error
- Compile Error
- No abnormally found


Question:
import java.util.*;

public class Main {
    static int INF = 1001001009;

    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int start = 0;
        int goal = n - 1;

        // ans:

        // to: 隣接リスト(有向)(自己ループ有)
        // rto: 逆向きの矢印
        List<int[]>[] to = new List[n];
        List<Integer>[] rto = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<int[]>();
            rto[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < m; i++) {
            int p = sc.nextInt() - 1;
            int q = sc.nextInt() - 1;
            int dis = sc.nextInt();
            dis = -(dis - k);

            to[p].add(new int[]{q, dis});
            rto[q].add(p);
        }

        // dist: startからの最短距離
        int[] dist = new int[n];
        Arrays.fill(dist, INF);
        dist[start] = 0;

        // ベルマンフォード法: 負の辺も行ける最短経路問題の解法
        // (特定の2点間の最短距離だけを求められる)
        // (startから各点までだとTLE)

        // froms: startから行ける点か否か
        boolean[] froms = new boolean[n];
        Queue<Integer> que = new ArrayDeque<Integer>();
        que.add(start);
        while (!que.isEmpty()) {
            int p = que.poll();
            froms[p] = true;

            for (int[] qData : to[p]) {
                int q = qData[0];
                if (!froms[q]) {
                    que.add(q);
                }
            }
        }
        // tog: goalへ行ける点か否か
        boolean[] tog = new boolean[n];
        que = new ArrayDeque<Integer>();
        que.add(goal);
        while (!que.isEmpty()) {
            int p = que.poll();
            tog[p] = true;

            for (Integer q : rto[p]) {
                if (!tog[q]) {
                    que.add(q);
                }
            }
        }

        // 頂点数-1回のループを回せば最短距離が確定する
        // (負の閉路から行ける頂点以外は除く)
        boolean negativeLoop = false;
        for (int i = 0; i < n; i++) {
            for (int p = 0; p < n; p++) {
                // startから行けない点は無視(INFのまま)
                if (!froms[p]) continue;
                if (!tog[p]) continue;

                for (int[] qData : to[p]) {
                    int q = qData[0];
                    int PtoQ = qData[1];

                    // 最短距離が更新されるか？
                    if (dist[p] + PtoQ < dist[q]) {
                        // System.out.println(p + " " + q);
                        dist[q] = dist[p] + PtoQ;

                        // n回目でも更新される点があれば
                        // 道中に必ず負の閉路がある
                        if (i == n - 1) {
                            negativeLoop = true;
                        }
                    }
                }
            }
        }

        // System.out.println(Arrays.toString(dist));

        if (negativeLoop) {
            System.out.println(-1);
        } else {
            if (-dist[goal] < 0) {
                System.out.println(0);
            } else {
                System.out.println(-dist[goal]);
            }
        }
    }
}

Choices:
- Time Limit Exceeded
- Compile Error
- Runtime Error
- No abnormally found


Question:
import java.util.*;

public class Main {
    static int INF = 1001001009;

    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int start = 0;
        int goal = n - 1;

        // ans:

        // to: 隣接リスト(有向)(自己ループ有)
        // rto: 逆向きの矢印
        List<int[]>[] to = new List[n];
        List<Integer>[] rto = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<int[]>();
            rto[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < m; i++) {
            int p = sc.nextInt() - 1;
            int q = sc.nextInt() - 1;
            int dis = sc.nextInt();
            dis = -(dis - k);

            to[p].add(new int[]{q, dis});
            rto[q].add(p);
        }

        // dist: startからの最短距離
        int[] dist = new int[n];
        Arrays.fill(dist, INF);
        dist[start] = 0;

        // ベルマンフォード法: 負の辺も行ける最短経路問題の解法

        // froms: startから行ける点か否か
        boolean[] froms = new boolean[n];
        Queue<Integer> que = new ArrayDeque<Integer>();
        que.add(start);
        while (!que.isEmpty()) {
            int p = que.poll();
            froms[p] = true;

            for (int[] qData : to[p]) {
                int q = qData[0];
                if (!froms[q]) {
                    que.add(q);
                }
            }
        }
        // tog: goalへ行ける点か否か
        boolean[] tog = new boolean[n];
        que = new ArrayDeque<Integer>();
        que.add(goal);
        while (!que.isEmpty()) {
            int p = que.poll();
            tog[p] = true;

            for (Integer q : rto[p]) {
                if (!tog[q]) {
                    que.add(q);
                }
            }
        }

        // 頂点数-1回のループを回せば最短距離が確定する
        // (負の閉路から行ける頂点以外は除く)
        for (int i = 0; i < n; i++) {
            for (int p = 0; p < n; p++) {
                // startから行けない点は無視(INFのまま)
                if (!froms[p]) continue;
                if (!tog[p]) continue;

                for (int[] qData : to[p]) {
                    int q = qData[0];
                    int PtoQ = qData[1];

                    // 最短距離が更新されるか？
                    if (dist[p] + PtoQ < dist[q]) {
                        // System.out.println(p + " " + q);
                        dist[q] = dist[p] + PtoQ;

                        // n回目でも更新される点は無限に最短距離が減るのでメモする
                        if (i == n - 1) {
                            dist[q] = -INF;
                            // System.out.println(q);
                        }
                    }
                }
            }
        }
        // startから負の閉路を経て、行ける頂点は全て-INFである
        for (int i = 0; i < n; i++) {
            int count = 0;
            for (int p = 0; p < n; p++) {
                if (!froms[p]) continue;
                if (!tog[p]) continue;

                if (dist[p] == -INF) {
                    for (int[] qData : to[p]) {
                        int q = qData[0];
                        dist[q] = -INF;
                    }
                }
            }
        }

        // System.out.println(Arrays.toString(dist));

        if (dist[goal] == -INF) {
            System.out.println(-1);
        } else {
            if (-dist[goal] < 0) {
                System.out.println(0);
            } else {
                System.out.println(-dist[goal]);
            }
        }
    }
}

Choices:
- Memory Limit Exceeded
- Time Limit Exceeded
- Internal error
- No abnormally found


Question:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        // ans: dequeue(array)において次の3種類の操作をk回までできる時の最大価値
        // 操作A: 左端から1個取り出す
        // 操作B: 右端から1個取り出す
        // 操作C: 手持ちから1個捨てる
        int ans = 0;

        // 左からi個右からj個取るパターンを全探索する
        for (int i = 0; i <= k; i++) {
            for (int j = 0; j <= k - i; j++) {
                PriorityQueue<Integer> que = new PriorityQueue<>();

                // 操作A
                for (int x = 0; x < i; x++) {
                    que.add(array[x]);
                }
                // 操作B
                for (int x = n - 1; x > n - 1 - j; x--) {
                    que.add(array[x]);
                }
                // 操作C
                for (int x = 0; x < k - i - j; x++) {
                    if (que.isEmpty()) break;
                    int num = que.peek();
                    if (num <= 0) {
                        que.poll();
                    }
                }

                int sum = 0;
                while (!que.isEmpty()) {
                    sum += que.poll();
                }

                ans = Math.max(ans, sum);
            }
        }
        System.out.println(ans);
    }
}

Choices:
- Runtime Error
- Memory Limit Exceeded
- Time Limit Exceeded
- Internal error


Question:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();

        int[] cumsum = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        }

        while (q-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];

            System.out.println(count);
        }
    }
}

Choices:
- No abnormally found
- Memory Limit Exceeded
- Runtime Error
- Compile Error


Question:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long start = sc.nextLong();
        long end = sc.nextLong();
        long num;
        if (end - start == 1) {
            num = start ^ end;
        } else if (end - start == 0) {
            num = start;
        } else {
            num = start ^ (start + 1);
            for (long i = start + 2; i <= end; i++) {
                num = num ^ i;
            }
        }

        System.out.println(num);
    }
}

Choices:
- Time Limit Exceeded
- Internal error
- Compile Error
- No abnormally found


Question:
import java.util.*;
import java.util.Map.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int currentPosition = sc.nextInt();

        TreeSet<Integer> numSet = new TreeSet<Integer>();
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            numSet.add(num);
        }

        int p = -1;
        if (numSet.size() > 1) {
            int a = numSet.floor(currentPosition);
            int b = numSet.ceiling(currentPosition);
            if (Math.abs(currentPosition - a) < Math.abs(currentPosition - b)) {
                p = a;
            } else {
                p = b;
            }
        } else {
            for (Integer num : numSet) {
                p = num;
            }
        }

        int d = Math.abs(currentPosition - p);
        int answer = 1;
        for (int i = 1; i < d; i++) {
            boolean end = true;
            if (d % i != 0) continue;
            int length = d / i;

            for (Integer num : numSet) {
                if ((num - currentPosition) % length != 0) {
                    end = false;
                    break;
                }
            }

            if (end) {
                answer = length;
                break;
            }
        }

        System.out.println(answer);
    }
}

Choices:
- Runtime Error
- Time Limit Exceeded
- Internal error
- Memory Limit Exceeded


Question:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] array = new int[n][2];

        for (int i = 0; i < n; i++) {
            array[i][1] = 1;
        }
        for (int i = 0; i < n; i++) {
            array[i][0] = sc.nextInt();
            for (int j = 0; j < i; j++) {
                if (array[j][0] + 1 == array[i][0]) {
                    array[j][1]++;
                    array[j][0]++;
                }
            }
        }

        int max = 0;
        for (int[] a : array) {
            max = Math.max(max, a[1]);
        }

        System.out.println(n - max);
    }
}

Choices:
- Internal error
- Runtime Error
- Memory Limit Exceeded
- Time Limit Exceeded


Question:
import java.util.*;

public class Main{

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

        int n = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        int ans = Math.min(a+(b-a)/2, n-b+1+(b-a)/2);
        if((b-a)%2==0){
            ans = (b-a)/2;
        }

        System.out.println(ans);
    }
}

Choices:
- Memory Limit Exceeded
- Runtime Error
- Internal error
- No abnormally found


Question:
import java.util.*;

public class Main{
    static int n;
    static long m;
    static int v;
    static int p;
    static long[] a;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        n = Integer.parseInt(sc.next());
        m = Long.parseLong(sc.next());
        v = Integer.parseInt(sc.next());
        p = Integer.parseInt(sc.next());
        a = new long[n];
        for(int i=0; i<n; i++){
            a[i] = Long.parseLong(sc.next());
        }

        Arrays.sort(a);
        //reverse
        for(int i=0; i<n/2; i++){
            long tmp = a[n-i-1];
            a[n-i-1] = a[i];
            a[i] = tmp;
        }

        int ok = 0;
        int ng = n;
        for(int i=0; i<20; i++){
            int mid = (ok+ng)/2;
            if(check(mid)){
                ok = mid;
            }else{
                ng = mid;
            }
        }

        System.out.println(ok+1);
    }

    public static boolean check(int x){
        if(a[x]+m < a[p-1]){
            return false;d
        }
        long sum = 0;
        for(int i=0; i<n; i++){
            if(i<p-1 || x<=i){
                sum+=m;
            }else{
                sum+=Math.max(a[x]+m-a[i], 0);
            }
        }

        return sum >= m*v;
    }
}

Choices:
- Memory Limit Exceeded
- Time Limit Exceeded
- Compile Error
- No abnormally found


Question:
import java.util.*;

public class Main{

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

        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());

        int[] v = new int[n+1];
        for(int i=0; i<n; i++){
            v[i] = Integer.parseInt(sc.next());
        }

        PriorityQueue<Integer> q = new PriorityQueue<>();
        int max = 0;
        //左から取り出す回数i
        for(int i=0; i<=k; i++){
            int lsum = 0;
            q.clear();
            q.add(0);
            for(int j=0; j<i; j++){
                q.add(v[j]);
                lsum += v[j];
            }

            {
                //捨てる前に更新
                max = Math.max(max, lsum);
                //左のみ、捨てれるだけ捨ててみる
                //捨てれるだけ捨ててみる
                int l = 0;
                int xsum = lsum;
                for(int tmp : q){
                    if(l>=k-i){
                        break;
                    }
                    xsum -= tmp;
                    l++;
                    max = Math.max(max, xsum);
                }
            }

            //右から取り出す個数
            for(int j=0; j<=k-i; j++){
                int rsum = 0;
                q.add(v[n-j]);
                for(int l=0; l<=j; l++){
                    rsum += v[n-l];
                }

                //捨てる前に更新
                max = Math.max(max, lsum+rsum);

                //捨てれるだけ捨ててみる
                int l = 0;
                for(int tmp : q){
                    if(l>=k-i-j){
                        break;
                    }
                    rsum -= tmp;
                    l++;
                    max = Math.max(max, lsum+rsum);
                }
            }
        }

        System.out.println(max);

    }
}

Choices:
- Internal error
- Time Limit Exceeded
- No abnormally found
- Runtime Error


Question:
import java.util.*;

public class Main{

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

        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());

        int[] v = new int[n+1];
        for(int i=0; i<n; i++){
            v[i] = Integer.parseInt(sc.next());
        }

        PriorityQueue<Integer> q = new PriorityQueue<>();
        int max = 0;
        //左から取り出す回数i
        for(int i=0; i<=k; i++){
            int lsum = 0;
            q.clear();
            q.add(0);
            for(int j=0; j<i; j++){
                q.add(v[j]);
                lsum += v[j];
            }

            //左のみ
            max = Math.max(max, lsum);

            {
                //左のみ、捨てれるだけ捨ててみる
                //捨てれるだけ捨ててみる
                int l = 0;
                int xsum = lsum;
                for(int tmp : q){
                    if(l>=k-i){
                        break;
                    }
                    xsum -= tmp;
                    l++;
                    max = Math.max(max, xsum);
                }
            }

            //右から取り出す個数
            for(int j=0; j<k-i; j++){
                int rsum = 0;
                q.add(v[n-j]);
                for(int l=0; l<=j; l++){
                    rsum += v[n-l];
                }

                //捨てれるだけ捨ててみる
                int l = 0;
                for(int tmp : q){
                    if(l>=k-i-j){
                        break;
                    }
                    rsum -= tmp;
                    l++;
                    max = Math.max(max, lsum+rsum);
                }
            }
        }

        System.out.println(max);

    }
}

Choices:
- Compile Error
- Memory Limit Exceeded
- Time Limit Exceeded
- Runtime Error


Question:
import java.util.*;

public class Main{

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

        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());

        int[] v = new int[n+1];
        for(int i=0; i<n; i++){
            v[i] = Integer.parseInt(sc.next());
        }

        PriorityQueue<Integer> q = new PriorityQueue<>();
        int max = 0;
        //左から取り出す回数i
        for(int i=0; i<=k; i++){
            int lsum = 0;
            q.clear();
            q.add(0);
            for(int j=0; j<i; j++){
                q.add(v[j]);
                lsum += v[j];
            }

            //左のみ
            max = Math.max(max, lsum);
            //System.out.println("左のみ" + lsum);

            //右から取り出す個数
            for(int j=0; j<k-i; j++){
                int rsum = 0;
                q.add(v[n-j]);
                for(int l=0; l<=j; l++){
                    rsum += v[n-l];
                }
                //System.out.println("合計" + (rsum) );

                //捨てれるだけ捨ててみる
                int l = 0;
                for(int tmp : q){
                    if(l>=k-i-j){
                        break;
                    }

                    //System.out.println("合計" + (rsum-tmp) );
                    //System.out.println("いらない " + tmp);
                    rsum -= tmp;
                    l++;
                    max = Math.max(max, lsum+rsum);
                }
            }
        }

        System.out.println(max);

    }
}

Choices:
- Time Limit Exceeded
- Internal error
- Compile Error
- Runtime Error


Question:
import java.util.*;

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        int mod = 1_000_000_007;

        //約数
        ArrayList<Integer> mfac = new ArrayList<>();

        for(int i=1; i*i<=m; i++){
            if(m%i==0){
                mfac.add(i);
                if(i*i!=m){
                    mfac.add(m/i);
                }
            }
        }

        int[] f = mfac.stream().mapToInt((Integer i)->i).toArray();
        Arrays.sort(f);

        //
        for(int i=0; i<f.length; i++){
            //System.out.println(f[i]);
        }
        //

        //DPする
        long[][] dp = new long[2][f.length];
        dp[0][0] = 1L;

        for(int i=0; i<n; i++){
            for(int j=0; j<f.length; j++){
                //System.out.println("j"+j);
                for(int k=0; k<f.length; k++){
                    int idx = bs(f, f[j]*f[k]);
                    //System.out.println(idx);
                    if(f.length <= idx) continue;
                    dp[1][idx] += dp[0][k];
                    dp[1][idx] %= mod;
                }
                /*
                for(int k=0; k<dp[0].length; k++){
                    System.out.println("i:" + k +"   val:" + dp[1][k]);
                }
                */
            }
            for(int j=0; j<f.length; j++){
                dp[0][j] = dp[1][j]%mod;
                dp[1][j] = 0;
            }
        }

        /*
        for(int i=0; i<dp[0].length; i++){
            System.out.println("i:" + i +"   val:" + dp[0][i]);
        }*/

        System.out.println(dp[0][dp[0].length-1]);

    }

    public static int bs(int[] f, int key){
        int result = Arrays.binarySearch(f, key);
        int idx = (result >= 0) ? result : 1_000_000_000;
        return idx;
    }
}

Choices:
- Memory Limit Exceeded
- Compile Error
- No abnormally found
- Time Limit Exceeded


Question:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.SortedMap;
import java.util.StringTokenizer;
import java.util.TreeMap;

public final class F {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int h = fs.nextInt();
        final int w = fs.nextInt();
        final int[] a = new int[h];
        final int[] b = new int[h];
        for (int i = 0; i < h; i++) {
            a[i] = fs.nextInt() - 1;
            b[i] = fs.nextInt();
        }
        final SortedMap<Integer, Integer> currToOrigin = new TreeMap<>();
        for (int i = 0; i < w; i++) {
            currToOrigin.put(i, i);
        }
        final int[] gaps = new int[w];
        final int[] results = new int[h];
        gaps[0] = w;
        Arrays.fill(results, -1);
        int minGapIndex = 0, maxGapIndex = 0;
        for (int i = 0; (i < h) && !currToOrigin.isEmpty(); i++) {
            final SortedMap<Integer, Integer> subMap = currToOrigin.subMap(a[i], b[i]);
            if (!subMap.isEmpty()) {
                final int maxOrigin = subMap.get(subMap.lastKey());
                subMap.forEach((key, value) -> gaps[key - value]--);
                subMap.clear();
                if ((b[i] < w) && !currToOrigin.containsKey(b[i])) {
                    currToOrigin.put(b[i], maxOrigin);
                    gaps[b[i] - maxOrigin]++;
                    maxGapIndex = Math.max(maxGapIndex, b[i] - maxOrigin);
                }
                while ((minGapIndex <= maxGapIndex) && (0 == gaps[minGapIndex])) {
                    minGapIndex++;
                }
            }
            results[i] = (minGapIndex <= maxGapIndex) ? minGapIndex + i + 1 : -1;
        }
        Arrays.stream(results).forEach(System.out::println);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

Choices:
- Internal error
- Time Limit Exceeded
- Compile Error
- Memory Limit Exceeded


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class B {

    private static final int MOD = 998244353;

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int a = in.nextInt();
        final int b = in.nextInt();
        final int c = in.nextInt();
        final int d = in.nextInt();
        System.out.println(dfs(a, b, c, d, new Integer[c + 1][d + 1]));
    }

    private static int dfs(int a, int b, int c, int d, Integer[][] dp) {
        if (a == c && b == d) {
            return 1;
        }
        if (dp[a][b] != null) {
            return dp[a][b];
        }
        int res = 0;
        if (a < c) {
            res += Math.floorMod(b * dfs(a + 1, b, c, d, dp), MOD);
        }
        if (b < d) {
            res = (res + Math.floorMod(a * dfs(a, b + 1, c, d, dp), MOD)) % MOD;
        }
        if (a < c && b < d) {
            res -= Math.floorMod(a * b * dfs(a + 1, b + 1, c, d, dp), MOD);
            if (res < 0) {
                res += MOD;
            }
        }
        return dp[a][b] = Math.floorMod(res, MOD);
    }
}

Choices:
- Memory Limit Exceeded
- Internal error
- Runtime Error
- Compile Error


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class C {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final String[] line = in.nextLine().split(" ");
        final int n = Integer.parseInt(line[0]);
        final int k = Integer.parseInt(line[1]);
        for (int i = 0; i < n; i++) {
            in.nextInt();
        }
        in.nextLine();
        System.out.println(Math.ceil((double) (n - 1) / (k - 1)));
    }
}

Choices:
- No abnormally found
- Compile Error
- Time Limit Exceeded
- Memory Limit Exceeded


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class C {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final String[] line = in.nextLine().split(" ");
        final int n = Integer.parseInt(line[0]);
        final int k = Integer.parseInt(line[1]);
        for (int i = 0; i < n; i++) {
            in.nextInt();
        }
        in.nextLine();
        System.out.println((n - 1) / (k - 1));
    }
}

Choices:
- Compile Error
- Runtime Error
- Internal error
- Time Limit Exceeded


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class D {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final long n = Long.parseLong(in.nextLine());
        long k = 0, kk = 1;
        for (int i = 0; i < n; i++) {
            if ((k / kk) % 10 == 9 && f(k + kk) > f(k + 10 * kk)) {
                kk *= 10;
            }
            k += kk;
            System.out.println(k);
        }
    }

    private static double f(long num) {
        long copy = num;
        long sum = 0;
        while (copy > 0) {
            sum += copy % 10;
            copy /= 10;
        }
        return (double) num / sum;
    }
}

Choices:
- Compile Error
- No abnormally found
- Time Limit Exceeded
- Internal error


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int n2 = n * n;
		int[] p = new int[n2];
		sa = br.readLine().split(" ");
		for (int i = 0; i < n2; i++) {
			p[i] = Integer.parseInt(sa[i]) - 1;
		}
		br.close();

		int[][] a = new int[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(a[i], 1);
		}

		int[] dx = {-1, 1, 0, 0};
		int[] dy = {0, 0, -1, 1};
		int ans = 0;
		for (int i = 0; i < n2; i++) {
			int[][] d = new int[n][n];
			for (int j = 0; j < n; j++) {
				Arrays.fill(d[j], 512);
			}
			int x = p[i] / n;
			int y = p[i] % n;
			d[x][y] = 0;
			a[x][y] = 0;
			Deque<Integer> que = new ArrayDeque<>();
			que.add(p[i]);
			label:
			while (!que.isEmpty()) {
				int cur = que.poll();
				int cx = cur / n;
				int cy = cur % n;
				for (int k = 0; k < 4; k++) {
					int nx = cx + dx[k];
					int ny = cy + dy[k];
					if (0 <= nx && nx < n && 0 <= ny && ny < n) {
						int alt = d[cx][cy] + a[nx][ny];
						if (alt < d[nx][ny]) {
							if (alt == d[cx][cy]) {
								que.addFirst(nx * n + ny);
							} else {
								que.addLast(nx * n + ny);
							}
							d[nx][ny] = alt;
						}
					} else {
						ans += d[cx][cy];
						break label;
					}
				}
			}
		}
		System.out.println(ans);
	}
}

Choices:
- No abnormally found
- Internal error
- Runtime Error
- Time Limit Exceeded


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		char[][] s = new char[n][];
		for (int i = 0; i < n; i++) {
			s[i] = br.readLine().toCharArray();
		}
		br.close();

		Obj[] arr = new Obj[n];
		int total = 0;
		for (int i = 0; i < n; i++) {
			Obj o = new Obj();
			int cnt = 0;
			for (int j = 0; j < s[i].length; j++) {
				if (s[i][j] == '(') {
					cnt++;
				} else {
					cnt--;
					o.min = Math.min(o.min, cnt);
				}
			}
			o.cnt = cnt;
			arr[i] = o;
			total += cnt;
		}
		if (total != 0) {
			System.out.println("No");
			return;
		}

		Arrays.sort(arr, (o1, o2) -> {
			if (o1.min != o2.min) {
				return o2.min - o1.min;
			}
			return o2.cnt - o1.cnt;
		});

		Queue<Obj> que = new ArrayDeque<>();
		int now = 0;
		for (Obj o : arr) {
			if (now + o.min >= 0 && o.cnt >= 0) {
				now += o.cnt;
			} else {
				que.add(o);
			}
		}

		List<Obj> list = new ArrayList<>();
		while (!que.isEmpty()) {
			Obj o = que.poll();
			if (now + o.min < 0) {
				System.out.println("No");
				return;
			}
			if (o.cnt >= 0) {
				now += o.cnt;
			} else {
				list.add(o);
			}
		}
		throw new Exception();

//		Collections.sort(list, (o1, o2) -> o2.cnt - o1.cnt);
//		for (Obj o : list) {
//			if (now + o.min < 0) {
//				System.out.println("No");
//				return;
//			}
//			now += o.cnt;
//		}
//		System.out.println("Yes");
	}

	static class Obj {
		int min, cnt;
	}
}

Choices:
- Runtime Error
- No abnormally found
- Memory Limit Exceeded
- Internal error


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		char[][] s = new char[n][];
		for (int i = 0; i < n; i++) {
			s[i] = br.readLine().toCharArray();
		}
		br.close();

		Obj[] arr = new Obj[n];
		int total = 0;
		for (int i = 0; i < n; i++) {
			Obj o = new Obj();
			int cnt = 0;
			for (int j = 0; j < s[i].length; j++) {
				if (s[i][j] == '(') {
					cnt++;
				} else {
					cnt--;
					o.min = Math.min(o.min, cnt);
				}
			}
			o.cnt = cnt;
			arr[i] = o;
			total += cnt;
		}
		if (total != 0) {
			System.out.println("No");
			return;
		}

		Arrays.sort(arr, (o1, o2) -> {
			if (o1.min != o2.min) {
				return o2.min - o1.min;
			}
			return o2.cnt - o1.cnt;
		});

		Queue<Obj> que = new ArrayDeque<>();
		int now = 0;
		for (Obj o : arr) {
			if (now + o.min >= 0 && o.cnt >= 0) {
				now += o.cnt;
			} else {
				que.add(o);
			}
		}
		while (!que.isEmpty()) {
			Obj o = que.poll();
			if (now + o.min < 0) {
				System.out.println("No");
				return;
			}
			now += o.cnt;
		}
//		System.out.println("Yes");
		throw new Exception();
	}

	static class Obj {
		int min, cnt;
	}
}

Choices:
- Time Limit Exceeded
- Runtime Error
- No abnormally found
- Memory Limit Exceeded