Question:
import java.util.Scanner;

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

        String s = sc.nextLine();
        String t = sc.nextLine();

        boolean flag = false;
        for (int i = 0; i < s.length(); i++) {
            if (flag)
                break;
            char cs = s.charAt(i);
            char ct = t.charAt(0);

            if (cs != ct)
                continue;

            int cnt = i + 1;
            for (int j = 1; j < t.length(); j++) {
                cs = s.charAt(cnt++);
                ct = t.charAt(j);
                if (cs != ct) {
                    flag = false;
                    break;
                }
                if (cnt >= s.length())
                    cnt = 0;
                flag = true;
            }
        }

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

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


Question:
import java.util.Scanner;

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

        String s = sc.nextLine();
        String t = sc.nextLine();

        boolean flag = false;
        for (int i = 0; i < s.length(); i++) {
            char cs = s.charAt(i);
            char ct = t.charAt(0);

            if (cs != ct)
                continue;

            int cnt = i + 1;
            for (int j = 1; j < t.length(); j++) {
                cs = s.charAt(cnt++);
                ct = t.charAt(j);
                if (cs != ct) {
                    flag = false;
                    break;
                }
                if (cnt >= s.length())
                    cnt = 0;
                flag = true;
            }
        }

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

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


Question:
import java.util.Scanner;
public class MainB {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();
        if(a >= k){
            print(a-k,b);
        }else if(a+b >= k){
            print(0,b-(k-a));
        }else{
            print(0,0);
        }
    }
    public static void print(long a, long b){
        System.out.println(a+" "+b);
    }
}

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


Question:
//Atcoder ABC147 B

import java.util.Scanner;

public class Main {

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

		char S[] = sc.next().toCharArray();
		int length = S.length;
		int cnt = 0;

		for(int i=0;i<length;i++) {
			if(S[i]!=S[length-i-1]) {
				cnt++;
			}
          	S[i] = [length-i-1];
		}
		System.out.println(cnt);
	}

}

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


Question:
//Atcoder ABC147 B

import java.util.Scanner;

public class Main {

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

		char S[] = sc.next().toChars();
		int length = S.length;
		char c =' ';
		char d =' ';
		int cnt = 0;

		for(int i=0;i<length/2;i++) {
			c = S[i];
			d = S[length-i-1];
			if(c!=d) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}

}

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


Question:
//Atcoder ABC147 B

import java.util.Scanner;

public class Main {

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

		char S[] = sc.next().toArray();
		int length = S.length;
		char c =' ';
		char d =' ';
		int cnt = 0;

		for(int i=0;i<length/2;i++) {
			c = S[i];
			d = S[length-i-1];
			if(c!=d) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}

}

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


Question:
//Atcoder ABC147 B

import java.util.Scanner;

public class Main {

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

		char S[] = sc.next().toArray();
		int length = S.length();
		char c =' ';
		char d =' ';
		int cnt = 0;

		for(int i=0;i<length/2;i++) {
			c = S[i];
			d = S[length-i-1];
			if(c!=d) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}

}

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


Question:
//Atcoder ABC147 B

import java.util.Scanner;

public class Main {

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

		String S = sc.next();
		int length = S.length();
		char c =' ';
		char d =' ';
		int cnt = 0;

		for(int i=0;i<length/2;i++) {
			c = S.charAt(i);
			d = S.charAt(length-i);
			if(c!=d) {
				cnt++;
			}
			length--;
		}
		System.out.println(cnt);
	}

}

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


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.SortedMap;
import java.util.TreeMap;

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] head = br.readLine().split(" ");
    int h = Integer.parseInt(head[0]);
    int w = Integer.parseInt(head[1]);
    int[][] ab = new int[h][2];
    for(int i = 0; i < h; i++){
      String[] data = br.readLine().split(" ");
      ab[i][0] = Integer.parseInt(data[0]);
      ab[i][1] = Integer.parseInt(data[1]);
    }
    br.close();

    // key:終点のH座標、value:始点のH座標
    SortedMap<Integer, Integer> routeMap = new TreeMap<>();
    SortedMap<Integer, Integer> distMap = new TreeMap<>();

    for(int num = 1; num <= w; num++){
      routeMap.put(num, num);
    }
    distMap.put(0, h);

    PrintWriter pw = new PrintWriter(System.out);
    for(int i = 0; i < h; i++){
      int from = ab[i][0];
      int to = ab[i][1];
      SortedMap<Integer, Integer> subMap = routeMap.subMap(from, to + 1);
      if(to < w && !routeMap.containsKey(to + 1) && !subMap.isEmpty()){
        int dist = to + 1 - subMap.get(subMap.lastKey());
        routeMap.put(to + 1, subMap.get(subMap.lastKey()));
        if(distMap.containsKey(dist)){
          distMap.put(dist, distMap.get(dist) + 1);
        } else {
          distMap.put(dist, 1);
        }
      }
      for(Integer key : subMap.keySet()){
        int dist = key - subMap.get(key);
        if(distMap.get(dist) == 1){
          distMap.remove(dist);
        } else {
          distMap.put(dist, distMap.get(dist) - 1);
        }
      }
      subMap.clear();

      if(distMap.isEmpty()){
        pw.println(-1);
      } else {
        pw.println(distMap.lastKey() + i + 1);
      }
    }
    pw.close();
  }
}

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


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

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    long answer = 0;
    int n = Integer.parseInt(br.readLine());
    int[] div2cnt = new int[n];
    int[] div5cnt = new int[n];
    long[] pow10 = new long[10];
    pow10[0] = 1;
    for(int i = 1; i < 10; i++){
      pow10[i] = pow10[i - 1] * 10;
    }
    for(int i = 0; i < n; i++){
      String a = br.readLine();
      int idx = a.indexOf('.');
      long num = 0;
      if(idx > 0){
        num = Long.parseLong(a.replace(".", "")) * pow10[9 - (a.length() - idx - 1)];
      } else {
        num = Long.parseLong(a) * pow10[9];
      }
      while(num % 5 == 0){
        div5cnt[i]++;
        num /= 5;
      }
      while(num % 2 == 0){
        div2cnt[i]++;
        num /= 2;
      }
    }
    for(int i = 0; i < n - 1; i++){
      for(int j = i + 1; j < n; j++){
        if(Math.min(div2cnt[i] + div2cnt[j], div5cnt[i] + div5cnt[j]) >= 18){
          answer++;
        }
      }
    }
    System.out.println(answer);
  }
}

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


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

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
    long answer = 0;
    int n = Integer.parseInt(sc.readLine());
    long[] nums = new long[n];
    int[] digits = new int[n];
    long[] mods = new long[19];
    mods[0] = 1;
    for(int i = 1; i < 19; i++){
      mods[i] = mods[i - 1] * 10;
    }
    for(int i = 0; i < n; i++){
      String a = sc.readLine();
      int idx = a.indexOf('.');
      if(idx > 0){
        digits[i] = a.replaceAll("0+$", "").length() - idx - 1;
        nums[i] = Long.parseLong(a.replaceAll("0+$", "").replace(".", ""));
      } else {
        digits[i] = 0;
        nums[i] = Long.parseLong(a);
      }
    }
    for(int i = 0; i < n - 1; i++){
      for(int j = i + 1; j < n; j++){
        if(digits[j] == 0 && digits[i] == 0) {
          answer++;
          continue;
        }
        int digit = digits[i] + digits[j];
        long n1 = nums[i] % mods[digit];
        long n2 = nums[j] % mods[digit];
        if((n1 * n2) % mods[digit] == 0){
          answer++;
          continue;
        }
      }
    }
    System.out.println(answer);
  }
}

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


Question:
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long answer = 0;
    int n = sc.nextInt();
    long[] nums = new long[n];
    int[] digits = new int[n];
    long[] mods = new long[19];
    mods[0] = 1;
    for(int i = 1; i < 19; i++){
      mods[i] = mods[i - 1] * 10;
    }
    for(int i = 0; i < n; i++){
      String a = sc.next();
      int idx = a.indexOf('.');
      if(idx > 0){
        digits[i] = a.replaceAll("0+$", "").length() - idx - 1;
        nums[i] = Long.parseLong(a.replaceAll("0+$", "").replace(".", ""));
      } else {
        digits[i] = 0;
        nums[i] = Long.parseLong(a);
      }
    }
    for(int i = 0; i < n - 1; i++){
      for(int j = i + 1; j < n; j++){
        if(digits[j] == 0 && digits[i] == 0) {
          answer++;
          continue;
        }
        int digit = digits[i] + digits[j];
        long n1 = nums[i] % mods[digit];
        long n2 = nums[j] % mods[digit];
        if((n1 * n2) % mods[digit] == 0){
          answer++;
          continue;
        }
      }
    }
    System.out.println(answer);
  }
}

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


Question:
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    sc.close();
    System.out.println(solve(a, b));

  }

  static int solve(int a, int b) {
    for (int price = b * 10; price < (b + 1) * 10; price++) {
      if (price * 8 / 100 == a) {
        System.out.println(price);
        return;
      }
    }
    System.out.println(-1);
  }
}

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


Question:
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        for(int price = b * 10; b <= b * 11; price++){
            if(price * 8 / 100 == a && price * 10 / 100 == b){
                System.out.println(price);
                return;
            }
        }
        System.out.println(-1);
    }
}

Choices:
- Internal error
- Memory Limit Exceeded
- Runtime Error
- Time 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 ans = 0;
        for (int x = 1; x <= N-1; x++) {
            for (int a = 1; a*a <= x; a++) {
                if (x%a == 0) {
                    if (x/a == a) {
                        ans++;
                    } else {
                        ans+=2;
                    }
                }
            }
        }
        System.out.println(ans);
    }
}

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


Question:
import java.util.*;
public class Main {

  private static long X = 1000000007;

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

