Question:
import java.util.Arrays;
import java.util.Comparator;
import java.util.TreeSet;

public class Main {

  private static void solve() {
    int n = ni();
    int[] a = na(n * n);

    int[][] h = new int[n][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        h[i][j] = Math.min(Math.min(i, n - i - 1), Math.min(j, n - j - 1));
      }
    }

    boolean[][] ved = new boolean[n][n];
    int ret = 0;
    for (int v : a) {
      v--;
      int y = v / n;
      int x = v % n;
      ret += h[y][x];
      ved[y][x] = true;
      dfs(y, x, h, ved);
    }
    System.out.println(ret);

  }

  private static int[][] dir = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } };

  private static void dfs(int y, int x, int[][] h, boolean[][] ved) {
    int n = h.length;
    for (int[] d : dir) {
      int ny = y + d[0];
      int nx = x + d[1];
      if (ny < 0 || ny >= n || nx < 0 || nx >= n)
        continue;

      int nd = h[y][x] + (ved[y][x] ? 0 : 1);
      if (nd < h[ny][nx]) {
        h[ny][nx] = nd;
        dfs(ny, nx, h, ved);
      }
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

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

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

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

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}

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


Question:
public class Main {

  private static void solve() {
    int n = ni();
    char[] s = ns();

    System.out.println(solve(s));

    // int d = 10;
    // for (int i = 0; i < Math.pow(3, d); i++) {
    // char[] s = new char[d];
    // int v = i;
    // for (int j = 0; j < d; j++) {
    // s[j] = (char) (v % 3 + 1 + '0');
    // v /= 3;
    // }
    //
    // int ret = solve(s);
    // int ret3 = solve3(s);
    // if (ret != ret3) {
    // System.out.println(new String(s) + " " + ret + " " + ret3 + "NG");
    // }
    // }

  }

  private static int solve(char[] s) {

    int odd = 0;
    int n = s.length;
    for (int i = 0; i < n; i++) {
      int d = s[i] - '0';
      int m = n - 1;
      int r = i;
      int f = (r | (m - r)) == m ? 1 : 0;
      odd += d * f;
      odd %= 2;
    }

    int[] cnt = new int[4];
    for (char c : s) {
      cnt[c - '0']++;
    }
    if (cnt[1] > 0 && cnt[3] > 0 && cnt[2] == 0) {
      char[] to = new char[n - 1];
      for (int i = 0; i < n - 1; i++) {
        int d = Math.abs(s[i] - s[i + 1]);
        to[i] = (char) ((d == 2 ? 1 : 0) + '0');
      }
      return solve(to) == 1 ? 2 : 0;

    } else {
      return odd;
    }

  }

  private static int solve3(char[] s) {
    int n = s.length;
    int[][] a = new int[n + 1][n];
    for (int i = 0; i < n; i++) {
      a[0][i] = s[i] - '0';
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n - i - 1; j++) {
        a[i + 1][j] = Math.abs(a[i][j] - a[i][j + 1]);
      }
    }
    return a[n - 1][0];
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

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

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

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

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}

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


Question:
public class Main {

  private static void solve() {
    int n = ni();
    char[] s = ns();

    System.out.println(solve(s));

    // int d = 10;
    // for (int i = 0; i < Math.pow(3, d); i++) {
    // char[] s = new char[d];
    // int v = i;
    // for (int j = 0; j < d; j++) {
    // s[j] = (char) (v % 3 + 1 + '0');
    // v /= 3;
    // }
    //
    // int ret = solve(s);
    // int ret3 = solve3(s);
    // if (ret != ret3) {
    // System.out.println(new String(s) + " " + ret + " " + ret3 + "NG");
    // }
    // }

  }

  private static int solve(char[] s) {

    int odd = 0;
    int n = s.length;
    for (int i = 0; i < n; i++) {
      int d = s[i] - '0';
      int m = n - 1;
      int r = i;
      int f = (r | (m - r)) == m ? 1 : 0;
      odd += d * f;
      odd %= 2;
    }

    int[] cnt = new int[4];
    for (char c : s) {
      cnt[c - '0']++;
    }
    if (cnt[1] > 0 && cnt[3] > 0 && cnt[2] == 0) {
      char[] to = new char[n - 1];
      for (int i = 0; i < n - 1; i++) {
        int d = Math.abs(s[i] - s[i + 1]);
        to[i] = (char) ((d == 2 ? 1 : 0) + '0');
      }
      return solve(to) == 1 ? 2 : 0;

    } else {
      return odd;
    }

  }

  private static int solve3(char[] s) {
    int n = s.length;
    int[][] a = new int[n + 1][n];
    for (int i = 0; i < n; i++) {
      a[0][i] = s[i] - '0';
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n - i - 1; j++) {
        a[i + 1][j] = Math.abs(a[i][j] - a[i][j + 1]);
      }
    }
    return a[n - 1][0];
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

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

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

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

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}

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


Question:
public class Main {

  private static void solve() {
    int n = ni();
    double l = nl();
    double[] phi = new double[n];
    for (int i = 0; i < n; i++) {
      phi[i] = Math.PI * 2 * nl() / l;
    }

    double x = 0;
    double y = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        double theta = (phi[i] + phi[j]) / 2;
        double cx = Math.cos(theta);
        double cy = Math.sin(theta);

        double dx = Math.cos(theta + Math.PI);
        double dy = Math.sin(theta + Math.PI);

        x -= cx * (j - i - 1) + dx * (i + (n - j - 1));
        y -= cy * (j - i - 1) + dy * (i + (n - j - 1));
      }
    }
    long total = (long) n * (n - 1) * (n - 2) / 6;
    System.out.printf("%.12f %.12f\n", x / total, y / total);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

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

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

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

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}

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


Question:
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Main {
  private static void solve() {
    int n = ni();
    int[][] a = ntable(n, n - 1);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n - 1; j++) {
        a[i][j]--;
      }
    }
    Map<Integer, Integer> map = new HashMap<>();
    int inf = 10000;
    int ptr = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        map.put(i * inf + j, ptr);
        map.put(j * inf + i, ptr);
        ptr++;
      }
    }

    int[][] e = new int[n][n - 1];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n - 1; j++) {
        e[i][j] = map.get(i * inf + a[i][j]);
      }
    }

    int m = ptr;
    int[] from = new int[m * 2];
    int[] to = new int[m * 2];

    ptr = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n - 2; j++) {
        from[ptr] = e[i][j];
        to[ptr] = e[i][j + 1];
        ptr++;
      }
    }
    from = Arrays.copyOf(from, ptr);
    to = Arrays.copyOf(to, ptr);
    int[][] g = packD(m, from, to);

    int[] v = sortTopologically(g);
    if (v == null) {
      System.out.println(-1);
      return;
    }

    int[] dp = new int[m];
    for (int i : v) {
      for (int nex : g[i]) {
        dp[nex] = Math.max(dp[nex], dp[i] + 1);
      }
    }

    System.out.println(Arrays.stream(dp).max().getAsInt() + 1);

  }

  public static int[] sortTopologically(int[][] g) {
    int n = g.length;
    int[] ec = new int[n];
    for (int i = 0; i < n; i++) {
      for (int to : g[i])
        ec[to]++;
    }
    int[] ret = new int[n];
    int q = 0;

    // sources
    for (int i = 0; i < n; i++) {
      if (ec[i] == 0)
        ret[q++] = i;
    }

    for (int p = 0; p < q; p++) {
      for (int to : g[ret[p]]) {
        if (--ec[to] == 0)
          ret[q++] = to;
      }
    }
    // loop
    for (int i = 0; i < n; i++) {
      if (ec[i] > 0)
        return null;
    }
    return ret;
  }

  static int[][] packD(int n, int[] from, int[] to) {
    int[][] g = new int[n][];
    int[] p = new int[n];
    for (int f : from)
      p[f]++;
    for (int i = 0; i < n; i++)
      g[i] = new int[p[i]];
    for (int i = 0; i < from.length; i++) {
      g[from[i]][--p[from[i]]] = to[i];
    }
    return g;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

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

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

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

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}

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