    long[][] memo = new long[N+1][N+1];
    for (int i = 0; i <= N; i++) {
      for (int j = 0; j <= N; j++) {
        memo[i][j] = -1;
      }
    }
    int MAX = Math.max(N-K+1, K);
    for (int i = 1; i <= MAX; i++) {
      long count = (comb(N-K+1, i, memo) * comb(K-1, i-1, memo)) % X;
      System.out.println(count);
    }
  }

  private static long comb(int n, int r, long[][] memo) {

    if (r == n || r == 0) {
      return 1;
    }

    if (memo[n][r] != -1) {
      return memo[n][r];
    }

    memo[n][r] = (comb(n-1, r-1, memo) + comb(n-1, r, memo)) % X;

    return memo[n][r];
  }
}

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


Question:
import java.util.*;
public class Main {

  private static long X = 1000000007;

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

    long[][] memo = new long[N+1][N+1];
    for (int i = 0; i <= N; i++) {
      for (int j = 0; j <= N; j++) {
        memo[i][j] = -1;
      }
    }
    for (int i = 1; i <= N-K+1; i++) {
      long count = (comb(N-K+1, i, memo) * comb(K-1, i-1, memo)) % X;
      System.out.println(count);
    }
  }

  private static long comb(int n, int r, long[][] memo) {

    if (r == n || r == 0) {
      return 1;
    }

    if (memo[n][r] != -1) {
      return memo[n][r];
    }

    memo[n][r] = (comb(n-1, r-1, memo) + comb(n-1, r, memo)) % X;

    return memo[n][r];
  }
}

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


Question:
import java.util.*;
public class Main {

  private static long X = 1000000007;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[][] graph = new int[N+1][N+1];
    for (int i = 0; i < M; i++) {
      int u = sc.nextInt();
      int v = sc.nextInt();
      graph[u][v] = 1;
    }
    int S = sc.nextInt();
    int T = sc.nextInt();

    Set<Integer> reachable = new HashSet<>();
    reachable.add(T);
    boolean hasNewNode = true;

    boolean reachStart = false;
    int count = 0;

    LinkedList<Integer> queue = new LinkedList<>();
    queue.add(T);
    while (hasNewNode && !reachStart) {

      check(graph, queue);
      count++;

      hasNewNode = false;
      Iterator<Integer> itr = queue.iterator();
      while(itr.hasNext()){
        int node = itr.next();
        if (node == S) {
          reachStart = true;
        }
        hasNewNode |= reachable.add(node);
      }
    }

    if (reachStart) {
      System.out.println(count);
    } else {
      System.out.println(-1);
    }
  }

  private static void check(int[][] graph, LinkedList<Integer> queue) {

    for (int c = 0; c < 3; c++) {
      int nodeCount = queue.size();
      while (nodeCount-- > 0) {
        Integer node = queue.remove();
        for (int i = 1; i < graph.length; i++) {
          int v = graph[i][node];
          if (v == 1) {
            queue.add(i);
          }
        }
      }
    }
  }
}

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


Question:
import java.util.*;
public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();

    long ans = 0;
    //
    long lcmCD = (C * D) / gcd(D, C);
    if (B / lcmCD - A / lcmCD <= 1) {
      for (long i = A; i <= B; i++) {
        if (i%C != 0 && i%D != 0) {
          ans++;
        }
      }
    } else {
      for (long i = A; i < (A/lcmCD + 1) * lcmCD; i++) {
        if (i%C != 0 && i%D != 0) {
          ans++;
        }
      }
      for (long i = B/lcmCD * lcmCD; i <= B; i++) {
        if (i%C != 0 && i%D != 0) {
          ans++;
        }
      }
      long unit = 0;
      for (long i = 1; i <= lcmCD; i++) {
        if (i%C != 0 && i%D != 0) {
          unit++;
        }
      }
      long count = B/lcmCD - A/lcmCD - 1;
      ans += unit*count;
    }

//    System.out.println(lcmCD);
//    System.out.println(C*D);
    System.out.println(ans);
  }

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

Choices:
- No abnormally found
- 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 H = sc.nextInt();
    int W = sc.nextInt();
    char[][] grid = new char[H][W];
    for (int i = 0; i < H; i++) {
      String string = sc.next();
      for (int j = 0; j < W; j++) {
        grid[i][j] = string.charAt(j);
      }
    }

    int maxValue = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (grid[i][j] == '.') {
          int value = calc(grid, i, j);
          if (maxValue < value) {
            maxValue = value;
          }
        }
      }
    }

    System.out.println(maxValue);
  }

  private static int calc(char[][] grid, int i, int j) {

    int count = 1;
    // up
    int a = i-1;
    while (a >= 0 && grid[a][j] == '.') {
      a--;
      count++;
    }
    // down
    a = i+1;
    while (a < grid.length && grid[a][j] == '.') {
      a++;
      count++;
    }
    // right
    a = j+1;
    while (a < grid[i].length && grid[i][a] == '.') {
      a++;
      count++;
    }
    // left
    a = j-1;
    while (a >=0 && grid[i][a] == '.') {
      a--;
      count++;
    }

    return count;
  }
}

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


Question:
import java.util.*;
public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    char[][] grid = new char[H][W];
    for (int i = 0; i < H; i++) {
      String string = sc.next();
      for (int j = 0; j < W; j++) {
        grid[i][j] = string.charAt(j);
      }
    }

    int maxValue = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (grid[i][j] == '.') {
          int value = calc(grid, i, j);
          if (maxValue < value) {
            maxValue = value;
          }
        }
      }
    }

    System.out.println(maxValue);
  }

  private static int calc(char[][] grid, int i, int j) {

    int count = 0;
    // up
    int a = i-1;
    while (a >= 0 && grid[a][j] == '.') {
      a--;
      count++;
    }
    // down
    a = i+1;
    while (a < grid.length && grid[a][j] == '.') {
      a++;
      count++;
    }
    // right
    a = j+1;
    while (a <=0 && grid[i][a] == '.') {
      a++;
      count++;
    }
    // left
    a = j-1;
    while (a < grid[i].length && grid[i][a] == '.') {
      a--;
      count++;
    }

    return count;
  }
}

Choices:
- Runtime Error
- No abnormally found
- Internal error
- Time 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 M = sc.nextInt();
    int[] L = new int[M+1];
    int[] R = new int[M+1];
    for (int i = 1; i <= M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    int ans = 0;
    int[] cards = new int[N+1];
    for (int i = 1; i <= M; i++) {
      for (int j = L[i]; j <= R[i]; j++) {
        cards[j]++;
        if (cards[j] == M) {
          ans++;
        }
      }
    }

    //System.out.println("L: " + Arrays.toString(L));
    //System.out.println("R: " + Arrays.toString(R));
    //System.out.println("cards: " + Arrays.toString(cards));

    System.out.println(ans);
  }
}

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


Question:
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();

    char[][] A = new char[H][W];
    for (int i = 0; i < H; i++) {
      String line = sc.next();
      for (int j = 0; j < line.length(); j++) {
        A[i][j] = line.charAt(j);
      }
    }

    int ans = resolve(A);

    System.out.println(ans);
    //System.out.println(Arrays.deepToString(A));
  }

  // up, down, left, right
  private static final int[] dx = { 0, 0, -1, 1 };
  private static final int[] dy = { -1, 1, 0, 0 };

  private static int resolve(char[][] a) {

    Queue<Node> queue = new ArrayDeque<Node>();

    // initial scan
    for (int i = 0; i < a.length; i++) {
      for (int j = 0; j < a[i].length; j++) {
        if (a[i][j] == '#') {
          queue.add(new Node(j, i, 0));
        }
      }
    }

    int max = 0;
    while (!queue.isEmpty()) {
      Node node = queue.remove();
      for (int i = 0; i < 4; i++) {
        int x = node.x + dx[i];
        int y = node.y + dy[i];
        int distance = node.distance + 1;
        if (y < 0 || a.length <= y || x < 0 || a[y].length <= x) {
          continue;
        }
        if (a[y][x] == '.') {
          a[y][x] = '#';
          queue.add(new Node(x, y, distance));
          max = Math.max(max, distance);
        }

      }
    }

    return max;
  }

  static class Node {
    final int x;
    final int y;
    final int distance;
    Node(int x, int y, int distance) {
      this.x = x;
      this.y = y;
      this.distance = distance;
    }
  }
}

Choices:
- Internal error
- Runtime Error
- No abnormally found
- 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];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }

    int maxGcd = 1;
    for (int i = 0; i < N; i++) {
      int l = gcdSum(A, 0, i-1);
      int r = gcdSum(A, i+1, N-1);
      int val = gcd(l, r);
      if (val > maxGcd) {
        maxGcd = val;
      }
    }

    System.out.println(maxGcd);
  }

  private static int gcdSum(int[] A, int start, int end) {
    int gcdVal = 0;
    for (int i = start; i <= end; i++) {
      gcdVal = gcd(gcdVal, A[i]);
    }
    return gcdVal;
  }

  private static int gcd(int i, int j) {
    int a, b;
    if (i > j) {
      a = i;
      b = j;
    } else {
      a = j;
      b = i;
    }

    // a > b
    if (b == 0) {
      return a;
    }

    return gcd(b, a % b);
  }
}

Choices:
- Internal error
- No abnormally found
- 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 = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }

    Map<Set<Integer>, Integer> memo = new HashMap<>();
    int maxGcd = 1;
    for (int i = 0; i < N; i++) {
      int l = gcdSum(A, 0, i-1, memo);
      int r = gcdSum(A, i+1, N-1, memo);
      int val = gcd(l, r, memo);
      if (val > maxGcd) {
        maxGcd = val;
      }
    }

    System.out.println(maxGcd);
  }

  private static int gcdSum(int[] A, int start, int end, Map<Set<Integer>, Integer> memo) {
    if (start > end) {
      return 0;
    }
    int gcdVal = A[start];
    for (int i = start+1; i <= end; i++) {
      gcdVal = gcd(gcdVal, A[i], memo);
    }
    return gcdVal;
  }

  private static int gcd(int i, int j, Map<Set<Integer>, Integer> memo) {
    int a, b;
    if (i > j) {
      a = i;
      b = j;
    } else {
      a = j;
      b = i;
    }

    // a > b
    if (b == 0) {
      return a;
    }

    Set<Integer> key = new HashSet<>();
    key.add(a);
    key.add(b);
    Integer cachedValue = memo.get(key);
    if (cachedValue != null) {
      return cachedValue;
    }

    int value = gcd(b, a % b, memo);
    memo.put(key, value);
    return value;
  }
}

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 = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }

    Map<Set<Integer>, Integer> memo = new HashMap<>();
    int maxGcd = 1;
    for (int i = 0; i < N; i++) {
      int l = gcdDiv(A, 0, i-1, memo);
      int r = gcdDiv(A, i+1, N-1, memo);
      int val;
      if (l > r) {
        val = gcd(l, r, memo);
      } else {
        val = gcd(r, l, memo);
      }

      if (val > maxGcd) {
        maxGcd = val;
      }
    }

    System.out.println(maxGcd);
  }

  private static int gcdDiv(int[] A, int start, int end, Map<Set<Integer>, Integer> memo) {
    if (start > end) {
      return 0;
    }
    if (start == end) {
      return A[start];
    }
    int l = gcdDiv(A, start, (start+end)/2, memo);
    int r = gcdDiv(A, (start+end)/2 + 1, end, memo);
    if (l > r) {
      return gcd(l, r, memo);
    } else {
      return gcd(r, l, memo);
    }
  }

  private static int gcd(int a, int b, Map<Set<Integer>, Integer> memo) {

    // a > b
    if (b == 0) {
      return a;
    }

    Set<Integer> key = new HashSet<>();
    key.add(a);
    key.add(b);
    Integer cachedValue = memo.get(key);
    if (cachedValue != null) {
      return cachedValue;
    }

    int value = gcd(b, a % b, memo);
    memo.put(key, value);
    return value;
  }
}

Choices:
- No abnormally found
- Runtime Error
- Compile Error
- Time 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];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }

    Map<Set<Integer>, Integer> memo = new HashMap<>();
    int maxGcd = 1;
    for (int i = 0; i < N; i++) {
      int tmp = A[i];
      A[i] = A[(i+1) % N];
      int val = gcdDiv(A, 0, N-1, memo);
      A[i] = tmp;
      if (val > maxGcd) {
        maxGcd = val;
      }
    }

    System.out.println(maxGcd);
  }

  private static int gcdDiv(int[] A, int start, int end, Map<Set<Integer>, Integer> memo) {
    if (start == end) {
      return A[start];
    }
    int l = gcdDiv(A, start, (start+end)/2, memo);
    int r = gcdDiv(A, (start+end)/2 + 1, end, memo);
    if (l > r) {
      return gcd(l, r, memo);
    } else {
      return gcd(r, l, memo);
    }
  }

  private static int gcd(int a, int b, Map<Set<Integer>, Integer> memo) {

    // a > b
    if (b == 0) {
      return a;
    }

    Set<Integer> key = new HashSet<>();
    key.add(a);
    key.add(b);
    Integer cachedValue = memo.get(key);
    if (cachedValue != null) {
      return cachedValue;
    }

    int value = gcd(b, a % b, memo);
    memo.put(key, value);
    return value;
  }
}

Choices:
- Internal error
- No abnormally found
- Time Limit Exceeded
- Compile 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[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }

    int maxGcd = 1;
    for (int i = 0; i < N; i++) {
      int tmp = A[i];
      A[i] = A[(i+1) % N];
      int val = gcdDiv(A, 0, N-1);
      A[i] = tmp;
      if (val > maxGcd) {
        maxGcd = val;
      }
    }

    System.out.println(maxGcd);
  }

  private static int gcdDiv(int[] A, int start, int end) {
    if (start == end) {
      return A[start];
    }
    int l = gcdDiv(A, start, (start+end)/2);
    int r = gcdDiv(A, (start+end)/2 + 1, end);
    if (l > r) {
      return gcd(l, r);
    } else {
      return gcd(r, l);
    }
  }

  private static int gcd(int a, int b) {
    // a > b
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  }
}

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


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];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }

    int maxGcd = 1;
    for (int i = 0; i < N; i++) {
      int tmp = A[i];
      A[i] = A[(i+1) % N];
      int val = gcdDiv(A, 0, N-1);
      A[i] = tmp;
      if (val > maxGcd) {
        maxGcd = val;
      }
    }

    System.out.println(maxGcd);
  }

  private static int gcdDiv(int[] A, int start, int end) {
    if (start == end) {
      return A[start];
    }
    int l = gcdDiv(A, start, end/2);
    int r = gcdDiv(A, end/2 + 1, end);
    if (l > r) {
      return gcd(l, r);
    } else {
      return gcd(r, l);
    }
  }

  private static int gcd(int a, int b) {
    // a > b
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  }
}

Choices:
- Memory Limit Exceeded
- Time Limit Exceeded
- Runtime Error
- Internal 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[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }

    int maxGcd = 0;
    for (int i = 0; i < n; i++) {
      int gcdValue = 0;
      for (int j = 0; j < n; j++) {
        if (j == i) {
          // skip
          continue;
        }
        if (gcdValue != 0 && a[j] % gcdValue == 0) {
          continue;
        }
        //System.out.println("j="+ j + ", " + gcdValue);
        if (a[j] > gcdValue) {
          gcdValue = gcd(a[j], gcdValue);
        } else {
          gcdValue = gcd(gcdValue, a[j]);
        }
        if (gcdValue <= maxGcd) {
          break;
        }
      }
      //System.out.println("i="+ i + ", " + gcdValue);
      maxGcd = Math.max(maxGcd, gcdValue);
    }

    System.out.println(maxGcd);
  }

  private static Map<Set<Integer>, Integer> memo = new HashMap<>();

  private static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    }
    Set<Integer> key = new HashSet<>();
    key.add(a);
    key.add(b);
    Integer cachedValue = memo.get(key);
    if (cachedValue != null) {
      //System.out.println("###"+"a " + a+ ", b " + b + ": " +cachedValue);
      return cachedValue;
    }
    int value = gcd(b, a % b);
    //System.out.println("$$$"+"a " + a+ ", b " + b + ": " +value);
    memo.put(key, value);
    return value;
  }
}

Choices:
- Runtime Error
- No abnormally found
- Internal error
- Time 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];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }

    int maxGcd = 0;
    for (int i = 0; i < n; i++) {
      int gcdValue = 0;
      for (int j = 0; j < n; j++) {
        if (j == i) {
          // skip
          continue;
        }
        if (gcdValue != 0 && a[j] % gcdValue == 0) {
          continue;
        }
        //System.out.println("j="+ j + ", " + gcdValue);
        if (a[j] > gcdValue) {
          gcdValue = gcd(a[j], gcdValue);
        } else {
          gcdValue = gcd(gcdValue, a[j]);
        }
      }
      //System.out.println("i="+ i + ", " + gcdValue);
      maxGcd = Math.max(maxGcd, gcdValue);
    }

    System.out.println(maxGcd);
  }

  private static Map<Set<Integer>, Integer> memo = new HashMap<>();

  private static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    }
    Set<Integer> key = new HashSet<>();
    key.add(a);
    key.add(b);
    Integer cachedValue = memo.get(key);
    if (cachedValue != null) {
      //System.out.println("###"+"a " + a+ ", b " + b + ": " +cachedValue);
      return cachedValue;
    }
    int value = gcd(b, a % b);
    //System.out.println("$$$"+"a " + a+ ", b " + b + ": " +value);
    memo.put(key, value);
    return value;
  }
}

Choices:
- Time Limit Exceeded
- No abnormally found
- Compile Error
- Internal 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[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }

    int maxGcd = 0;
    for (int i = 0; i < n; i++) {
      int gcdValue = 0;
      for (int j = 0; j < n; j++) {
        if (j == i) {
          // skip
          continue;
        }
        //System.out.println("j="+ j + ", " + gcdValue);
        if (a[j] > gcdValue) {
          gcdValue = gcd(a[j], gcdValue);
        } else {
          gcdValue = gcd(gcdValue, a[j]);
        }
        if (gcdValue <= maxGcd) {
          break;
        }
      }
      //System.out.println("i="+ i + ", " + gcdValue);
      maxGcd = Math.max(maxGcd, gcdValue);
    }

    System.out.println(maxGcd);
  }

  private static Map<Set<Integer>, Integer> memo = new HashMap<>();

  private static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    }
    Set<Integer> key = new HashSet<>();
    key.add(a);
    key.add(b);
    Integer cachedValue = memo.get(key);
    if (cachedValue != null) {
      //System.out.println("###"+"a " + a+ ", b " + b + ": " +cachedValue);
      return cachedValue;
    }
    int value = gcd(b, a % b);
    //System.out.println("$$$"+"a " + a+ ", b " + b + ": " +value);
    memo.put(key, value);
    return value;
  }
}

Choices:
- Internal 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 = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }

    int maxGcd = 0;
    for (int i = 0; i < n; i++) {
      int gcdValue = 0;
      for (int j = 0; j < n; j++) {
        if (j == i) {
          // skip
          continue;
        }
        //System.out.println("j="+ j + ", " + gcdValue);
        gcdValue = gcd(a[j], gcdValue);
        if (gcdValue <= maxGcd) {
          break;
        }
      }
      //System.out.println("i="+ i + ", " + gcdValue);
      maxGcd = Math.max(maxGcd, gcdValue);
      if (maxGcd == 2) {
        break;
      }
    }

    System.out.println(maxGcd);
  }

  private static Map<Set<Integer>, Integer> memo = new HashMap<>();

  private static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    }
    Set<Integer> key = new HashSet<>();
    key.add(a);
    key.add(b);
    Integer cachedValue = memo.get(key);
    if (cachedValue != null) {
      //System.out.println("###"+"a " + a+ ", b " + b + ": " +cachedValue);
      return cachedValue;
    }
    int value = gcd(b, a % b);
    //System.out.println("$$$"+"a " + a+ ", b " + b + ": " +value);
    memo.put(key, value);
    return value;
  }
}

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


Question:
import java.util.*;