Question:
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Comparator;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.TreeSet;

public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] from = new int[M];
    int[] to = new int[M];

    for (int i = 0; i < M; i++) {
      from[i] = sc.nextInt() - 1;
      to[i] = sc.nextInt() - 1;
    }

    int Q = sc.nextInt();
    int[][] query = sc.nextIntTable(Q, 3);
    for (int i = 0; i < Q; i++) {
      query[i][0]--;
    }

    int[][] g = packU(N, from, to);
    int[] color = new int[N];
    int[] len = new int[N];
    Arrays.fill(len, -1);
    for (int i = Q - 1; i >= 0; i--) {
      dij(query[i][0], color, query[i][2], len, query[i][1], g);
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < N; i++) {
      sb.append(color[i]);
      sb.append("\n");
    }
    System.out.print(sb);
  }

  public static int[][] packU(int n, int[] from, int[] to) {
    int[][] g = new int[n][];
    int[] p = new int[n];
    for (int f : from)
      p[f]++;
    for (int t : to)
      p[t]++;
    for (int i = 0; i < n; i++)
      g[i] = new int[p[i]];
    for (int i = 0; i < from.length; i++) {
      g[from[i]][--p[from[i]]] = to[i];
      g[to[i]][--p[to[i]]] = from[i];
    }
    return g;
  }

  private static ArrayDeque<int[]> queue = new ArrayDeque<>();
  private static void dij(int now, int[] color, int nowColor, int[] len, int d, int[][] g) {
    queue.add(new int[] {now, d});

    while (queue.size() > 0) {
      int[] v = queue.poll();

      if (len[v[0]] < 0) {
        color[v[0]] = nowColor;
      }

      if (len[v[0]] >= v[1]) {
        continue;
      }

      len[v[0]] = v[1];

      if (v[1] == 0) {
        continue;
      }

      for (int u : g[v[0]]) {
        if (len[u] >= v[1] - 1) {
          continue;
        }
        queue.add(new int[] {u, v[1] - 1});
      }
    }
  }
}

class FastScanner {
  public static String debug = null;

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

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        if (debug != null) {
          buflen = debug.length();
          buffer = debug.getBytes();
          debug = "";
          eos = true;
        } else {
          buflen = in.read(buffer);
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen < 0) {
        eos = true;
        return false;
      } else if (buflen == 0) {
        return false;
      }
    }
    return true;
  }

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

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

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr]))
      ptr++;
  }

  public boolean isEOS() {
    return this.eos;
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

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

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

  public int nextInt() {
    return (int) nextLong();
  }

  public long[] nextLongList(int n) {
    return nextLongTable(1, n)[0];
  }

  public int[] nextIntList(int n) {
    return nextIntTable(1, n)[0];
  }

  public long[][] nextLongTable(int n, int m) {
    long[][] ret = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        ret[i][j] = nextLong();
      }
    }
    return ret;
  }

  public int[][] nextIntTable(int n, int m) {
    int[][] ret = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        ret[i][j] = nextInt();
      }
    }
    return ret;
  }
}

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


Question:
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Comparator;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.TreeSet;

public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] from = new int[M];
    int[] to = new int[M];

    for (int i = 0; i < M; i++) {
      from[i] = sc.nextInt() - 1;
      to[i] = sc.nextInt() - 1;
    }

    int Q = sc.nextInt();
    int[][] query = sc.nextIntTable(Q, 3);
    for (int i = 0; i < Q; i++) {
      query[i][0]--;
    }

    int[][] g = packU(N, from, to);
    int[] color = new int[N];
    int[] len = new int[N];
    Arrays.fill(len, -1);
    for (int i = Q - 1; i >= 0; i--) {
      dij(query[i][0], color, query[i][2], len, query[i][1], g);
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < N; i++) {
      sb.append(color[i]);
      sb.append("\n");
    }
    System.out.print(sb);
  }

  public static int[][] packU(int n, int[] from, int[] to) {
    int[][] g = new int[n][];
    int[] p = new int[n];
    for (int f : from)
      p[f]++;
    for (int t : to)
      p[t]++;
    for (int i = 0; i < n; i++)
      g[i] = new int[p[i]];
    for (int i = 0; i < from.length; i++) {
      g[from[i]][--p[from[i]]] = to[i];
      g[to[i]][--p[to[i]]] = from[i];
    }
    return g;
  }

  private static ArrayDeque<int[]> queue = new ArrayDeque<>();
  private static void dij(int now, int[] color, int nowColor, int[] len, int d, int[][] g) {
    queue.add(new int[] {now, d});

    while (queue.size() > 0) {
      int[] v = queue.poll();

      if (len[v[0]] < 0) {
        color[v[0]] = nowColor;
      }

      if (len[v[0]] >= v[1]) {
        continue;
      }

      len[v[0]] = v[1];

      if (v[1] == 0) {
        continue;
      }

      for (int u : g[v[0]]) {
        if (len[u] >= v[1] - 1) {
          continue;
        }
        queue.add(new int[] {u, v[1] - 1});
      }
    }
  }
}

class FastScanner {
  public static String debug = null;

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

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        if (debug != null) {
          buflen = debug.length();
          buffer = debug.getBytes();
          debug = "";
          eos = true;
        } else {
          buflen = in.read(buffer);
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen < 0) {
        eos = true;
        return false;
      } else if (buflen == 0) {
        return false;
      }
    }
    return true;
  }

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

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

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr]))
      ptr++;
  }

  public boolean isEOS() {
    return this.eos;
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

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

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

  public int nextInt() {
    return (int) nextLong();
  }

  public long[] nextLongList(int n) {
    return nextLongTable(1, n)[0];
  }

  public int[] nextIntList(int n) {
    return nextIntTable(1, n)[0];
  }

  public long[][] nextLongTable(int n, int m) {
    long[][] ret = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        ret[i][j] = nextLong();
      }
    }
    return ret;
  }

  public int[][] nextIntTable(int n, int m) {
    int[][] ret = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        ret[i][j] = nextInt();
      }
    }
    return ret;
  }
}

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