public class Main {
  private static final int[] mnum = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] A = new int[M];
    for (int i = 0; i < M; i++) {
      A[i] = sc.nextInt();
    }
    Arrays.sort(A);

    int[] dp = new int[N+1];
    for (int i = 1; i <= N; i++) {
      for (int j = 0; j < M; j++) {
        if (i - mnum[A[j]] >= 0) {
          dp[i] = Math.max(dp[i], dp[i-mnum[A[j]]]+1);
        }
      }
    }

    String ans = "";
    int remain = dp[N];
    int match = N;
    while (match > 0) {
      for (int j = M-1; j >= 0; j--) {
        if (match-mnum[A[j]] < 0) {
          continue;
        }
        if (remain == 1) {
          if (match-mnum[A[j]] == 0) {
            ans = ans + Integer.toString(A[j]);
            match -= mnum[A[j]];
            break;
          }
        } else {
          if (dp[match-mnum[A[j]]] == remain-1) {
            ans = ans + Integer.toString(A[j]);
            match -= mnum[A[j]];
            remain--;
            break;
          }
        }
      }
    }

    System.out.println(ans);
  }
}

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


Question:
import java.util.*;

public class Main {

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

    // length table
    // p count for level n
    long[] len = new long[N+1];
    long[] pcount = new long[N+1];
    len[0] = 1;
    pcount[0] = 1;
    for (int i = 1; i <= N; i++) {
      len[i] = 2*len[i-1] + 3;
      pcount[i] = 2*pcount[i-1] + 1;
    }

    long ans = solve(N, X, len, pcount);

    System.out.println(ans);
  }

  private static long solve(int n, long x, long[] len, long[] pcount) {

    if (x == 1) {
      return 0;
    } else if (2 <= x && x < 2 + len[n-1]) {
      return solve(n-1, x-1, len, pcount);
    } else if (x == 2 + len[n-1]) {
      return pcount[n-1] + 1;
    } else if (3 + len[n-1] <= x) {
      return pcount[n-1] + 1 + solve(n-1, x-len[n-1]-2, len, pcount);
    }
    throw new IllegalStateException("unexpected !!");
  }
}

Choices:
- Memory 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);
    String S = sc.next();
    String T = sc.next();

    char[] src = new char[26];
    char[] dst = new char[26];

    for (int i = 0; i < S.length(); i++) {
      char s = S.charAt(i);
      char t = T.charAt(i);

      // src
      if (src[s-'a'] == 0) {
        src[s-'a'] = t;
      } else {
        if (src[s-'a'] != t) {
          System.out.println("No");
          return;
        }
      }

      // dst
      if (dst[t-'a'] == 0) {
        dst[t-'a'] = s;
      } else {
        if (dst[t-'a'] != s) {
          System.out.println("No");
          return;
        }
      }
    }

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

Choices:
- Time Limit Exceeded
- Runtime Error
- Compile 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 x = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
    }

    Arrays.sort(a);

    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (x >= A[i]) {
        x -= A[i];
        ans++;
      }
    }
    if (x > 0 && ans == N) {
      ans--;
    }
    System.out.println(ans);
  }
}

Choices:
- Runtime Error
- Memory Limit Exceeded
- Compile Error
- Time 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 x = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
    }

    Arrays.sort(a);

    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (N >= A[i]) {
        N -= A[i];
        ans++;
      }
    }
    if (N > 0 && ans == N) {
      ans--;
    }
    System.out.println(ans);
  }
}

Choices:
- Compile Error
- Runtime Error
- Internal 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 = sc.nextInt();
        int M = sc.nextInt();
        int Q = sc.nextInt();
        int[][] cnt = new int[N+1][N+1];
        for (int i = 0; i < M; i++) {
            int L = Integer.parseInt(sc.next());
            int R = Integer.parseInt(sc.next());
            cnt[L][R]++;
        }

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < Q; i++) {
            int p = sc.nextInt();
            int q = sc.nextInt();
            int tmp = 0;
            for (int l = p; l <= q; l++) {
                for (int r = l; r <= q; r++) {
                    tmp += cnt[l][r];
                }
            }
            ans.append(tmp).append('\n');
        }

        System.out.print(ans);
    }
}

Choices:
- No abnormally found
- Time Limit Exceeded
- 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 M = sc.nextInt();
        int Q = sc.nextInt();
        int[][] cnt = new int[N+1][N+1];
        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            cnt[L][R]++;
        }

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < Q; i++) {
            int p = sc.nextInt();
            int q = sc.nextInt();
            int tmp = 0;
            for (int l = p; l <= q; l++) {
                for (int r = l; r <= q; r++) {
                    tmp += cnt[l][r];
                }
            }
            ans.append(tmp).append('\n');
        }

        System.out.print(ans);
    }
}

Choices:
- Runtime Error
- Time Limit Exceeded
- Compile Error
- Internal 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[] A = new int[N+1];
    int[] B = new int[N];
    for (int i = 1; i <= N; i++) {
      A[i] = sc.nextInt();
      B[i-1] = A[i] - i;
    }
    Arrays.sort(B);
    long min = Long.MAX_VALUE;
    for (int i = 0; i < N; i++) {
      long val = calc(A, B[i]);
      if (val < min) {
        min = val;
      }
    }
    System.out.println(min);
  }

  private static long calc(int[] A, int b) {
    long ret = 0;
    for (int i = 1; i < A.length; i++) {
      ret += Math.abs(A[i] - (b + i));
    }
    return ret;
  }
}

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


Question:
// A, B, C
// B+C, C+A, A+B  (B-A)
// 2A+B+C, 2B+C+A, 2C+A+B (A-B)
// 2A+3B+3C, 2B+3C+3A, 2C+3A+3B (B-A)
// 6A+5B+5C, 6B+5C+5A, 6C+5A+5B (A-B)
// 10A+11B+11C, 10B+11C+11A, 10C+11A+11B (B-A)
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int K = sc.nextInt();
    System.out.println(K%2 == 0 ? A-B : B-A);
  }
}

Choices:
- Runtime Error
- Internal error
- No abnormally found
- Compile 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[] idx1 = new int[N];
    int[] idx2 = new int[N];
    for (int i = 0; i < N; i++) {
      int P = sc.nextInt();
      idx1[--P] = i;
      idx2[--P] = i;
    }

    int minIdx = 0;
    for (int i = N-2; i >= 0; i--) {
      if (idx1[i] > idx1[i+1]) {
        idx1[i] = --minIdx;
      }
    }
    int maxIdx = N-1;
    for (int i = 0; i < N-1; i++) {
      if (idx2[i] > idx2[i+1]) {
        idx2[i] = ++maxIdx;
      }
    }

    System.out.println(Math.min(-minIdx, maxIdx-N+1));
  }
}

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


Question:
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int Q = sc.nextInt();
    int H = sc.nextInt();
    int S = sc.nextInt();
    int D = sc.nextInt();
    int N = sc.nextInt();
    int Sl = Math.min(Math.min(4*Q, 2*H), S);
    if (2*Sl > D) {
      System.out.println((long)N/2*D + (N%2 == 1 ? Sl : 0));
    } else {
      System.out.println((lomg)N*Sl);
    }
  }
}

Choices:
- Runtime Error
- No abnormally found
- Memory Limit Exceeded
- Compile 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 A = sc.nextInt();
    int B = sc.nextInt();
    if (A > B || (N == 1 && A != B))) {
      System.out.println(0);
    } else {
      System.out.println(A+(long)B*(N-1)-(long)A*(N-1)-B+1);
    }
  }
}

Choices:
- Internal error
- Time Limit Exceeded
- 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 A = sc.nextInt();
    int B = sc.nextInt();

    System.out.println(A+(long)B*(N-1)-(long)A*(N-1)-B-1);
  }
}

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


Question:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int[] num = new int[26];
        for (int i = 0; i < H; i++) {
            String s = sc.next();
            for (int j = 0; j < W; j++) {
                num[s.charAt(j)-'a']++;
            }
        }

        boolean ans = true;
        if (H%2 == 0 && W%2 == 0) {
            int num4 = H*W/4;
            for (int i = 0; i < 26; i++) {
                if (num[i] >= 4) {
                    int a = Math.min(num[i]/4, num4);
                    num[i] -= a*4;
                    num4 -= a;
                }
            }
            int others = 0;
            for (int i = 0; i < 26; i++) {
                others += num[i];
            }
            ans = others == 0;
        } else if (H%2 == 1 && W%2 == 1) {
            int num4 = (H-1)*(W-1)/4;
            for (int i = 0; i < 26; i++) {
                if (num[i] >= 4) {
                    int a = Math.min(num[i]/4, num4);
                    num[i] -= a*4;
                    num4 -= a;
                }
            }
            int num2 = (H-1)/2+(W-1)/2;
            for (int i = 0; i < 26; i++) {
                if (num[i] >= 2) {
                    int a = Math.min(num[i]/2, num2);
                    num[i] -= a*2;
                    num2 -= a;
                }
            }
            int others = 0;
            for (int i = 0; i < 26; i++) {
                others += num[i];
            }
            ans = others == 1;
        } else {
            int odd = H%2 == 1 ? H : W;
            int even = H%2 == 1 ? W : W;

            int num4 = (odd-1)*even/4;
            for (int i = 0; i < 26; i++) {
                if (num[i] >= 4) {
                    int a = Math.min(num[i]/4, num4);
                    num[i] -= a*4;
                    num4 -= a;
                }
            }
            int num2 = even/2;
            for (int i = 0; i < 26; i++) {
                if (num[i] >= 2) {
                    int a = Math.min(num[i]/2, num2);
                    num[i] -= a*2;
                    num2 -= a;
                }
            }
            int others = 0;
            for (int i = 0; i < 26; i++) {
                others += num[i];
            }
            ans = others == 0;
        }
        System.out.println(ans ? "Yes" : "No");
    }
}

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