Question:
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Comparator;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.TreeSet;

public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] from = new int[M];
    int[] to = new int[M];

    for (int i = 0; i < M; i++) {
      from[i] = sc.nextInt() - 1;
      to[i] = sc.nextInt() - 1;
    }

    int Q = sc.nextInt();
    int[][] query = sc.nextIntTable(Q, 3);
    for (int i = 0; i < Q; i++) {
      query[i][0]--;
    }

    int[][] g = packU(N, from, to);
    int[] color = new int[N];
    int[] len = new int[N];
    Arrays.fill(len, -1);
    for (int i = Q - 1; i >= 0; i--) {
      dij(query[i][0], color, query[i][2], len, query[i][1], g);
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < N; i++) {
      sb.append(color[i]);
      sb.append("\n");
    }
    System.out.print(sb);
  }

  public static int[][] packU(int n, int[] from, int[] to) {
    int[][] g = new int[n][];
    int[] p = new int[n];
    for (int f : from)
      p[f]++;
    for (int t : to)
      p[t]++;
    for (int i = 0; i < n; i++)
      g[i] = new int[p[i]];
    for (int i = 0; i < from.length; i++) {
      g[from[i]][--p[from[i]]] = to[i];
      g[to[i]][--p[to[i]]] = from[i];
    }
    return g;
  }

  private static ArrayDeque<int[]> queue = new ArrayDeque<>();
  private static void dij(int now, int[] color, int nowColor, int[] len, int d, int[][] g) {
    queue.add(new int[] {now, d});

    while (queue.size() > 0) {
      int[] v = queue.poll();

      if (len[v[0]] < 0) {
        color[v[0]] = nowColor;
      }

      if (len[v[0]] >= v[1]) {
        continue;
      }

      len[v[0]] = v[1];

      if (v[1] == 0) {
        continue;
      }

      for (int u : g[v[0]]) {
        if (len[u] >= v[1] - 1) {
          continue;
        }
        queue.add(new int[] {u, v[1] - 1});
      }
    }
  }
}

class FastScanner {
  public static String debug = null;

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

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        if (debug != null) {
          buflen = debug.length();
          buffer = debug.getBytes();
          debug = "";
          eos = true;
        } else {
          buflen = in.read(buffer);
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen < 0) {
        eos = true;
        return false;
      } else if (buflen == 0) {
        return false;
      }
    }
    return true;
  }

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

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

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr]))
      ptr++;
  }

  public boolean isEOS() {
    return this.eos;
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

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

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

  public int nextInt() {
    return (int) nextLong();
  }

  public long[] nextLongList(int n) {
    return nextLongTable(1, n)[0];
  }

  public int[] nextIntList(int n) {
    return nextIntTable(1, n)[0];
  }

  public long[][] nextLongTable(int n, int m) {
    long[][] ret = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        ret[i][j] = nextLong();
      }
    }
    return ret;
  }

  public int[][] nextIntTable(int n, int m) {
    int[][] ret = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        ret[i][j] = nextInt();
      }
    }
    return ret;
  }
}

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


Question:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int[] A = sc.nextIntList(N);
    int count = 0;
    for (int a : A) {
      if (a % 2 == 1) {
        count ++;
      }
    }
    System.out.println(count % 2 == 0 ? "YES" : "NO");
  }

}

class FastScanner {
	public static String debug = null;

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

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

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

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

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

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

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

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


Question:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    long[] A = new long[N];
    long[] B = new long[N];
    for (int i = 0; i < N; i ++) {
      A[i] = sc.nextLong();
      B[i] = sc.nextLong();
    }

    StarrySkyTree sst = new ConcreteTree(N);
    for (int i = 0; i < N; i++) {
      sst.queryUpdate(i, i + 1, A[i]);
    }

    long count = 0;
    for (int i = N - 1; i >= 0; i -- ) {
      long v = sst.query(i, i + 1);
      long mod = (B[i] - v % B[i]) % B[i];
      count += mod;
      sst.queryUpdate(0, i + 1, mod);
    }
    System.out.println(count);
  }

}

class ConcreteTree extends StarrySkyTree {
  public ConcreteTree(int size) {
      super(size, 0);
  }

  @Override
  public long calcAdd(long a, long b) {
      return a + b;
  }

  @Override
  public long calcGet(long a, long b) {
      return Math.max(a, b);
  }
}

abstract class StarrySkyTree {
  private final long UNIT;
  private final long[] tree;
  private final long[] add;
  private final int size;

  public StarrySkyTree(int size, int unit) {
      this.UNIT = unit;
      size = 1 << (32 - Integer.numberOfLeadingZeros(size));

      this.tree = new long[size * 2];
      this.add = new long[size * 2];
      for (int i = 0; i < size * 2; i ++) {
          this.tree[i] = UNIT;
          this.add[i] = UNIT;
      }
      this.size = size;
  }

  public abstract long calcAdd(long a, long b);
  public abstract long calcGet(long a, long b);

  private void queryUpdate(int a, int b, int k, int l, int r, long n) {
      if (b <= l || r <= a) {
          return;
      }

      if (a <= l && r <= b) {
          add[k] = calcAdd(add[k], n);
          while (k > 0) {
              k = (k - 1) / 2;
              long x1 = tree[2 * k + 1];
              long x2 = add[2 * k + 1];
              long y1 = tree[2 * k + 2];
              long y2 = add[2 * k + 2];
              long x = calcAdd(x1, x2);
              long y = calcAdd(y1, y2);
              tree[k] = calcGet(x, y);
          }
      } else {
          queryUpdate(a, b, 2 * k + 1, l, (l + r) / 2, n);
          queryUpdate(a, b, 2 * k + 2, (l + r) / 2, r, n);
      }
  }

  private long query(int a, int b, int k, int l, int r) {
      if (b <= l || r <= a) {
          return UNIT;
      }

      if (a <= l && r <= b) {
          long x1 = tree[k];
          long x2 = add[k];
          return calcAdd(x1, x2);
      } else {
          long ql = query(a, b, 2 * k + 1, l, (l + r) / 2);
          long qr = query(a, b, 2 * k + 2, (l + r) / 2, r);
          long x = calcGet(ql, qr);
          return calcAdd(x, add[k]);
      }
  }

  public long query(int a, int b) {
      return query(a, b, 0, 0, size);
  }

  public void queryUpdate(int a, int b, long n) {
      queryUpdate(a, b, 0, 0, size, n);
  }
}

class FastScanner {
	public static String debug = null;

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

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

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

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

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

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

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

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


Question:
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int[][] array = new int[N][2];
    int[][] list = new int[N][];

    int[] count = new int[N];
    for (int i = 1; i < N; i ++) {
      array[i][0] = i;
      array[i][1] = sc.nextInt() - 1;

      count[array[i][1]] ++;
    }
    int[] ptr = new int[N];
    for (int i = 0; i < N; i ++) {
      list[i] = new int[count[i]];
    }
    for (int[] v : array) {
      if (v[0] != 0) {
        int i = v[1];
        list[i][ptr[i] ++] = v[0];
      }
    }