Question:
// x < y
//   x < 0 && y < 0 || x > 0 && y > 0 : y-x
//   x < 0 && y > 0
//      |x| < |y| : y+x+1
//      |y| < |x| : -y-x+1
// y < x
//   y < 0 && x < 0 : +2
//   y > 0 && x > 0 : +2
//   y < 0 && x > 0
//      |x| < |y| : +1
//      |y| < |x| : +1

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int A = Math.abs(Math.abs(x)-Math.abs(y));
    int B = 0;
    if (x == 0 || y == 0) {
      B = 0;
    } else if (x > y) {
      B = (long)x*y < 0 ? 1 : 0;
    } else if (y < x) {
      B = (long)x*y > 0 ? 2 : 1;
    }
    Systrm.out.println(A+B);
  }
}

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


Question:
// x < y
//   x < 0 && y < 0 || x > 0 && y > 0 : y-x
//   x < 0 && y > 0
//      |x| < |y| : y+x+1
//      |y| < |x| : -y-x+1
// y < x
//   y < 0 && x < 0 : +2
//   y > 0 && x > 0 : +2
//   y < 0 && x > 0
//      |x| < |y| : +1
//      |y| < |x| : +1

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int A = Math.abs(Math.abs(x)-Math.abs(y));
    int B = 0;
    if (x == 0 || y == 0) {
      B = 0;
    } else if (x > y) {
      B = (long)x*y < 0 ? 1 : 0;
    } else if (y < x) {
      B = (long)x*y > 0 : 2 : 1;
    }
    Systrm.out.println(A+B);
  }
}

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


Question:
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    if (A == 0 || B == 0 || (A < 0 && B > 0)) {
      System.out.println("Zero");
    } else if ((A > 0 && B > 0) || ((B-A+1)%2 == 0) {
      System.out.println("Positive");
    } else {
      System.out.println("Negative");
    }
  }
}

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


Question:
import java.util.*;
public class Solution{
    public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        String s = sc.next();
        if(s.endsWith("s"))
            s+="es";
        else
            s+="s";
        System.out.println(s);
    }
}

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


Question:
import java.util.*;
public class atcoder{
    public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        String s = sc.next();
        if(s.endsWith("s"))
            s+="es";
        else
            s+="s";
        System.out.println(s);
    }
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count =0;
		for (int i=1;i<=N;i++) {
			int b;
			for (b=1;b*b<N-i;b++) {
				if ((N-i)%b==0) {
					count +=2;
				}
			}
			if (b*b==(N-i)) {
				count +=1;
			}
		}
		System.out.println(count);
	}
}

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


Question: 1000000000000000 1000000000000000 1000000000000000

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int a[] = new int[N];
		for (int i=0;i<N;i++) {
			a[i] =sc.nextInt();
		}
		long sum =0;
		long dp0[]= new long[N];
		long dp1[]= new long[N];
		long dp2[]= new long[N];
		dp0[0] = 0;
		dp1[0] = a[0];
		dp0[1] = 0;
		dp1[1] = Math.max(a[0], a[1]);
		dp2[1] = Math.max(a[0], a[1]);
		dp0[2] = 0;
		dp1[2] = Math.max(a[0], Math.max(a[1], a[2]));
		dp2[2] = a[0]+a[2];
		for (int i=3;i<N;i++) {
			if (i%2==0) {
				dp0[i] = Math.max(dp0[i-2]+a[i], dp1[i-2]);
				dp0[i] = Math.max(dp0[i], dp0[i-1]);
				dp1[i] = Math.max(dp1[i-2]+a[i], dp2[i-2]);
				dp1[i] = Math.max(dp1[i], dp1[i-1]);
				dp2[i] = dp2[i-2]+a[i];
			} else {
				dp0[i] = Math.max(dp0[i-2]+a[i],dp1[i-2]);
				dp0[i] = Math.max(dp0[i], dp1[i-1]);
				dp1[i] = Math.max(dp1[i-2]+a[i],dp2[i-1]);
				dp2[i] = dp1[i];
			}
		}
		if (N%2==1) {
			System.out.println(Math.max(dp1[N-1], dp1[N-2]));
		} else {
			System.out.println(Math.max(dp1[N-1], dp2[N-2]));
		}
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int a[] = new int[N];
		for (int i=0;i<N;i++) {
			a[i] =sc.nextInt();
		}
		long sum =0;
		long dp[][] = new long[3][N];
		dp[0][0] = 0;
		dp[1][0] = a[0];
		dp[0][1] = 0;
		dp[1][1] = Math.max(a[0], a[1]);
		dp[2][1] = Math.max(a[0], a[1]);
		dp[0][2] = 0;
		dp[1][2] = Math.max(a[0], Math.max(a[1], a[2]));
		dp[2][2] = a[0]+a[2];
		for (int i=3;i<N;i++) {
			if (i%2==0) {
				dp[0][i] = Math.max(dp[0][i-2]+a[i], dp[1][i-2]);
				dp[0][i] = Math.max(dp[0][i], dp[0][i-1]);
				dp[1][i] = Math.max(dp[1][i-2]+a[i], dp[2][i-2]);
				dp[1][i] = Math.max(dp[1][i], dp[1][i-1]);
				dp[2][i] = dp[2][i-2]+a[i];
			} else {
				dp[0][i] = Math.max(dp[0][i-2]+a[i],dp[1][i-2]);
				dp[0][i] = Math.max(dp[0][i], dp[1][i-1]);
				dp[1][i] = Math.max(dp[1][i-2]+a[i],dp[2][i-1]);
				dp[2][i] = dp[1][i];
			}
		}
		if (N%2==1) {
			System.out.println(Math.max(dp[1][N-1], dp[1][N-2]));
		} else {
			System.out.println(Math.max(dp[1][N-1], dp[2][N-2]));
		}
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int a[] = new int[N];
		for (int i=0;i<N;i++) {
			a[i] =sc.nextInt();
		}
		long sum =0;
		long dp[][] = new long[3][N];
		dp[0][0] = 0;
		dp[1][0] = a[0];
		dp[0][1] = 0;
		dp[1][1] = a[1];
		dp[0][2] = 0;
		dp[1][2] = Math.max(a[0], Math.max(a[1], a[2]));
		dp[2][2] = a[0]+a[2];
		for (int i=3;i<N;i++) {
			if (i%2==0) {
				dp[0][i] = dp[0][i-2];
				dp[1][i] = Math.max(dp[1][i-2], dp[2][i-2]);
				dp[1][i] = Math.max(dp[1][i], dp[0][i-2]+a[i]);
				dp[2][i] = Math.max(dp[2][i-2]+a[i], dp[1][i-2]+a[i]);
			} else {
				dp[0][i] = dp[0][i-2]+a[i];
				dp[1][i] = Math.max(dp[2][i-2], dp[1][i-2]+a[i]);
				dp[2][i] = Math.max(dp[2][i-2], dp[1][i-2]+a[i]);
			}
		}
		if (N%2==1) {
			System.out.println(dp[2][N-1]);
		} else {
			System.out.println(Math.max(dp[2][N-1], dp[1][N-1]));
		}
	}
}

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


Question:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N= sc.nextInt();
		int a[] = new int[N];
		for (int i=0;i<N;i++) {
			a[i] = sc.nextInt();
		}
		int b[] = new int[100000];
		for (int i=0;i<N;i++) {
			b[a[i]]++;
		}
		long sum=0;
		for (int i=0;i<b.length;i++) {
			sum += b[i]*(b[i]-1)/2;
		}
		for (int i=0;i<N;i++) {
			long temp=sum;
			temp-=b[a[i]]*(b[a[i]]-1)/2;
			temp+=(b[a[i]]-1)*(b[a[i]]-2)/2;
			System.out.println(temp);
		}
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int B[] = new int[N];
		if (M>0) {
			B = new int[M];
		}
		for (int i=0;i<M;i++) {
			B[i] = sc.nextInt();
		}
		long A[]= new long[N];
		int now =0;
		if (B[now]==1) {
			A[1]=1;
			now ++;
		}
		for(int i=2;i<N;i++) {
			if (now<M&&B[now]!=i) {
				A[i]=(A[i-1]+A[i-2])%1000000007;
			} else {
				i++;
			}
		}
		System.out.println((A[N-1]+A[N-2])%1000000007);
	}
}

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