    Arrays.fill(memo, -1);
    int ret = dfs(0, list);
    System.out.println(ret);
  }

  private static int[] memo = new int[100010];
  private static int dfs(int idx, int[][] list) {
    if (memo[idx] >= 0) {
      return memo[idx];
    }

    List<Integer> tmp = new ArrayList<>();
    for (int v : list[idx]) {
      tmp.add(dfs(v, list));
    }
    Collections.sort(tmp);

    for (int i = 0; i < tmp.size(); i ++) {
      int v = tmp.get(i);
      tmp.set(i, v + (tmp.size() - i));
    }

    int ret = 0;
    for (int v : tmp) {
      ret = Math.max(v, ret);
    }
    memo[idx] = ret;
    return ret;
  }

}

class FastScanner {
	public static String debug = null;

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

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

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

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

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

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

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

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


Question:
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] a = sc.nextIntList(N);
		int[] idx = new int[N + 1];

		SegmentTreeRMQ st = new SegmentTreeRMQ(N);
		for (int i = 0; i < N; i++) {
			st.update(i, a[i]);
			idx[a[i]] = i;
		}

		long ret = calc(idx, st, 0, N);
		System.out.println(ret);
	}

	private static long calc(int[] idx, SegmentTreeRMQ st, int left, int right) {
		if (left == right) {
			return 0;
		}

		int min = st.min(left, right);
		int i = idx[min];
		long ret = (long) min * (right - i) * (i - left + 1);
		ret += calc(idx, st, i + 1, right);
		ret += calc(idx, st, left, i);
		return ret;
	}
}

class SegmentTreeRMQ {
	public int M, H, N;
	public int[] st;

	public SegmentTreeRMQ(int n) {
		N = n;
		M = Integer.highestOneBit(Math.max(N - 1, 1)) << 2;
		H = M >>> 1;
		st = new int[M];
		Arrays.fill(st, 0, M, Integer.MAX_VALUE);
	}

	public SegmentTreeRMQ(int[] a) {
		N = a.length;
		M = Integer.highestOneBit(Math.max(N - 1, 1)) << 2;
		H = M >>> 1;
		st = new int[M];
		for (int i = 0; i < N; i++) {
			st[H + i] = a[i];
		}
		Arrays.fill(st, H + N, M, Integer.MAX_VALUE);
		for (int i = H - 1; i >= 1; i--)
			propagate(i);
	}

	public void update(int pos, int x) {
		st[H + pos] = x;
		for (int i = (H + pos) >>> 1; i >= 1; i >>>= 1)
			propagate(i);
	}

	private void propagate(int i) {
		st[i] = Math.min(st[2 * i], st[2 * i + 1]);
	}

	public int min(int l, int r) {
		return l >= r ? 0 : min(l, r, 0, H, 1);
	}

	private int min(int l, int r, int cl, int cr, int cur) {
		if (l <= cl && cr <= r) {
			return st[cur];
		} else {
			int mid = cl + cr >>> 1;
			int ret = Integer.MAX_VALUE;
			if (cl < r && l < mid) {
				ret = Math.min(ret, min(l, r, cl, mid, 2 * cur));
			}
			if (mid < r && l < cr) {
				ret = Math.min(ret, min(l, r, mid, cr, 2 * cur + 1));
			}
			return ret;
		}
	}

}

class FastScanner {
	public static String debug = null;

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

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

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

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

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

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

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

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


Question:
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

public class Main {

	private static int[] primes = sieveAtkin(100000);

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		long[] s = sc.nextLongList(N);
		long[] t = new long[N];

		for (int i = 0; i < N; i ++) {
			if (s[i] == 1) {
				t[i] = 1;
				continue;
			}

			long x = s[i];
			long y = 1;
			for (int p : primes) {
				long q = (long)p * p * p;
				if (q > x) {
					break;
				}
				while (x % q == 0) {
					x /= q;
					s[i] /= q;
				}

				long sp = (long)p * p;
				if (s[i] % sp == 0) {
					y *= p;
					x /= sp;
				} else if (s[i] % p == 0) {
					y *= sp;
					x /= p;
				}
			}
			long rx = sqrtL(x);
			y *= rx < 0 ? x * x : rx;
			t[i] = y;
		}

		Map<Long, Long> rev = new HashMap<>();
		Map<Long, Integer> map = new HashMap<>();
		for (int i = 0; i < N; i ++) {
			int a = !map.containsKey(s[i]) ? 0 : map.get(s[i]);
			int b = !map.containsKey(t[i]) ? 0 : map.get(t[i]);

			if (s[i] == 1) {
				map.put(s[i], a + 1);
				rev.put(1L, 1L);
			} else {

				map.put(s[i], a + 1);
				map.put(t[i], b);

				rev.put(s[i], t[i]);
				rev.put(t[i], s[i]);
			}
		}

		int count = 0;
		for (Long l : rev.keySet()) {
			if (l != 1L) {
				int max = Math.max(map.get(l), map.get(rev.get(l)));
				count += max;
			}
		}
		count /= 2;
		if (rev.containsKey(1L)) {
			count ++;
		}

		System.out.println(count);

	}

	public static long sqrtL(long N) {
		long left = (long)(Math.sqrt(N) * 0.99);
		long right = (long)(Math.sqrt(N) * 1.01);

		while (left <= right) {
			long mid = (left + right) / 2;
			long cmp = N - mid * mid;
			if (cmp == 0) {
				return mid;
			} else if (cmp > 0) {
				left = mid + 1;
			} else {
				right = mid - 1;
			}
		}
		return -1;
	}

	public static int[] sieveAtkin(int size) {
		boolean[] isPrime = new boolean[size + 1];
		int sqrtN = (int) Math.sqrt(size);
		int n;
		for (int x = 1; x <= sqrtN; ++x) {
			for (int y = 1; y <= sqrtN; ++y) {
				n = 4 * x * x + y * y;
				if (n <= size && (n % 12 == 1 || n % 12 == 5)) {
					isPrime[n] = !isPrime[n];
				}
				n = 3 * x * x + y * y;
				if (n <= size && n % 12 == 7) {
					isPrime[n] = !isPrime[n];
				}
				n = 3 * x * x - y * y;
				if (x > y && n <= size && n % 12 == 11) {
					isPrime[n] = !isPrime[n];
				}
			}
		}

		for (n = 5; n <= sqrtN; ++n) {
			if (isPrime[n]) {
				for (int k = n * n; k <= size; k += n * n) {
					isPrime[k] = false;
				}
			}
		}
		isPrime[2] = isPrime[3] = true;

		int[] ret = new int[size];
		int count = 0;
		for (int i = 1; i < size; i ++) {
			if (isPrime[i]) {
				ret[count ++] = i;
			}
		}
		return Arrays.copyOf(ret, count);
	}
}

class FastScanner {
	public static String debug = null;

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

	public FastScanner() {
//		try {
//			this.in =new FileInputStream("13.txt");
//		} catch (Exception e) {
//		}
	}

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

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

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

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

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

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

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


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
public class Main {
  public static void main(String[] args) {
    Main m = new Main();
    m.run();
  }
  private void run() {
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
      String[] s = br.readLine().split("\\s+");
      int n = Integer.parseInt(s[0]);
      int m = Integer.parseInt(s[1]);
      int[] a = Arrays.stream(br.readLine().split("\\s+"))
        .mapToInt(Integer::parseInt).toArray();
      PriorityQueue<Integer> pq = new PriorityQueue<>();
      PriorityQueue<Operation> op = new PriorityQueue<>(Comparator.reverseOrder());
      for (int i=0;i<n;i++) pq.offer(a[i]);
      for (int i=0;i<m;i++) {
        s = br.readLine().split("\\s+");
        int b = Integer.parseInt(s[0]);
        int c = Integer.parseInt(s[1]);
        op.offer(new Operation(b,c));
      }
      for (int i=0;i<m;i++) {
        Operation o = op.poll();
        for (int j=0;j<o.b;j++) {
          int d = pq.peek();
          if (d >= o.c) break;
          d = pq.poll();
          pq.offer(o.c);
        }
      }
      long sum = 0L;
      for (int i=0;i<n;i++) sum += (long)pq.poll();
      System.out.println(sum);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  private class Operation implements Comparable<Operation> {
    int b,c;
    Operation(int b,int c) {
      this.b = b;
      this.c = c;
    }
    @Override
    public int compareTo(Operation other) {
      if (c == other.c) return Integer.compare(b,other.b);
      return Integer.compare(c,other.c);
    }
  }
}

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


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

public class Main {

    private int n;
    private TreeMap<Integer,Integer> a;

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

    private void set() {
	try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
	    n = Integer.parseInt(br.readLine());
	    a = new TreeMap<>();
	    for (String str : br.readLine().split(" ")) {
		int ai = Integer.parseInt(str);
		int num = a.getOrDefault(ai,0) + 1;
		a.put(ai,num);
	    }
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    private void solve() {
	set();
	int pair = 0;
	while (!a.isEmpty()) {
	    int ai = a.lastKey();
	    int complement = 2*Integer.highestOneBit(ai) - ai;
	    if (ai == complement) {
		int num = a.get(ai);
		pair += num/2;
		a.remove(ai);
		continue;
	    }
	    if (a.containsKey(complement)) {
		int numA = a.get(ai);
		int numC = a.get(complement);
		if (numA < numC) {
		    pair += numA;
		    a.remove(ai);
		    a.put(complement,numC-numA);
		} else {
		    pair += numC;
		    a.remove(ai);
		    a.remove(complement);
		}
		continue;
	    }
	    a.remove(ai);
	}
	System.out.println(pair);
    }
}

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


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

public class Main {

    private int n;
    private TreeMap<Integer,Integer> a;

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

    private void set() {
	try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
	    n = Integer.parseInt(br.readLine());
	    a = new TreeMap<>();
	    for (String str : br.readLine().split(" ")) {
		int ai = Integer.parseInt(str);
		int num = a.getOrDefault(ai,0) + 1;
		a.put(ai,num);
	    }
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    private void solve() {
	set();
	int pair = 0;
	while (!a.isEmpty()) {
	    int ai = a.lastKey();
	    int complement = 2*Integer.highestOneBit(ai) - ai;
	    if (ai == complement) {
		int num = a.get(ai);
		pair += num/2;
		a.remove(ai);
		continue;
	    }
	    if (a.containsKey(complement)) {
		int numA = a.get(ai);
		int numC = a.get(complement);
		if (numA < numC) {
		    pair += numA;
		    a.remove(ai);
		    a.put(complement,numC-numA);
		} else {
		    pair += numC;
		    a.remove(ai);
		    a.remove(complement);
		}
		continue;
	    }
	    a.remove(ai);
	}
	System.out.println(pair);
    }
}

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


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

public class Main {

    private int n;
    private TreeMap<Integer,Integer> a;

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

    private void set() {
	try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
	    n = Integer.parseInt(br.readLine());
	    a = new TreeMap<>();
	    for (String str : br.readLine().split(" ")) {
		int ai = Integer.parseInt(str);
		int num = a.getOrDefault(ai,0) + 1;
		a.put(ai,num);
	    }
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    private void solve() {
	set();
	int pair = 0;
	while (!a.isEmpty()) {
	    int ai = a.lastKey();
	    int complement = 2*Integer.highestOneBit(ai) - ai;
	    if (ai == complement) {
		int num = a.get(ai);
		pair += num/2;
		a.remove(ai);
		continue;
	    }
	    if (a.containsKey(complement)) {
		int numA = a.get(ai);
		int numC = a.get(complement);
		if (numA < numC) {
		    pair += numA;
		    a.remove(ai);
		    a.put(complement,numC-numA);
		} else {
		    pair += numC;
		    a.remove(ai);
		    a.remove(complement);
		}
		continue;
	    }
	    a.remove(ai);
	}
	System.out.println(pair);
    }
}

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


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

public class Main implements Runnable {

    private int n;
    private long x;

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

    private void set() {
	try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
	    String[] parts = br.readLine().split("[\\s]+");
	    n = Integer.parseInt(parts[0]);
	    x = Long.parseLong(parts[1]);
	} catch (IOException e) {
	    e.printStackTrace();
	}
    }

    @Override
    public void run() {
	set();
	long[] length = new long[n+1];
	long[] number = new long[n+1];
	length[0] = 1;
	number[0] = 1;
	for (int i=1;i<n+1;i++) {
	    length[i] = 2*length[i-1]+3;
	    number[i] = 2*number[i-1]+1;
	}
	long num = 0;
	long rem = x;
	for (int i=n;i>=0;i--) {
	    if (i == 0) {
		num++;
		break;
	    }

	    if (rem == 1) break;
	    if (rem == length[i]) {
		num += number[i];
		break;
	    }
	    if (rem == length[i-1]+2) {
		num += number[i-1]+1;
		break;
	    }

	    if (rem < length[i-1]+2) {
		rem = rem - 1;
	    } else {
		rem = rem - (length[i-1]+2);
		num += number[i-1]+1;
	    }
	}
	System.out.println(num);
    }