Question:
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Set<Long> set = new HashSet<Long>();
		for (int i=0;i<M;i++) {
			set.add(sc.nextLong());
		}
		long A[]= new long[N];
		A[0]=1;
		if (set.contains(1)==false) {
			A[1]=1;
		}
		for(int i=2;i<N;i++) {
			if (set.contains(i)==false) {
				A[i]=(A[i-1]+A[i-2])%1000000007;
			}
		}
		System.out.println((A[N-1]+A[N-2])%1000000007);
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println(A*B/2);
	}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a[]= new int[200];
		for (int i=1;i<200;i++) {
			a[i] ++;
		}
		for (int i=3;i<200;i+=2) {
			for (int j=1;j*i<200;j+=2) {
				a[i*j]++;
			}
		}
		int N =sc.nextInt();
		int count =0;
		for (int i=1;i<=N;i++) {
			if (a[i]==8) {
				count ++;
			}
		}
		System.out.println(count);
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long K = sc.nextLong();
		for (int i = 0; i < K; i++) {
			long tempa = B + C;
			long tempb = A + C;
			long tempc = B + A;
			A = tempa;
			B = tempb;
			C = tempc;
			if (Math.abs(A-B)>1000000000000000000l) {
				System.out.println("Unfair");
				return ;
			}
		}
		System.out.println(A-B);
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char c[][] = new char[H][W];
		for (int i=0;i<H;i++) {
			char ch[] = sc.next().toCharArray();
			for (int j=0;j<W;j++) {
				c[i][j] = ch[j];
			}
		}
		int a[][]= new int[H][W];
		int h = 0;
		int w = 0;
		a[h][w]=1;
		while (h<=H-1&&w<=W-1) {
			if (w<W) {
				if (c[h][w+1]=='#') {
					w++;
					a[h][w]=1;
				} else if (h<H) {
					if (c[h+1][w]=='#') {
						h++;
						a[h][w]=1;
					} else {
						System.out.println("Impossible");
						return ;
					}
				} else {
					System.out.println("Impossible");
					return ;
				}
			} else {
				if (h<H) {
					if (c[h+1][w]=='#') {
						h++;
						a[h][w]=1;
					} else {
						System.out.println("Impossible");
						return ;
					}
				} else {
					System.out.println("Impossible");
					return ;
				}
			}
		}
		for (int i=0;i<H;i++) {
			for (int j=0;j<W;j++) {
				if (a[h][w]==0&&c[h][w]=='#') {
					System.out.println("Impossible");
					return ;
				}
			}
		}
		System.out.println("Possible");
	}
}

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


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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[][][] summary = new int[10][45][45];
        int[][] A = new int[N][3];
        for (int i = 0; i < N; i++) {
            String temp = scan.next();
            int digits = 0;
            long x = 0;
            if (temp.indexOf(".") == -1) {
                x = Long.parseLong(temp);
            } else {
                String t = temp.substring(temp.indexOf(".") + 1);
                if (Long.valueOf(t) == 0) {
                    t = "";
                }
                digits = t.length();
                String tt = temp.substring(0, temp.indexOf(".")) + t;
                x = Long.parseLong(tt);
            }
            int two_count = this.count(2, x);
            int five_count = this.count(5, x);
            summary[digits][two_count][five_count] += 1;
            A[i][0] = digits;
            A[i][1] = two_count;
            A[i][2] = five_count;
        }
        long ans = 0;
        for (int i = 0; i < N; i++) {
            int digit_count = A[i][0];
            int two_count = A[i][1];
            int five_count = A[i][2];
            for (int j = 0; j < 10; j++) {
                int total_digits = digit_count + j;
                for (int k = 0; k < 45; k++) {
                    for (int l = 0; l < 45; l++) {
                        if (summary[j][k][l] == 0) {
                            continue;
                        }
                        int count = Math.min(two_count + k, five_count + l);
                        if (total_digits <= count) {
                            if (j == digit_count && k == two_count && l == five_count) {
                                ans += summary[j][k][l] - 1;
                            } else {
                                ans += summary[j][k][l];
                            }
                        }
                    }
                }
            }
        }
        System.out.println(ans/2);
    }
    private int count(long base, long x) {
        int count = 0;
        while (x % base == 0) {
            count += 1;
            x /= base;
        }
        return count;
    }
}

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


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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[][][] summary = new int[10][65][65];
        int[][] A = new int[N][3];
        for (int i = 0; i < N; i++) {
            String temp = scan.next();
            int digits = 0;
            long x = 0;
            if (temp.indexOf(".") == -1) {
                x = Long.parseLong(temp);
            } else {
                String t = temp.substring(temp.indexOf(".") + 1);
                if (Long.valueOf(t) == 0) {
                    t = "";
                }
                digits = t.length();
                String tt = temp.substring(0, temp.indexOf(".")) + t;
                x = Long.parseLong(tt);
            }
            int two_count = this.count(2, x);
            int five_count = this.count(5, x);
            summary[digits][two_count][five_count] += 1;
            A[i][0] = digits;
            A[i][1] = two_count;
            A[i][2] = five_count;
        }
        long ans = 0;
        for (int i = 0; i < N; i++) {
            int digit_count = A[i][0];
            int two_count = A[i][1];
            int five_count = A[i][2];
            for (int j = 0; j < 10; j++) {
                int total_digits = digit_count + j;
                for (int k = 0; k < 65; k++) {
                    for (int l = 0; l < 65; l++) {
                        if (summary[j][k][l] == 0) {
                            continue;
                        }
                        int count = Math.min(two_count + k, five_count + l);
                        if (total_digits <= count) {
                            if (j == digit_count && k == two_count && l == five_count) {
                                ans += summary[j][k][l] - 1;
                            } else {
                                ans += summary[j][k][l];
                            }
                        }
                    }
                }
            }
        }
        System.out.println(ans/2);
    }
    private int count(long base, long x) {
        int count = 0;
        while (x % base == 0) {
            count += 1;
            x /= base;
        }
        return count;
    }
}

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


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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        boolean[] prime = new boolean[N+1];
        Arrays.fill(prime, true);
        prime[0] = true;
        prime[1] = true;
        for (int i = 2; i * i <= N; i++) {
            if (!prime[i]) {
                continue;
            }
            for (int j = 2; i * j <= N; j++) {
                prime[i*j] = false;
            }
        }
        List<Integer> primes = new ArrayList<>();
        for (int i = 2; i <= N; i++) {
            if (prime[i]) {
                primes.add(i);
            }
        }
        int[] dp = new int[N+1];
        Arrays.fill(dp, -1);
        dp[1] = 1;
        dp[2] = 2;
        dp[3] = 2;
        int len = primes.size();
        for (int i = 4; i <= N; i++) {
            if (prime[i]) {
                dp[i] = 2;
                continue;
            }
            for (int j = 0; j < len; j++) {
                if (i % primes.get(j) != 0) {
                    continue;
                }
                int x = primes.get(j);
                int current = i;
                int count = 0;
                int t = 1;
                while (current % x == 0) {
                    count += 1;
                    current /= x;
                    t *= x;
                }
                if (count == 1) {
                    dp[i] = dp[x] * dp[i/x];
                } else {
                    dp[i] = (dp[t/x] + 1)*dp[i/t];
                }
                break;
            }
        }

        long ans = 0;
        for (int i = 1; i <= N; i++) {
            ans += (long) i * (long) dp[i];
        }
        System.out.println(ans);
    }
}

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


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

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

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        HashMap<Long, HashMap<Long, Integer>> mapAB = new HashMap<>();
        long[] A = new long[N];
        long[] B = new long[N];
        int zeros = 0;
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong();
            B[i] = scan.nextLong();
            if (A[i] == 0 && B[i] == 0) {
                zeros += 1;
            }
        }
        for (int i = 0; i < N; i++) {
            if (A[i] == 0 && B[i] == 0) {
                continue;
            }
            increment(mapAB, A[i], B[i]);
        }
        HashMap<String, Group> map = new HashMap<>();
        for (long a : mapAB.keySet()) {
            HashMap<Long, Integer> t = mapAB.get(a);
            for (long b : t.keySet()) {
                String key = key(a, b);
                boolean is_first = is_first(a, b);
                if (!map.containsKey(key)) {
                    map.put(key, new Group());
                }
                Group group = map.get(key);
                if (is_first) {
                    group.first += t.get(b);
                } else {
                    group.second += t.get(b);
                }
            }
        }
        long ans = 1;
        long mod = 1000000007;
        for (Group group : map.values()) {
            long t = 1;
            t += pow(2, group.first, mod);
            t += mod - 1;
            t %= mod;
            t += pow(2, group.second, mod);
            t %= mod;
            t += mod - 1;
            t %= mod;
            ans *= t;
            ans %= mod;
        }
        ans += mod - 1;
        ans %= mod;
        ans += zeros;
        System.out.println(ans);
    }
    void increment(HashMap<Long, HashMap<Long, Integer>> map, long A, long B) {
        if (A == 0 && B != 0) {
            B = Long.MAX_VALUE;
        }
        if (B == 0 && A != 0) {
            A = Long.MAX_VALUE;
        }
        if (A != 0 && B != 0) {
            long gcd = gcd(A, B);
            A = A / gcd;
            B = B / gcd;
        }
        HashMap<Long, Integer> t = map.get(A);
        if (t == null) {
            t = new HashMap<>();
        }
        int count = t.getOrDefault(B, 0);
        t.put(B, count + 1);
        map.put(A, t);
    }
    long pow(int base, int count, long mod) {
        if (count == 0) {
            return 1;
        }
        if (count % 2 == 1) {
            long t = base * pow(base, count - 1, mod);
            t %= mod;
            return t;
        }
        long t = pow(base, count / 2, mod);
        t *= t;
        t %= mod;
        return t;
    }
    long gcd(long x, long y) {
        if (y == 0) {
            return x;
        }
        return gcd(y , x % y);
    }
    private String key(long A, long B) {
        if (B == 0 && A == Long.MAX_VALUE) {
            return A + ":" + B;
        }
        if (A == 0 && B == Long.MAX_VALUE) {
            return B + ":" + A;
        }
        if (0 < A && 0 < B) {
            return A + ":" + B;
        }
        if (A < 0 && B < 0) {
            return -A + ":" + -B;
        }
        if (0 < A && B < 0) {
            return -B + ":" + A;
        }
        return B + ":" + -A;
    }
    private boolean is_first(long A, long B) {
        if (B == 0 && A == Long.MAX_VALUE) {
            return true;
        }
        if (A == 0 && B == Long.MAX_VALUE) {
            return false;
        }
        if (0 < A && 0 < B) {
            return true;
        }
        if (A < 0 && B < 0) {
            return true;
        }
        return false;
    }
    class Group {
        int first = 0;
        int second = 0;
    }
}

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


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

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

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        HashMap<Long, HashMap<Long, Integer>> mapAB = new HashMap<>();
        long[] A = new long[N];
        long[] B = new long[N];
        int zeros = 0;
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong();
            B[i] = scan.nextLong();
            if (A[i] == 0 && B[i] == 0) {
                zeros += 1;
            }
        }
        for (int i = 0; i < N; i++) {
            if (A[i] == 0 && B[i] == 0) {
                continue;
            }
            mapAB = increment(mapAB, A[i], B[i]);
        }
        HashMap<String, Group> map = new HashMap<>();
        for (long a : mapAB.keySet()) {
            HashMap<Long, Integer> t = mapAB.get(a);
            for (long b : t.keySet()) {
                String key = key(a, b);
                boolean is_first = is_first(a, b);
                if (!map.containsKey(key)) {
                    map.put(key, new Group());
                }
                Group group = map.get(key);
                if (is_first) {
                    group.first += t.get(b);
                } else {
                    group.second += t.get(b);
                }
            }
        }
        long ans = 1;
        long mod = 1000000007;
        for (Group group : map.values()) {
            long t = 1;
            t += pow(2, group.first, mod);
            t %= mod;
            t += mod - 1;
            t %= mod;
            t += pow(2, group.second, mod);
            t %= mod;
            t += mod - 1;
            t %= mod;
            ans *= t;
            ans %= mod;
        }
        ans += mod - 1;
        ans %= mod;
        ans += zeros;
        System.out.println(ans);
    }
    HashMap<Long, HashMap<Long, Integer>> increment(HashMap<Long, HashMap<Long, Integer>> map, long A, long B) {
        if (A == 0 && B != 0) {
            B = Long.MAX_VALUE;
        }
        if (B == 0 && A != 0) {
            A = Long.MAX_VALUE;
        }
        if (A != 0 && B != 0) {
            long gcd = gcd(A, B);
            A = A / gcd;
            B = B / gcd;
        }
        HashMap<Long, Integer> t = map.get(A);
        if (t == null) {
            t = new HashMap<>();
        }
        int count = t.getOrDefault(B, 0);
        t.put(B, count + 1);
        map.put(A, t);
        return map;
    }
    long pow(int base, int count, long mod) {
        if (count == 0) {
            return 1;
        }
        if (count % 2 == 1) {
            long t = base * pow(base, count - 1, mod);
            t %= mod;
            return t;
        }
        long t = pow(base, count / 2, mod);
        t *= t;
        t %= mod;
        return t;
    }
    long gcd(long x, long y) {
        if (y == 0) {
            return x;
        }
        return gcd(y , x % y);
    }
    private String key(long A, long B) {
        if (B == 0 && A == Long.MAX_VALUE) {
            return A + ":" + B;
        }
        if (A == 0 && B == Long.MAX_VALUE) {
            return B + ":" + A;
        }
        if (0 < A && 0 < B) {
            return A + ":" + B;
        }
        if (A < 0 && B < 0) {
            return Long.toString(-A) + ":" + Long.toString(-B);
        }
        if (0 < A && B < 0) {
            return Long.toString(-B) + ":" + A;
        }
        return B + ":" + Long.toString(-A);
    }
    private boolean is_first(long A, long B) {
        if (B == 0 && A == Long.MAX_VALUE) {
            return true;
        }
        if (A == 0 && B == Long.MAX_VALUE) {
            return false;
        }
        if (0 < A && 0 < B) {
            return true;
        }
        if (A < 0 && B < 0) {
            return true;
        }
        return false;
    }
    class Group {
        int first = 0;
        int second = 0;
    }
}

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


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

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

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String S = scan.next();
        char[] d = S.toCharArray();
        int[][] summary = new int[N+1][26];
        for (int i = 0; i <= N; i++) {
            Arrays.fill(summary[i], 0);
        }
        for (int i = 1; i <= N; i++) {
            for (int j = 0; j < 26; j++) {
                summary[i][j] = summary[i-1][j];
            }
            summary[i][(int)d[i-1]-'a'] += 1;
        }
        int Q = scan.nextInt();
        int[][] diff = new int[Q][26];
        for (int i = 0; i < Q; i++) {
            int type = scan.nextInt();
            if (type == 1) {
                int index = scan.nextInt();
                char c = scan.next().toCharArray()[0];
                if (d[index-1] == c) {
                    continue;
                }
                diff[i][(int) d[index-1]-'a'] -= 1;
                diff[i][(int) c-'a'] += 1;
                d[index-1] = c;
                for (int k = i + 1; k < Q; k++) {
                    for (int l = 0; l < 26; l++) {
                        diff[k][l]=diff[i][l];
                    }
                }
                continue;
            }
            int l = scan.nextInt();
            int r = scan.nextInt();
            int ans = 0;
            for (int j = 0; j < 26; j++) {
                if (0 < summary[r][j]+diff[i][j] - summary[l-1][j]-diff[l-1][j]) {
                    ans += 1;
                }
            }
            System.out.println(ans);
        }
    }
}

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