    private long pow(long base,long power) {
	if (power == 0) return 1;
	if (power%2 == 0) {
	    long h = pow(base,power/2);
	    return h*h;
	} else {
	    return base*pow(base,power-1);
	}
    }
}

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


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

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s = br.readLine();
    br.close();
    int p = s.length() - s.replaceAll("\\+","").length();
    int m = s.length() - p;
    System.out.println(p-m);
  }

}

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


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.TreeSet;
public class Main {
  public static void main(String[] args) {
    Main m = new Main();
    m.run();
  }
  private void run() {
    int n = 0;
    int[] a = new int[0];
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
      n = Integer.parseInt(br.readLine());
      a = Arrays.stream(br.readLine().split("\\s+"))
        .mapToInt(Integer::parseInt).toArray();
    } catch (IOException e) {
      e.printStackTrace();
    }
    TreeSet<Integer> s = new TreeSet<>();
    s.add(0);
    s.add(n+1);
    int[] b = new int[n];
    for (int i=0;i<n;i++) b[a[i]-1] = i+1;
    long m = 0L;
    for (int i=0;i<n;i++) {
      s.add(b[i]);
      m += (long)(i+1)*(long)(b[i]-s.lower(b[i]))*(long)(s.higher(b[i])-b[i]);
    }
    System.out.println(m);
  }
}

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


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

public class Main {
    static final long MOD = 1000000007L;
    //static final long MOD = 998244353L;
    static final int INF = 50000000;
    static final int NINF = -500000000;

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

        int N = sc.ni();
        long[][] nums = new long[N][2];
        TreeSet<Long> Ys = new TreeSet<Long>();
        for (int i = 0; i < N; i++) {
        	nums[i] = new long[] {sc.nl(),sc.nl()};
        	Ys.add(nums[i][1]);
        }
        sort(nums);
        HashMap<Long,Integer> hm = new HashMap<Long,Integer>();
        int T = 0;
        for (long y: Ys) {
        	hm.put(y,T);
        	T++;
        }

        SegmentTree st1 = new SegmentTree(T);
        SegmentTree st2 = new SegmentTree(T);
        for (int i = 0; i < T; i++) {
        	st1.update(i, -100000000000L);
        	st2.update(i, -100000000000L);
        }
        long ans = 0;
        for (long[] p: nums) {
        	int index = hm.get(p[1]);
        	long v1 = p[1]-p[0];
        	long v2 = 0-p[0]-p[1];
        	long val = Math.max(st1.query(index,T-1)-v1,st2.query(0, index)-v2);
        	ans = Math.max(ans, val);
        	if (v1 > st1.arr[index])
        		st1.update(index, v1);
        	if (v2 > st2.arr[index])
        		st2.update(index, v2);
        }
        pw.println(ans);
        pw.close();
    }

    //No lazy propagation. 0 indexed. Very fast.
    static class SegmentTree {
    	public long[] tree;
    	public long[] arr;
    	public long NONE;
    	public int N;

    	//Zero initialization
    	public SegmentTree(int n) {
    		N = n;
    		tree = new long[4*N+1];
    		arr = new long[N];
    		NONE = -100000000000L; //set this manually (Long.MIN_VALUE for max-st, Long.MAX_VALUE for min-st, 0 for sum,xor-st, etc.)
    	}

    	public long merge(long a, long b) {
    		return Math.max(a, b); //set this manually
    	}

    	public long query(int i, int j) {
    		return query(0,0,N-1,i,j);
    	}

    	public void update(int arrIndex, long val) {
    		arr[arrIndex] = val;
    		update(0,0,N-1,arrIndex,val);
    	}

    	private long query(int treeIndex, int lo, int hi, int i, int j) {
    		// query for arr[i..j]
    		if (lo > j || hi < i)
    			return NONE;
    		if (i <= lo && j >= hi)
    			return tree[treeIndex];
    		int mid = lo + (hi - lo) / 2;

    		if (i > mid)
    			return query(2 * treeIndex + 2, mid + 1, hi, i, j);
    		else if (j <= mid)
    			return query(2 * treeIndex + 1, lo, mid, i, j);

    		long leftQuery = query(2 * treeIndex + 1, lo, mid, i, mid);
    		long rightQuery = query(2 * treeIndex + 2, mid + 1, hi, mid + 1, j);

    		// merge query results
    		return merge(leftQuery, rightQuery);
    	}

    	private void update(int treeIndex, int lo, int hi, int arrIndex, long val) {
    		if (lo == hi) {
    			tree[treeIndex] = val;
    			return;
    		}

    		int mid = lo + (hi - lo) / 2;

    		if (arrIndex > mid)
    			update(2 * treeIndex + 2, mid + 1, hi, arrIndex, val);
    		else if (arrIndex <= mid)
    			update(2 * treeIndex + 1, lo, mid, arrIndex, val);

    		// merge updates
    		tree[treeIndex] = merge(tree[2 * treeIndex + 1], tree[2 * treeIndex + 2]);
    	}
    }

    public static void sort(long[][] arr) {
    	//Sort an array (immune to quicksort TLE)
    	Random rgen = new Random();
    	for (int i = 0; i < arr.length; i++) {
    		int randomPosition = rgen.nextInt(arr.length);
    		long[] temp = arr[i];
    		arr[i] = arr[randomPosition];
    		arr[randomPosition] = temp;
    	}
    	Arrays.sort(arr, new Comparator<long[]>() {
    		@Override
    		public int compare(long[] arr1, long[] arr2) {
    			if (arr1[0] > arr2[0])
    				return 1;
    			else if (arr1[0] < arr2[0])
    				return -1;
    			else
    				return 0;
    			//Ascending order.
    		}
    	});
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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


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

public class Main {
	//static final long MOD = 1000000007L;
	static final int INF = 1000000007;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);

		int N = sc.ni();
		long[][] cnt = new long[40][60];
		int ints = 0;
		for (int i = 0; i < N; i++) {
			String s = sc.next();

			int ind = s.indexOf(".");
			if (ind==-1) {
				s += ".0";
				ind = s.indexOf(".");
			}
			int M = s.length();
			String str = s.substring(0,ind);
			if (ind < M)
				str += s.substring(ind+1,M);
			long num = Long.parseLong(str);
			int[] pow = new int[2];
			pow[0] = (ind-M+1);
			pow[1] = (ind-M+1);
			while (num % 2 == 0) {
				pow[0] += 1;
				num /= 2;
			}
			while (num % 5 == 0) {
				pow[1] += 1;
				num /= 5;
			}
			if (pow[0] >= 0 && pow[1] >= 0)
				ints += 1;
			cnt[pow[0]+9][pow[1]+9] += 1;
		}

		long ans = 0;

		for (int i = 0; i < cnt.length; i++) {
			for (int j = 0; j < cnt[0].length; j++) {
				for (int a = Math.max(18-i,0); a < cnt.length; a++) {
					for (int b = Math.max(18-j,0); b < cnt[1].length; b++) {
						ans += cnt[i][j]*cnt[a][b];
					}
				}
			}
		}
		ans = (ans-ints)/2;
		pw.println(ans);
		pw.close();
	}

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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


Question:
import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.Point;

public class Main {
	static final long MOD = 998244353L;
	//static final long INF = 1000000000000000007L;
	static String letters = "abcdefghijklmnopqrstuvwxyz";
	//static final long MOD = 1000000007L;
	static final int INF = 1000000007;

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

		int N = sc.ni();
		int S = sc.ni();
		long HALF = MOD/2 + 1;
		int[] nums = new int[N];
		for (int i = 0; i < N; i++)
			nums[i] = sc.ni();
		nums = shuffle(nums);
		Arrays.sort(nums);