Question:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Stream;

public class Main {
    private static char[] map;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        FastScan scan = new FastScan(System.in);
        String S = scan.strings()[0];
        int length = S.length();
        char[] data = S.toCharArray();
        int[][] step = new int[length][3];
        for (int i = 0; i < length; i++) {
            Arrays.fill(step[i],Integer.MAX_VALUE);
        }
        for (int i = 0; i < length - 1; i++) {
            if (data[i] == 'R' && data[i+1] == 'L') {
                step[i][0] = 0;
                step[i][1] = i;
                step[i][2] = 1;
                step[i+1][0] = 0;
                step[i+1][1] = i+1;
                step[i+1][2] = -1;
            }
        }
        Deque<Integer> deq = new ArrayDeque<Integer>();
        for (int i = 0; i < length; i++) {
            if (step[i][0] == 0) {
                continue;
            }
            deq.add(i);
        }
        while(!deq.isEmpty()) {
            int x = deq.poll();
            if (data[x] == 'L' && step[x-1][0] != Integer.MAX_VALUE) {
                step[x][0] = step[x-1][0] + 1;
                step[x][1] = step[x-1][1];
                step[x][2] = step[x-1][2];
                continue;
            }
            if (data[x] == 'R' && step[x+1][0] != Integer.MAX_VALUE) {
                step[x][0] = step[x+1][0] + 1;
                step[x][1] = step[x+1][1];
                step[x][2] = step[x+1][2];
                continue;
            }
            deq.add(x);
        }
        int[] answer = new int[length];
        BigInteger total = BigInteger.TEN.pow(100);
        BigInteger two = new BigInteger("2");
        for (int i = 0; i < length; i++) {
            BigInteger remain = total.subtract(new BigInteger(Long.toString(step[i][0])));
            if (remain.mod(two).longValue() == 0) {
                answer[step[i][1]] += 1;
            } else {
                answer[step[i][1]+step[i][2]] += 1;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (long i : answer) {
            sb.append(i);
            sb.append(" ");
        }
        System.out.println(sb.substring(0, sb.length()-1));
    }
    class FastScan {
        BufferedReader br;
        FastScan(InputStream is)  {
            InputStreamReader isr = new InputStreamReader(is);
            this.br = new BufferedReader(isr);
        }
        String[] strings() throws IOException {
            return this.br.readLine().split(" ");
        }
        long[] longs() throws IOException {
            String[] list = this.br.readLine().split(" ");
            return Stream.of(list).mapToLong(s -> Long.parseLong(s)).toArray();
        }
        int[] ints() throws IOException {
            String[] list = this.br.readLine().split(" ");
            return Stream.of(list).mapToInt(s -> Integer.parseInt(s)).toArray();
        }
    }
}

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


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;

public class Main {
    private static char[] map;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        int length = S.length();
        char[] data = S.toCharArray();
        int[][] step = new int[length][3];
        for (int i = 0; i < length; i++) {
            Arrays.fill(step[i],Integer.MAX_VALUE);
        }
        for (int i = 0; i < length - 1; i++) {
            if (data[i] == 'R' && data[i+1] == 'L') {
                step[i][0] = 0;
                step[i][1] = i;
                step[i][2] = 1;
                step[i+1][0] = 0;
                step[i+1][1] = i+1;
                step[i+1][2] = -1;
            }
        }
        Deque<Integer> deq = new ArrayDeque<Integer>();
        for (int i = 0; i < length; i++) {
            if (step[i][0] == 0) {
                continue;
            }
            deq.add(i);
        }
        while(!deq.isEmpty()) {
            int x = deq.poll();
            if (data[x] == 'L' && step[x-1][0] != Integer.MAX_VALUE) {
                step[x][0] = step[x-1][0] + 1;
                step[x][1] = step[x-1][1];
                step[x][2] = step[x-1][2];
                continue;
            }
            if (data[x] == 'R' && step[x+1][0] != Integer.MAX_VALUE) {
                step[x][0] = step[x+1][0] + 1;
                step[x][1] = step[x+1][1];
                step[x][2] = step[x+1][2];
                continue;
            }
            deq.add(x);
        }
        int[] answer = new int[length];
        BigInteger total = BigInteger.TEN.pow(100);
        BigInteger two = new BigInteger("2");
        for (int i = 0; i < length; i++) {
            BigInteger remain = total.subtract(new BigInteger(Long.toString(step[i][0])));
            if (remain.mod(two).longValue() == 0) {
                answer[step[i][1]] += 1;
            } else {
                answer[step[i][1]+step[i][2]] += 1;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (long i : answer) {
            sb.append(i);
            sb.append(" ");
        }
        System.out.println(sb.substring(0, sb.length()-1));
    }
}

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


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;

public class Main {
    private static char[] map;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        int length = S.length();
        char[] data = S.toCharArray();
        boolean[] check = new boolean[length];
        int[][] step = new int[length][3];
        for (int i = 0; i < length; i++) {
            Arrays.fill(step[i],Integer.MAX_VALUE);
        }
        for (int i = 0; i < length - 1; i++) {
            if (data[i] == 'R' && data[i+1] == 'L') {
                step[i][0] = 0;
                step[i][1] = i;
                step[i][2] = 1;
                step[i+1][0] = 0;
                step[i+1][1] = i+1;
                step[i+1][2] = -1;
            }
        }
        Deque<Integer> deq = new ArrayDeque<Integer>();
        for (int i = 0; i < length; i++) {
            if (step[i][0] == 0) {
                continue;
            }
            deq.add(i);
        }
        while(!deq.isEmpty()) {
            int x = deq.poll();
            if (data[x] == 'L' && step[x-1][0] != Integer.MAX_VALUE) {
                step[x][0] = step[x-1][0] + 1;
                step[x][1] = step[x-1][1];
                step[x][2] = step[x-1][2];
                continue;
            }
            if (data[x] == 'R' && step[x+1][0] != Integer.MAX_VALUE) {
                step[x][0] = step[x+1][0] + 1;
                step[x][1] = step[x+1][1];
                step[x][2] = step[x+1][2];
                continue;
            }
            deq.add(x);
        }
        int[] answer = new int[length];
        BigInteger total = BigInteger.TEN.pow(100);
        for (int i = 0; i < length; i++) {
            BigInteger remain = total.subtract(new BigInteger(Long.toString(step[i][0])));
            if (remain.mod(new BigInteger("2")).longValue() == 0) {
                answer[step[i][1]] += 1;
            } else {
                answer[step[i][1]+step[i][2]] += 1;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (long i : answer) {
            sb.append(i);
            sb.append(" ");
        }
        System.out.println(sb.substring(0, sb.length()-1));
    }
}

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


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    private static char[] map;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        Main.map = S.toCharArray();
        int length = S.length();
        int[] data = new int[length];
        Arrays.fill(data, 1);
        Stage first = new Stage(0, data);
        HashMap<String, Stage> map = new HashMap<>();
        Stage current = first;
        for (int i = 1; i <= 100010; i++) {
            current = current.next();
        }
        StringBuilder sb = new StringBuilder();
        for (long i : current.data) {
            sb.append(i);
            sb.append(" ");
        }
        System.out.println(sb.substring(0, sb.length()-1));
    }
    class Stage {
        long step;
        int[] data;
        public Stage(long step, int[] data) {
            this.step = step;
            this.data = data;
        }