		long[][] dp = new long[N+1][S+1]; //num,sum
		dp[0][0] = power(2,N,MOD);
		for (int i = 1; i <= N; i++) {
			for (int j = 0; j <= S; j++) {
				dp[i][j] = dp[i-1][j];
				if (j >= nums[i-1]) {
					dp[i][j] += (dp[i-1][j-nums[i-1]]*HALF);
					dp[i][j] %= MOD;
				}
			}
		}

		pw.println(dp[N][S]);

		pw.close();
	}

	static class SegmentTree {
		public int[] tree;
		public int N;

		//Zero initialization
		public SegmentTree(int n) {
			N = n;
			tree = new int[4*N+1];
		}

		public int query(int treeIndex, int lo, int hi, int i, int j) {
			// query for arr[i..j]
			if (lo > j || hi < i)
				return 0;
			if (i <= lo && j >= hi)
				return tree[treeIndex];
			int mid = lo + (hi - lo) / 2;

			if (i > mid)
				return query(2 * treeIndex + 2, mid + 1, hi, i, j);
			else if (j <= mid)
				return query(2 * treeIndex + 1, lo, mid, i, j);

			int leftQuery = query(2 * treeIndex + 1, lo, mid, i, mid);
			int rightQuery = query(2 * treeIndex + 2, mid + 1, hi, mid + 1, j);

			// merge query results
			return merge(leftQuery, rightQuery);
		}

		public void update(int treeIndex, int lo, int hi, int arrIndex, int val) {
			if (lo == hi) {
				tree[treeIndex] = val;
				return;
			}

			int mid = lo + (hi - lo) / 2;

			if (arrIndex > mid)
				update(2 * treeIndex + 2, mid + 1, hi, arrIndex, val);
			else if (arrIndex <= mid)
				update(2 * treeIndex + 1, lo, mid, arrIndex, val);

			// merge updates
			tree[treeIndex] = merge(tree[2 * treeIndex + 1], tree[2 * treeIndex + 2]);
		}

		public int merge(int a, int b) {
			return Math.max(a,b);
		}
	}

	public static long dist(long[] p1, long[] p2) {
		return (Math.abs(p2[0]-p1[0])+Math.abs(p2[1]-p1[1]));
	}

	//Find the GCD of two numbers
	public static long gcd(long a, long b) {
		if (a < b) return gcd(b,a);
		if (b == 0)
			return a;
		else
			return gcd(b,a%b);
	}

	//Fast exponentiation (x^y mod m)
	public static long power(long x, long y, long m) {
		if (y < 0) return 0L;
		long ans = 1;
		x %= m;
		while (y > 0) {
			if(y % 2 == 1)
				ans = (ans * x) % m;
			y /= 2;
			x = (x * x) % m;
		}
		return ans;
	}

	public static int[] shuffle(int[] array) {
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		return array;
	}

	public static long[] shuffle(long[] array) {
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    long temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		return array;
	}

	public static int[][] shuffle(int[][] array) {
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		return array;
	}

    public static int[][] sort(int[][] array) {
    	//Sort an array (immune to quicksort TLE)

		Arrays.sort(array, new Comparator<int[]>() {
			  @Override
        	  public int compare(int[] a, int[] b) {
				  return a[0]-b[0]; //ascending order
	          }
		});
		return array;
	}

    public static long[][] sort(long[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    long[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<long[]>() {
			  @Override
        	  public int compare(long[] a, long[] b) {
				  if (a[0] < b[0])
					  return -1;
				  else
					  return 1;
	          }
		});
		return array;
	}

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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


Question:
import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();

        BigInteger a = new BigInteger(next()), b = new BigInteger(next());
        System.out.println(a.multiply(b).divide(a.gcd(b)));
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }
}

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


Question:
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int[][] directions25= {{-2,-2},{-2,-1},{-2,0},{-2,1},{-2,2},{-1,-2},{-1,-1},{-1,1},{-1, 2}
	,{0,-2},{0,2},{1,-2},{1,-1},{1,1},{1,2},{2,-2},{2, -1},{2,0},{2,1},{2,2}};
	static int[][] directions4= {{-1,0},{1,0},{0,-1},{0,1}};
	static int ans;
	static int[] parent;//union-find用
	static int[] rank;//union-find用
	static int[][] warp;
	static Queue<int[]> q;
	static int H;
	static int W;
	static int Dh;
	static int Dw;
	static char[][] S;

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

		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int M = sc.nextInt();

		int[] h = new int[H];
		int[] w = new int[W];
		HashSet<String> exists = new HashSet<>();

		for(int i = 0;i<M ; i++) {
			int nowH =sc.nextInt()-1;
			int nowW =sc.nextInt()-1;
			h[nowH]++;
			w[nowW]++;
			String now =nowH+","+nowW;
			exists.add(now);
		}

		int maxH = 0;
		int maxW = 0;
		List<Integer> selectedH = new ArrayList<Integer>();
		List<Integer> selectedW = new ArrayList<Integer>();

		for(int i = 0;i<H ; i++) {
			if(maxH < h[i] ) {
				maxH = h[i];
				selectedH.clear();
				selectedH.add(i);
			}else if(maxH == h[i]) {
				selectedH.add(i);
			}
		}
		for(int i = 0;i<W ; i++) {
			if(maxW < w[i] ) {
				maxW = w[i];
				selectedW.clear();
				selectedW.add(i);
			}else if(maxW == w[i]) {
				selectedW.add(i);
			}
		}

		boolean allExist = true;

		for(int sH:selectedH) {
			for(int sW: selectedW) {
				if(!exists.contains(sH+","+sW)) {
					allExist = false;
					break;
				}
			}
		}
		ans = maxH + maxW;

		if(allExist) {
			ans--;
		}

		System.out.println(ans);
	}

	//素数判定
	public static boolean isPrime(long num) {
		if (num < 2) return false;
		else if (num == 2) return true;
		else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

		double sqrtNum = Math.sqrt(num);
		for (int i = 3; i <= sqrtNum; i += 2)
		{
			if (num % i == 0)
			{
				// 素数ではない
				return false;
			}
		}

		// 素数である
		return true;
	}

	//BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}

	//Union-Find用の配列を要素数nで初期化
	static void ufInit(int n){
		parent = new int[n];
		rank = new int[n];
	}

	//Union-Findの要素の最上位の親（グループ名）を返す
	static int ufFind(int a) {
		if(parent[a]==a) {
			return a;
		}else {
			return ufFind(parent[a]);
		}
	}

	//Union-Find木を連結する
	static void ufUnite(int a, int b) {
		a = parent[a];
		b = parent[b];

		if(a==b) {
			return;
		}
		if(rank[a] > rank[b]){
			parent[b]=a;
		}else {
			parent[a]=b;
			if(rank[a]==rank[b]) {
				rank[b]++;
			}
		}
	}

	static boolean ufSame(int a, int b) {
		return ufFind(a)==ufFind(b);
	}
}

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