        public Stage next() {
            int[] next_data = new int[data.length];
            for (int i = 0; i < data.length; i++) {
                if (Main.map[i] == 'L') {
                    next_data[i-1] += this.data[i];
                } else {
                    next_data[i+1] += this.data[i];
                }
            }
            Stage next = new Stage(this.step + 1, next_data);
            return next;
        }

    }
}

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


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    private static char[] map;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        Main.map = S.toCharArray();
        int length = S.length();
        int[] data = new int[length];
        Arrays.fill(data, 1);
        Stage first = new Stage(0, data);
        HashMap<String, Stage> map = new HashMap<>();
        Stage current = first;
        for (int i = 1; i <= 150000; i++) {
            current = current.next();
        }
        StringBuilder sb = new StringBuilder();
        for (long i : current.data) {
            sb.append(i);
            sb.append(" ");
        }
        System.out.println(sb.substring(0, sb.length()-1));
    }
    class Stage {
        long step;
        int[] data;
        public Stage(long step, int[] data) {
            this.step = step;
            this.data = data;
        }

        public Stage next() {
            int[] next_data = new int[data.length];
            for (int i = 0; i < data.length; i++) {
                if (Main.map[i] == 'L') {
                    next_data[i-1] += this.data[i];
                } else {
                    next_data[i+1] += this.data[i];
                }
            }
            Stage next = new Stage(this.step + 1, next_data);
            return next;
        }

    }
}

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


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    private static char[] map;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        Main.map = S.toCharArray();
        int length = S.length();
        int[] data = new int[length];
        Arrays.fill(data, 1);
        Stage first = new Stage(0, data);
        HashMap<String, Stage> map = new HashMap<>();
        Stage current = first;
        while(!map.containsKey(current.key)) {
            map.put(current.key, current);
            current = current.next();
        }
        Stage prev = map.get(current.key);
        long diff = current.step - prev.step;
        BigInteger total = BigInteger.TEN.pow(100);
        BigInteger remain = total.subtract(new BigInteger(Long.toString(current.step)));
        remain = remain.mod(new BigInteger(Long.toString(diff)));
        long x = remain.longValue();
        for (int i = 1; i <= x; i++) {
            current = current.next();
        }
        StringBuilder sb = new StringBuilder();
        for (long i : current.data) {
            sb.append(i);
            sb.append(" ");
        }
        System.out.println(sb.substring(0, sb.length()-1));
    }
    class Stage {
        long step;
        int[] data;
        String key;
        public Stage(long step, int[] data) {
            this.step = step;
            this.data = data;
            this.key = this.key();
        }

        public Stage next() {
            int[] next_data = new int[data.length];
            for (int i = 0; i < data.length; i++) {
                if (Main.map[i] == 'L') {
                    next_data[i-1] += this.data[i];
                } else {
                    next_data[i+1] += this.data[i];
                }
            }
            Stage next = new Stage(this.step + 1, next_data);
            return next;
        }

        public String key() {
            StringBuilder sb = new StringBuilder();
            for (int x : this.data) {
                sb.append(x);
            }
            return sb.toString();
        }
    }
}

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


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

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        char[][] map = new char[H][W];
        for (int i = 0; i < H; i++) {
            String line = scan.next();
            char[] data = line.toCharArray();
            for (int j = 0; j < W; j++) {
                map[i][j] = data[j];
            }
        }
        int answer = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (map[i][j] == '#') {
                    continue;
                }
                int count = 1;
                for (int k = j - 1; 0 <= k; k--) {
                    if (map[i][k] == '#') {
                        break;
                    }
                    count += 1;
                }
                for (int k = j + 1; k < W; k++) {
                    if (map[i][k] == '#') {
                        break;
                    }
                    count += 1;
                }
                for (int k = i - 1; 0 <= k; k--) {
                    if (map[k][j] == '#') {
                        break;
                    }
                    count += 1;
                }
                for (int k = i + 1; k < H; k++) {
                    if (map[k][j] == '#') {
                        break;
                    }
                    count += 1;
                }
                answer = Math.max(answer, count);
            }
        }
        System.out.println(answer);
    }
}

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


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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        int[] V = new int[N];
        for (int i = 0; i < N; i++) {
            V[i] = scan.nextInt();
        }
        int[] sumL = new int[N+1];
        sumL[0] = 0;
        for (int i = 0; i < N; i++) {
            sumL[i+1] = sumL[i] + V[i];
        }
        int[] sumR = new int[N+1];
        sumR[0] = 0;
        for (int i = 0; i < N; i++) {
            sumR[i+1] = sumR[i]+V[N-i-1];
        }
        int[] leftP = new int[N];
        for (int i = 0; i < K; i++) {
            if (N <= i) {
                break;
            }
            if (V[i] < 0) {
                leftP[i] = V[i];
            }
        }
        int[] rightP = new int[N];
        for (int i = 0; i < K; i++) {
            if (N - i - 1 < 0) {
                break;
            }
            if (V[N - i - 1] < 0) {
                rightP[i] = V[N - i - 1];
            }
        }
        int answer = Integer.MIN_VALUE;
        // 何も処理しない
        answer = Math.max(answer, 0);
        // 左からK個全部取る
        // 左からK-1個取得して1個戻す
        // 左からK-2個取得して2個戻す
        int onlyL = left(N, K, sumL, leftP);
        answer = Math.max(answer, onlyL);
        // 右からK個全部取る
        // 右からK-1個取得して1個戻す
        // 右からK-2個取得して2個戻す
        int onlyR = right(N, K, sumR, rightP);
        answer = Math.max(answer, onlyR);
        for (int i = 1; i < K; i++) {
            int LandR = left_and_right(N, K, i, sumL, leftP, sumR, rightP);
            answer = Math.max(answer, LandR);
        }
        System.out.println(answer);
    }
    private int right(int N, int maxR, int[] sumR, int[] rightP) {
        int maxanswer = Integer.MIN_VALUE;
        for (int i = maxR; 0 < i; i--) {
            int temp = sumR[Math.min(N, i)];
            if (i < maxR) {
                PriorityQueue<Integer> rightQ = new PriorityQueue<>(Comparator.naturalOrder());
                for(int j = 0; j < i ; j++) {
                    if (rightP[j] < 0) {
                        rightQ.add(rightP[j]);
                    }
                }
                for (int j = 0; j < maxR - i; j++) {
                    if (rightQ.isEmpty()) {
                        break;
                    }
                    temp -= rightQ.poll();
                }
            }
            maxanswer = Math.max(maxanswer, temp);
        }
        return maxanswer;
    }
    private int left(int N, int maxL, int[] sumL, int[] leftP) {
        int maxanswer = Integer.MIN_VALUE;
        for (int i = maxL; 0 < i; i--) {
            int temp = sumL[Math.min(N, i)];
            if (i < maxL) {
                PriorityQueue<Integer> leftQ = new PriorityQueue<>(Comparator.naturalOrder());
                for(int j = 0; j < i; j++) {
                    if (leftP[j] < 0) {
                        leftQ.add(leftP[j]);
                    }
                }
                for (int j = 0; j < maxL - i; j++) {
                    if (leftQ.isEmpty()) {
                        break;
                    }
                    temp -= leftQ.poll();
                }
            }
            maxanswer = Math.max(maxanswer, temp);
        }
        return maxanswer;
    }
    private int left_and_right(int N, int K, int maxL, int[] sumL, int[] leftP, int[] sumR, int[] rightP) {
        int maxanswer = Integer.MIN_VALUE;
        int maxLanswer = Integer.MIN_VALUE;
        int maxRanswer = Integer.MIN_VALUE;
        for (int i = maxL; 0 < i; i--) {
            int tempL = sumL[Math.min(N, i)];
            if (i < maxL) {
                PriorityQueue<Integer> leftQ = new PriorityQueue<>(Comparator.naturalOrder());
                for(int j = 0; j < i; j++) {
                    if (leftP[j] < 0) {
                        leftQ.add(leftP[j]);
                    }
                }
                for (int j = 0; j < maxL - i; j++) {
                    if (leftQ.isEmpty()) {
                        break;
                    }
                    if (leftP[j] < 0) {
                        tempL -= leftQ.poll();
                    }
                }
            }
            maxLanswer = Math.max(maxLanswer, tempL);
            for (int j = K - maxL; 0 < j; j--) {
                int tempR = sumR[Math.min(N, j)];
                if (j < K - maxL) {
                    PriorityQueue<Integer> rightQ = new PriorityQueue<>(Comparator.naturalOrder());
                    for(int k = 0; k < j; k++) {
                        if (rightP[k] < 0) {
                            rightQ.add(rightP[k]);
                        }
                    }
                    for (int k = 0; k < K - maxL - j; k++) {
                        if (rightQ.isEmpty()) {
                            break;
                        }
                        tempR -= rightQ.poll();
                    }
                }
                maxRanswer = Math.max(maxRanswer, tempR);

            }
            maxanswer = Math.max(maxanswer, maxLanswer+maxRanswer);
        }
        return maxanswer;

    }
}

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