Question:
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//		String W	 = in.readLine();
		//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		Map<Long, Long> nums = new HashMap<>();

		long ans = 0;

		for(int i = 0;i<N ; i++) {
			A[i] = sc.nextLong();
			ans += A[i];
			Long tmp = nums.get(A[i]);
			if(tmp == null) {
				tmp =0L;
			}
			nums.put(A[i], ++tmp);
		}
		long Q = sc.nextLong();
		long[] B = new long[(int)Q];
		long[] C = new long[(int)Q];
		for(int i = 0;i<Q ; i++) {
			B[i] = sc.nextLong();
			C[i] = sc.nextLong();
			Long tmpB = nums.get(B[i]);
			if(tmpB == null) {
				tmpB = 0L;
			}
			ans += (C[i]-B[i])*tmpB;
			Long tmpC = nums.get(C[i]);
			if(tmpC == null) {
				tmpC = 0L;
			}
			nums.put(C[i], tmpC + tmpB);
			nums.put(B[i],  0L);
			System.out.println(ans);
		}
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}

}

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


Question:
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//		String W	 = in.readLine();
		//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		Map<Long, Long> nums = new HashMap<>();

		long ans = 0;

		for(int i = 0;i<N ; i++) {
			A[i] = sc.nextLong();
			ans += A[i];
			Long tmp = nums.get(A[i]);
			if(tmp == null) {
				tmp =0L;
			}
			nums.put(A[i], ++tmp);
		}
		long Q = sc.nextLong();
		long[] B = new long[(int)Q];
		long[] C = new long[(int)Q];
		for(int i = 0;i<Q ; i++) {
			B[i] = sc.nextLong();
			C[i] = sc.nextLong();
			Long tmpB = nums.get(B[i]);
			if(tmpB == null) {
				tmpB = 0L;
			}
			ans += (C[i]-B[i])*tmpB;
			Long tmpC = nums.get(C[i]);
			if(tmpC == null) {
				tmpC = 0L;
			}
			nums.put(C[i], tmpC + tmpB);
			nums.put(B[i],  0L);
			System.out.println(ans);
		}
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}

}

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


Question:
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
//			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//			String W = in.readLine();
//
//			int N= Integer.parseInt(W.split(" ")[0]);
//			int M= Integer.parseInt(W.split(" ")[1]);
		Scanner sc = new Scanner(System.in);
			int N  = sc.nextInt();
			int M= sc.nextInt();
//			int[] A = new int[M];
			int homework =0;

			for(int i=0;i<M;i++) {
				homework+= sc.nextInt();
			}

			int ans = N - homework;

			if(ans >=0) {
				System.out.println(ans);
			}else {
				System.out.println(-1);
			}

	}

}

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


Question:
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextInt();
		long K = sc.nextInt();
		long ans = 0;
		long nSum = (N+1)*N/2+1;

		for(long k = K; k<=N+1; k++) {
			ans+=((2*N+1-k)*k/2-(k-1)*k/2+1);
			ans%=Math.pow(10,9)+7;
//			System.out.println(ans);
		}

		ans%=Math.pow(10,9)+7;

		System.out.println(ans);

	}
	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}

}

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


Question:
import java.io.IOException;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

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

			BigInteger N = scanner.nextBigInteger();
			BigInteger K = scanner.nextBigInteger();

			BigInteger newN = N;

			newN = (N.remainder(K)).abs();

			N = K.subtract(newN);

			if(N.compareTo(newN) == 1) {
				System.out.println(newN);
			}else {
				System.out.println(N);
			}

	}

}

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


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

public class Main {

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

			int N = Integer.parseInt(W.split(" ")[0]);
			int M = Integer.parseInt(W.split(" ")[1]);

         int allPatternsNM = (N + M)*(N + M -1)/2;
         int eachPatternsNM = N*M;
         int ans= allPatternsNM - eachPatternsNM;
         System.out.println(ans);
	}

}

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


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

public class Main {

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

			int N = Integer.parseInt(W.split(" ")[0]);
			int M = Integer.parseInt(W.split(" ")[1]);

         int allPatternsNM = (N + M)*(N + M -1)/2;
         int eachPatternsNM = N*M;
         int ans= allPatternsNM - eachPatternsNM;
         System.out.println(ans);
	}

}

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


Question:
import java.io.IOException;
import java.util.Scanner;

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

		long[] a = new long[(int) N];
		long[] values = new long[(int) (N+1)];

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			values[(int) a[i]]++;
		}
		sc.close();

		long sum = 0;
		for (long c : values) {
			if(c > 1) {
			sum += (c-1)*c/2;
			}
		}

		for (long c :a) {
			System.out.println(sum - (values[(int) c]-1));
		}

	}

}

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


Question:
import java.io.IOException;
import java.util.Scanner;

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

		long[] a = new long[(int) N];
		long[] values = new long[(int) (N+1)];

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			values[(int) a[i]]++;
		}
		sc.close();

		long sum = 0;
		for (long c : values) {
			if(c > 1) {
			sum += (c-1)*c/2;
			}
		}

		for (long c :a) {
			System.out.println(sum - (values[(int) c]-1));
		}

	}

}

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


Question:
import java.util.*;

class Main{

  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int arr[] = new int[n];
    for(int i = 0;i < n;i++){
      arr[i] = sc.nextInt();
    }

    Arrays.sort(arr);

    int x = 0;
    for(int i = 0;i < n-1;i++){
      x += arr[i];
    }
    if(arr[n-1]<x){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }

  }

}

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


Question:
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	static void solve(){//Here is the main function
		ArrayList<Integer> one = nextIntArray();
		int N = one.get(0);
		int K = one.get(1);
		int mod = 998244353;
		long[] dp = new long[N];
		long[] ruiseki = new long[N];
		dp[0] = 1;
		ruiseki[0] = 1;
		ArrayList<Node> S = new ArrayList<>();
		for(int i = 0; i < K; i++){
			ArrayList<Integer> tmp = nextIntArray();
			S.add(new Node(tmp.get(0), tmp.get(1)));
		}
		for(int i = 1; i < N; i++){
			for(int j = 0; j < S.size(); j++){
				Node check = S.get(j);
				if(i - check.L < 0){
					continue;
				}
				if(check.L == check.R){
					dp[i] += dp[i - check.L];
				}else if(i - check.R - 1 < 0){
					dp[i] += ruiseki[i - check.L];
				}else{
					dp[i] += ruiseki[i - check.L] - ruiseki[i - check.R - 1];
				}
				if(dp[i] < 0){
					dp[i] += mod;
				}
				dp[i] %= mod;
			}
			ruiseki[i] = dp[i] + ruiseki[i - 1];
			ruiseki[i] %= mod;
		}

		myout(dp[N - 1]);

	}
	//Method addition frame start

static class Node{
	int L;
	int R;
	Node(int L, int R){
		this.L = L;
		this.R = R;
	}
}

	//Method addition frame end

	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	@SuppressWarnings("unchecked")
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
}

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