Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = Integer.parseInt(input.nextLine());
		String S = input.nextLine();
		System.out.println(SOLVE(N,S));
	}
	public static long SOLVE(int N, String S) {
		if (N<=3) return 0;
		long cnt = 0;
		for (int gap = 1; gap <= N-2; gap++) {
			for (int start = 0; start < N-gap-1; start++) {
				int middle = start+gap;
				for (int end = middle+1; end<N; end++) {
					if (S.charAt(start)!=S.charAt(middle)&&S.charAt(start)!=S.charAt(end)
						&&S.charAt(end)!=S.charAt(middle)&&end!=(middle+gap)) {
						cnt++;
					}
				}
			}
		}
		return cnt;
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = Integer.parseInt(input.nextLine());
		String S = input.nextLine();
		System.out.println(SOLVE(N,S));
	}
	public static long SOLVE(int N, String S) {
		if (N<=3) return 0;
		long cnt = 0;
		for (int gap = 1; gap < N; gap++) {
			for (int start = 0; start < N-gap-1; start++) {
				int middle = start+gap;
				for (int end = middle+1; end<N; end++) {
					if (S.charAt(start)!=S.charAt(middle)&&S.charAt(start)!=S.charAt(end)
						&&S.charAt(end)!=S.charAt(middle)&&end!=(middle+gap)) {
						cnt++;
					}
				}
			}
		}
		return cnt;
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int A = input.nextInt();
		int B = input.nextInt();
		int answer = A%B;
		System.out.println(Math.min(B-answer, answer));
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int[] balls = new int[N];
		for (int i = 0; i < N; i++) {
			balls[i] = input.nextInt();
		}
		int k=0; int cnt = 0;
		while (k<N) {
			for (int i = 0; i < N-1; i++) {
				if (i!=k) {
					for (int j = i+1; j < N; j++) {
						if (balls[i]==balls[j]&&j!=k) cnt++;
					}
				}
			}
			System.out.println(cnt);
			cnt=0;
			k++;
		}
	}
}

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


Question:
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
	/*1 --> (N,N-1)
	 * 2 --> (N,N-2)
	 * 3 --> (N-1,N-3)
	 * .
	 * .
	 * .
	 * i --> (N-i+2,N-i)
	 * 1 2 3 4 5 --> 2 5 1 4 3
	 *
	 * 2 8 1 6 3
	 * */
	public static void main(String[] args) {
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
      	long H = I.nextLong();
      	long sum = 0;
      for (int i = 0; i < N; i++) sum+=I.nextLong();
      O.pln(sum>=H?"Yes":"No");
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0)
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}

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


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

	public static void main(String[] args) { //WOOOOOOO AtCoder is HELPING!!!!!!!!!!
		//Arraylist cheese for the win
		Scanner input = new Scanner(System.in);
		PriorityQueue<Long> subs = new PriorityQueue<Long>(Comparitor.reverseOrder());
		int N = input.nextInt();
		int M = input.nextInt();
		long ans = 0;
		for (int i = 0; i < N; i++) {
			long x = input.nextLong();
			ans+=x;
			while (x>0) {
				long sub = x-x/2;
				subs.add(sub);
				x/=2;
			}
		}
		int cnt = 0;
		while (cnt < M) {
			ans-=subs.poll();
			cnt++;
			if (subs.isEmpty()) break;
		}
		System.out.println(ans);
	}
}

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


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

	public static void main(String[] args) { //Boolean markers+DP
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		boolean[] bad = new boolean[N+1];
		long mod = (long)(1e9+7);
		long[] dp = new long[N+1];
		for (int i = 0; i < M; i++) {
			int x = input.nextInt();
			bad[x]=true;
		}
		if (!bad[1]) dp[1]=1;
		if (!bad[2]) dp[2]=dp[1]+1;
		for (int step = 3; step<=N; step++) {
			if (!bad[step]) {
				dp[step]=dp[step-1]+dp[step-2];
				dp[step]%=mod;
			}
		}
		System.out.println(dp[N]);
	}
}

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


Question:
import java.io.*;
import java.math.*;
import java.util.*;
public class AGC015APlusB {

	public static void main(String[] args) {
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long ans = 0;
		long N = I.nextLong();
		long A = I.nextLong();
		long B = I.nextLong();
		if (A<=B&&N>=2) {
			N-=2;
			long lo = N*A;
			long hi = N*B;
			ans=hi-lo+1;
			ans = Math.max(ans, 0);
		}else if (N==1&&A==B) ans++;
		O.pln(ans);
	}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
	}
}

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


Question:
ort java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String x = input.next();
      	String ans = "";
      	for (int i = 0; i < x.length(); i++){
        	if (x.charAt(i)==',') ans+=" ";
          	else ans+=x.substring(i,i+1);
        }
      	System.out.println(ans);
	}
}

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


Question:
import java.util.Scanner;

public class SumOfThreeIntegersBC51Q2 {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String x = input.next();
      	String ans = "";
      	for (int i = 0; i < x.length(); i++){
        	if (x.charAt(i)==',') ans+=" ";
          	else ans+=x.substring(i,i+1);
        }
      	System.out.println(ans);
	}
}

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


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

public class Main {

  private static void solve() {
    int h = ni();
    int w = ni();
    int k = ni();

    int sy = ni() - 1;
    int sx = ni() - 1;
    int gy = ni() - 1;
    int gx = ni() - 1;

    char[][] map = new char[h][];
    for (int i = 0; i < h; i++) {
      map[i] = ns();
    }

    int ret = dijk(map, sy, sx, gy, gx, h, w, k);
    System.out.println(ret >= Integer.MAX_VALUE ? -1 : ret);
  }

  public static int dijk(char[][] map, int sy, int sx, int gy, int gx, int h, int w, int k) {
    int n = h * w;
    int[] d = new int[n];
    Arrays.fill(d, Integer.MAX_VALUE);
    Queue<int[]> q = new PriorityQueue<int[]>(100000, new Comparator<int[]>() {
      public int compare(int[] a, int[] b) {
        if (a[1] - b[1] != 0)
          return a[1] - b[1];
        if (a[2] - b[2] != 0) {
          return b[2] - a[2];
        }
        return a[0] - b[0];
      }
    });

    int from = sy * w + sx;
    q.add(new int[] { from, 0, 0 });

    d[from] = 0;
    int[][] dir = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };

    while (q.size() > 0) {
      int[] cur = q.poll();
      int y = cur[0] / w;
      int x = cur[0] % w;

      if (y == gy && x == gx) {
        return d[gy * w + gx];
      }

      for (int[] dd : dir) {
        int ny = y;
        int nx = x;
        for (int i = 0; i < k; i++) {
          ny += dd[0];
          nx += dd[1];

          if (ny < 0 || nx < 0 || ny >= h || nx >= w || map[ny][nx] == '@') {
            break;
          }

          int next = ny * w + nx;
          int nd = d[cur[0]] + 1;
          if (nd < d[next]) {
            d[next] = nd;
            q.add(new int[] { next, nd, i });
          }
        }
      }
    }

    return d[gy * w + gx];
  }

  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:
- No abnormally found
- Runtime Error
- Time Limit Exceeded
- Memory Limit Exceeded


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

public class Main {

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

    int[][] map = new int[n][n];
    int ptr = 0;
    for (int i = 0; i < n * n; i++) {
      p[i]--;
      int x = p[i] / n;
      int y = p[i] % n;

      map[x][y] = ptr++;
    }

    long ret = 0;
    final int[][] td = new int[n][n];
    int[] from = new int[2];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        from[0] = i;
        from[1] = j;
        int now = dijk(map, from, td);
        ret += now;
      }
    }
    System.out.println(ret);
  }

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

  public static int dijk(int[][] map, int[] from, final int[][] td) {
    int n = map.length;
    for (int[] v : td)
      Arrays.fill(v, Integer.MAX_VALUE / 4);
    TreeSet<int[]> q = new TreeSet<>((o1, o2) -> {
      if (td[o1[0]][o1[1]] != td[o2[0]][o2[1]]) {
        return td[o1[0]][o1[1]] - td[o2[0]][o2[1]];
      } else {
        return o1[0] != o2[0] ? o1[0] - o2[0] : o1[1] - o2[1];
      }
    });
    q.add(from);
    td[from[0]][from[1]] = 0;

    int v = map[from[0]][from[1]];

    while (q.size() > 0) {
      int[] cur = q.pollFirst();
      int cx = cur[0];
      int cy = cur[1];

      for (int[] d : dir) {
        int nx = cx + d[0];
        int ny = cy + d[1];
        if (nx < 0 || nx >= n || ny < 0 || ny >= n)
          return td[cx][cy];

        int nd = td[cx][cy] + (v < map[nx][ny] ? 1 : 0);
        if (nd < td[nx][ny]) {
          int[] next = {nx, ny};
          q.remove(next);
          td[nx][ny] = nd;
          q.add(next);
        }
      }
    }
    return -1;
  }

  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:
- Runtime Error
- Time Limit Exceeded
- No abnormally found
- Compile Error


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

public class Main {

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

    int[][] map = new int[n][n];
    int ptr = 0;
    for (int i = 0; i < n * n; i++) {
      p[i]--;
      int x = p[i] / n;
      int y = p[i] % n;

      map[x][y] = ptr++;
    }

    long ret = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int now = dijk(map, new int[] {i, j});
        ret += now;
      }
    }
    System.out.println(ret);
  }

  public static int dijk(int[][] map, int[] from) {
    int n = map.length;
    final int[][] td = new int[n][n];
    for (int[] v : td)
      Arrays.fill(v, Integer.MAX_VALUE / 4);
    TreeSet<int[]> q = new TreeSet<>((o1, o2) -> {
      if (td[o1[0]][o1[1]] != td[o2[0]][o2[1]]) {
        return td[o1[0]][o1[1]] - td[o2[0]][o2[1]];
      } else {
        return o1[0] != o2[0] ? o1[0] - o2[0] : o1[1] - o2[1];
      }
    });
    q.add(from);
    td[from[0]][from[1]] = 0;

    int v = map[from[0]][from[1]];

    int[][] dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
    while (q.size() > 0) {
      int[] cur = q.pollFirst();
      int cx = cur[0];
      int cy = cur[1];

      for (int[] d : dir) {
        int nx = cx + d[0];
        int ny = cy + d[1];
        if (nx < 0 || nx >= n || ny < 0 || ny >= n)
          return td[cx][cy];

        int nd = td[cx][cy] + (v < map[nx][ny] ? 1 : 0);
        if (nd < td[nx][ny]) {
          int[] next = {nx, ny};
          q.remove(next);
          td[nx][ny] = nd;
          q.add(next);
        }
      }
    }
    return -1;
  }

  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
- No abnormally found
- Runtime Error
- Time Limit Exceeded


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

  private static int solve(char[] s) {

    int odd = 0;
    int n = s.length;
    long[] table = new long[n];
    for (int i = 0; i < n; i++) {
      if (i <= n / 2)
        table[i] = C(n - 1, i, 2);

      int d = s[i] - '0';
      odd += d * table[i <= n / 2 ? i : (n - 1 - i)] % 2;
      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 long C(long n, long r, int p) {
    if (n < 0 || r < 0 || r > n)
      return 0L;
    if (r == 0 || n == r)
      return 1;
    long pe = 0;
    for (long i = n / p; i >= 1; i /= p)
      pe += i;
    for (long i = r / p; i >= 1; i /= p)
      pe -= i;
    for (long i = (n - r) / p; i >= 1; i /= p)
      pe -= i;
    if (pe > 0)
      return 0L;

    long flip = n / p - r / p - (n - r) / p;
    int nmp = (int) (n % p), rmp = (int) (r % p);
    if (nmp < rmp)
      return 0L;
    long ret = C(n / p, r / p, p);
    long den = 1;
    for (int i = 1; i <= rmp; i++) {
      ret = ret * (nmp - i + 1) % p;
      den = den * i % p;
    }
    ret = ret * invl(den, p) % p;
    if (flip % 2 != 0) {
      ret = -ret;
      if (ret < 0)
        ret += p;
    }
    return ret;
  }

  public static long invl(long a, long mod) {
    long b = mod;
    long p = 1, q = 0;
    while (b > 0) {
      long c = a / b;
      long d;
      d = a;
      a = b;
      b = d % b;
      d = p;
      p = q;
      q = d - c * q;
    }
    return p < 0 ? p + mod : p;
  }

  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
- Time Limit Exceeded
- Internal error
- Runtime Error


Question:
public class Main {

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

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

    // int d = 8;
    // 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("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';
      odd += d * C(n - 1, i, 2);
      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 long C(long n, long r, int p) {
    if (n < 0 || r < 0 || r > n)
      return 0L;
    if (r == 0 || n == r)
      return 1;
    long pe = 0;
    for (long i = n / p; i >= 1; i /= p)
      pe += i;
    for (long i = r / p; i >= 1; i /= p)
      pe -= i;
    for (long i = (n - r) / p; i >= 1; i /= p)
      pe -= i;
    if (pe > 0)
      return 0L;

    long flip = n / p - r / p - (n - r) / p;
    int nmp = (int) (n % p), rmp = (int) (r % p);
    if (nmp < rmp)
      return 0L;
    long ret = C(n / p, r / p, p);
    long den = 1;
    for (int i = 1; i <= rmp; i++) {
      ret = ret * (nmp - i + 1) % p;
      den = den * i % p;
    }
    ret = ret * invl(den, p) % p;
    if (flip % 2 != 0) {
      ret = -ret;
      if (ret < 0)
        ret += p;
    }
    return ret;
  }

  public static long invl(long a, long mod) {
    long b = mod;
    long p = 1, q = 0;
    while (b > 0) {
      long c = a / b;
      long d;
      d = a;
      a = b;
      b = d % b;
      d = p;
      p = q;
      q = d - c * q;
    }
    return p < 0 ? p + mod : p;
  }

  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
- Runtime Error
- Time Limit Exceeded
- No abnormally found


Question:
public class Main {
  private static void solve() {
    int n = ni();
    double l = nl();
    double[][] p = new double[n][2];

    for (int i = 0; i < n; i++) {
      double t = nl();
      double theta = 2 * Math.PI * t / l;
      p[i][0] = Math.cos(theta);
      p[i][1] = Math.sin(theta);
    }

    double[][] d = new double[n][n];
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        double dx = p[i][0] - p[j][0];
        double dy = p[i][1] - p[j][1];
        d[j][i] = d[i][j] = Math.sqrt(dx * dx + dy * dy);
      }
    }

    double retX = 0;
    double retY = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        for (int k = j + 1; k < n; k++) {
          double a = d[i][j] + d[j][k] + d[k][i];

          double x = d[i][j] * p[k][0] + d[j][k] * p[i][0] + d[k][i] * p[j][0];
          double y = d[i][j] * p[k][1] + d[j][k] * p[i][1] + d[k][i] * p[j][1];

          retX += x / a;
          retY += y / a;
        }
      }
    }
    long total = (long) n * (n - 1) * (n - 2) / 6;
    System.out.printf("%.12f %.12f\n", retX / total, retY / 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:
- Runtime Error
- No abnormally found
- Compile Error
- Time Limit Exceeded


Question:
import java.util.Arrays;

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]--;
      }
    }

    int[] ptr = new int[n];

    int cnt = 0;
    boolean[] used = new boolean[n];
    while (true) {
      Arrays.fill(used, false);
      cnt++;
      boolean update = false;
      for (int i = 0; i < n; i++) {
        if (used[i] || ptr[i] == n - 1)
          continue;
        int j = a[i][ptr[i]];

        if (!used[j] && a[j][ptr[j]] == i) {
          ptr[i]++;
          ptr[j]++;
          used[i] = used[j] = true;
          update = true;
        }
      }
      if (!update) {
        for (int i = 0; i < n; i++) {
          if (ptr[i] < n - 1) {
            System.out.println(-1);
            return;
          }
        }
        break;
      }
    }
    System.out.println(cnt - 1);
  }

  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:
- No abnormally found
- Compile Error
- Internal error
- Time Limit Exceeded


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

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]--;
      }
    }

    Set<Integer> cur = new HashSet<>();
    Set<Integer> nex = new HashSet<>();
    for (int i = 0; i < n; i++) {
      cur.add(i);
    }

    int[] ptr = new int[n];

    int cnt = 0;
    while (true) {
      cnt++;
      boolean update = false;
      while (cur.size() > 0) {
        int i = cur.iterator().next();
        cur.remove(i);
        if (ptr[i] < n - 1) {
          nex.add(i);
        }

        if (ptr[i] == n - 1)
          continue;
        int j = a[i][ptr[i]];

        if (cur.contains(j) && a[j][ptr[j]] == i) {
          cur.remove(j);
          if (ptr[j] < n - 1) {
            nex.add(j);
          }
          ptr[i]++;
          ptr[j]++;
          update = true;
        }
      }

      Set<Integer> tmp = cur;
      cur = nex;
      nex = tmp;

      if (!update) {
        for (int i = 0; i < n; i++) {
          if (ptr[i] < n - 1) {
            System.out.println(-1);
            return;
          }
        }
        break;
      }
    }
    System.out.println(cnt - 1);
  }

  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:
- No abnormally found
- Time Limit Exceeded
- Internal error
- Memory Limit Exceeded


Question:
import java.util.Arrays;

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]--;
      }
    }

    int[] ptr = new int[n];

    int cnt = 0;
    boolean[] used = new boolean[n];
    while (true) {
      Arrays.fill(used, false);
      cnt++;
      boolean update = false;
      for (int i = 0; i < n; i++) {
        if (ptr[i] == n - 1)
          continue;
        int j = a[i][ptr[i]];

        if (!used[i] && !used[j] && a[j][ptr[j]] == i) {
          ptr[i]++;
          ptr[j]++;
          used[i] = used[j] = true;
          update = true;
        }
      }
      if (!update) {
        for (int i = 0; i < n; i++) {
          if (ptr[i] < n - 1) {
            System.out.println(-1);
            return;
          }
        }
        break;
      }
    }
    System.out.println(cnt - 1);
  }

  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:
- Time Limit Exceeded
- No abnormally found
- Runtime Error
- Memory Limit Exceeded


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

    int[] ptr = new int[n];

    int cnt = 0;
    while (true) {
      cnt++;
      boolean update = false;
      boolean[] used = new boolean[n];
      for (int i = 0; i < n; i++) {
        if (ptr[i] == n - 1)
          continue;
        int j = a[i][ptr[i]];

        if (!used[i] && !used[j] && a[j][ptr[j]] == i) {
          ptr[i]++;
          ptr[j]++;
          used[i] = used[j] = true;
          update = true;
        }
      }
      if (!update) {
        for (int i = 0; i < n; i++) {
          if (ptr[i] < n - 1) {
            System.out.println(-1);
            return;
          }
        }
        break;
      }
    }
    System.out.println(cnt - 1);
  }

  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:
- Time Limit Exceeded
- No abnormally found
- Compile Error
- Memory Limit Exceeded


Question:
import java.math.BigInteger;

public class Main {

  private static void solve() {
    int n = ni();
    int m = ni();
    int[] a = na(m);
    int[] num = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

    BigInteger[] dp = new BigInteger[n + 10];
    for (int i = 0; i < dp.length; i++) {
      dp[i] = BigInteger.valueOf(-1);
    }
    dp[0] = BigInteger.ZERO;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        BigInteger x = BigInteger.valueOf(a[j]);
        if (!dp[i].equals(BigInteger.ZERO)) {
          int digit = dp[i].toString().length();
          for (int k = 0; k < digit; k++) {
            x = x.multiply(BigInteger.valueOf(10));
          }
        }
        x = x.add(dp[i]);
        if (dp[i].compareTo(BigInteger.ZERO) >= 0 && x.compareTo(dp[i + num[a[j]]]) > 0) {
          dp[i + num[a[j]]] = x;
        }
      }
    }

    System.out.println(dp[n]);
  }

  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
- No abnormally found
- Time Limit Exceeded
- Memory Limit Exceeded


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];
    for (int i = 0; i < Q; i++) {
      dij(query[i][0], color, query[i][2], 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 void dij(int now, int[] color, int nowColor, int d, int[][] g) {
    ArrayDeque<Integer> queue = new ArrayDeque<>();
    ArrayDeque<Integer> next = new ArrayDeque<>();
    queue.add(now);

    boolean[] visited = new boolean[g.length];

    for (int i = 0; i <= d; i ++) {
      while (queue.size() > 0) {
        int v = queue.poll();
        color[v] = nowColor;
        visited[v] = true;

        for (int u : g[v]) {
          if (!visited[u]) {
            next.add(u);
          }
        }
      }

      ArrayDeque<Integer> tmp = queue;
      queue = next;
      next = tmp;
    }
  }
}

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
- Compile Error
- Time Limit Exceeded
- Internal error


Question:
import java.io.IOException;
import java.io.InputStream;
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];
    for (int i = 0; i < Q; i++) {
      dij(query[i][0], color, query[i][2], 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 final int[] td = new int[200000];
  private static void dij(int now, int[] color, int nowColor, int d, int[][] g) {
    Arrays.fill(td, Integer.MAX_VALUE);
    PriorityQueue<Integer> q = new PriorityQueue<Integer>((a, b) -> {
      if (td[a] - td[b] != 0)
        return td[a] - td[b];
      return a - b;
    });
    q.add(now);
    td[now] = 0;

    while (q.size() > 0) {

      int cur = q.poll();
      color[cur] = nowColor;

      if (td[cur] >= d) {
        continue;
      }

      for (int i = 0; i < g[cur].length; i++) {
        int next = g[cur][i];
        int nd = td[cur] + 1;
        if (nd < td[next]) {
          q.remove(next);
          td[next] = nd;
          q.add(next);
        }
      }
    }
  }
}

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:
- Time Limit Exceeded
- Internal error
- No abnormally found
- Compile Error


Question:
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.NoSuchElementException;
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];
    for (int i = 0; i < Q; i++) {
      dij(query[i][0], color, query[i][2], 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 void dij(int now, int[] color, int nowColor, int d, int[][] g) {
    int n = g.length;
    final int[] td = new int[n];
    Arrays.fill(td, Integer.MAX_VALUE);
    TreeSet<Integer> q = new TreeSet<Integer>((a, b) -> {
      if (td[a] - td[b] != 0)
        return td[a] - td[b];
      return a - b;
    });
    q.add(now);
    td[now] = 0;

    while (q.size() > 0) {

      int cur = q.pollFirst();
      color[cur] = nowColor;

      if (td[cur] >= d) {
        continue;
      }

      for (int i = 0; i < g[cur].length; i++) {
        int next = g[cur][i];
        int nd = td[cur] + 1;
        if (nd < td[next]) {
          q.remove(next);
          td[next] = nd;
          q.add(next);
        }
      }
    }
  }
}

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
- Time Limit Exceeded
- Memory Limit Exceeded
- Compile Error


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

public class Main {
  private static int N;
  private static int[][] g;
  private static long[] A;

  private static long[] last;

  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    N = sc.nextInt();
    A = sc.nextLongList(N);

    int[] from = new int[N - 1];
    int[] to = new int[N - 1];
    for (int i = 0; i < N - 1; i ++) {
      from[i] = sc.nextInt() - 1;
      to[i] = sc.nextInt() - 1;
    }
    g = packU(N, from, to);

    last = new long[N];

    int s = -1;
    for (int i = 0; i < N; i ++) {
      if (g[i].length > 1) {
        s = i;
        break;
      }
    }
    if (s >= 0) {
      boolean ret = dfs(s, -1);
      if (ret && last[s] == 0) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    } else {
      System.out.println(A[0] == A[1] ? "YES" : "NO");
    }
  }

  private static boolean dfs(int now, int pre) {
    if (pre >= 0 && g[now].length == 1) {
      last[now] = A[now];
      return true;
    }

    long a = 0;
    long max = 0;
    for (int v : g[now]) {
      if (v != pre) {
        boolean ret = dfs(v, now);
        if (!ret) {
          return false;
        }
        a += last[v];
        max = Math.max(max, a);
      }
    }

    if (pre >= 0 && g[now].length == 2) {
      last[now] = A[now];
      return a == A[now];
    } else {
      if (a <= A[now] * 2 && A[now] <= a) {
        last[now] = A[now] * 2 - a;

        if (A[now] < max) {
          return false;
        }
        return true;
      } else {
        return false;
      }
    }
  }

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

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:
- Time Limit Exceeded
- Runtime Error
- Compile Error
- No abnormally found


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 = sc.nextLong();
    long B = sc.nextLong();
    long[] S = new long[N + 1];
    System.arraycopy(sc.nextLongList(N), 0, S, 1, N);
    S[0] = -Integer.MAX_VALUE;

    if (A > B) {
      long tmp = A;
      A = B;
      B = tmp;
    }

    for (int i = 3; i <= N; i++) {
      if (S[i] - S[i - 2] < A) {
        System.out.println(0);
        return;
      }
    }

    // i番目まで追加済み Yの最大はj番目 j <= i
    long[] from = new long[N + 1];
    long[] to = new long[N + 1];
    from[0] = 1;
    int ptr = 0;

    for (int i = 1; i <= N; i++) {
      // S[i] -> Y
      to[i] = 0;
      for (int j = ptr; j < i; j++) {
        if (S[i] - S[j] >= B) {
          to[i] += from[j];
        }
      }

      if (S[i] - S[i - 1] < A) {
        // S[i - 1]-> Y S[i]->X
        ptr = i - 1;
        to[i - 1] = from[i - 1];
      } else {
        // S[i] -> X
        for (int j = ptr; j < i; j++) {
          to[j] = from[j];
        }
      }

      long[] tmp = from;
      from = to;
      to = tmp;
    }

    long ret = 0;
    for (int i = ptr; i <= N; i++) {
      ret += from[i];
    }
    System.out.println(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:
- Time Limit Exceeded
- Compile Error
- Memory Limit Exceeded
- Runtime Error


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[10010];
  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:
- Time Limit Exceeded
- Runtime Error
- Internal error
- 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();
		long[] a = sc.nextLongList(N);

		long ret = Arrays.stream(a).sum();
		for (int i = 1; i < N; i++) {
			for (int j = 0; j < N - i; j++) {
				a[j] = Math.min(a[j], a[j + 1]);
				ret += a[j];
			}
		}
		System.out.println(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
- Time Limit Exceeded
- Runtime Error
- No abnormally found


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

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

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

			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 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:
- Memory Limit Exceeded
- Time Limit Exceeded
- Compile Error
- Runtime Error


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
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<>();
      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]);
        for (int j=0;j<b;j++) {
          int d = pq.peek();
          if (d >= c) break;
          d = pq.poll();
          pq.offer(c);
        }
      }
      long sum = 0L;
      for (int i=0;i<n;i++) sum += (long)pq.poll();
      System.out.println(sum);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

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


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

public class Main {

    private int n;
    private long[] 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 = Arrays.stream(br.readLine().split(" "))
		.map(Long::valueOf).sorted(Comparator.reverseOrder())
		.mapToLong(i -> i).toArray();
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    private void solve() {
	set();
	int pair = 0;
	long max = a[0];
	for (int i=0;i<n;i++) {
	    if (a[i] > max) continue;
	    long p = 2*Long.highestOneBit(a[i]) - a[i];
	    for (int j=i+1;j<n;j++) {
		if (a[j] > p) {
		    continue;
		} else if (a[j] < p) {
		    break;
		} else {
		    a[j] = max + 1;
		    pair++;
		    break;
		}
	    }
	}
	System.out.println(pair);
    }
}

Choices:
- Compile Error
- Memory Limit Exceeded
- 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.Comparator;
import java.util.TreeMap;

public class Main {

    private int n;
    private long[] 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 = Arrays.stream(br.readLine().split(" ")).mapToLong(Long::parseLong)
		.map(i -> -i).sorted().map(i -> -i).toArray();
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    private void solve() {
	set();
	int pair = 0;
	long max = a[0];
	for (int i=0;i<n;i++) {
	    if (a[i] > max) continue;
	    long p = 2*Long.highestOneBit(a[i]) - a[i];
	    for (int j=i+1;j<n;j++) {
		if (a[j] > p) {
		    continue;
		} else if (a[j] < p) {
		    break;
		} else {
		    a[j] = max + 1;
		    pair++;
		    break;
		}
	    }
	}
	System.out.println(pair);
    }
}

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


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

    private int n;
    private List<Long> 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 = Arrays.stream(br.readLine().split(" ")).map(Long::valueOf)
		.sorted().collect(Collectors.toList());
	    Collections.reverse(a);
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    private void solve() {
	set();
	int pair = 0;
	double loge2 = Math.log(2);
	while (!a.isEmpty()) {
	    Iterator<Long> it = a.iterator();
	    long ai = it.next();
	    it.remove();
	    int t = (int)(Math.log(ai)/loge2) + 1;
	    long p = (1 << t) - ai;
	    if (a.contains(p)) {
		pair++;
		a.remove(p);
	    }
	}
	System.out.println(pair);
    }
}

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


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

public class Main {

    private int n;
    private long[] 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 = Arrays.stream(br.readLine().split(" ")).mapToLong(Long::parseLong)
		.map(i -> -i).sorted().map(i -> -i).toArray();
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    private void solve() {
	set();
	int pair = 0;
	double loge2 = Math.log(2);
	for (int i=0;i<n;i++) {
	    if (a[i] < 0) continue;
	    int t = (int)(Math.log(a[i])/loge2) + 1;
	    long p = (1 << t) - a[i];
	    for (int j=i+1;j<n;j++) {
		if (a[j] < 0) continue;
		if (p > a[j]) break;
		if (a[j] == p) {
		    a[j] = -1;
		    pair++;
		    break;
		}
	    }
	}
	System.out.println(pair);
    }
}

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


Question:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

    private int n;
    private List<Long> 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 = Arrays.stream(br.readLine().split(" ")).map(Long::valueOf)
		.sorted().collect(Collectors.toList());
	    Collections.reverse(a);
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    private void solve() {
	set();
	int pair = 0;
	double loge2 = Math.log(2);
	while (!a.isEmpty()) {
	    Iterator<Long> it = a.iterator();
	    long ai = it.next();
	    it.remove();
	    int t = (int)(Math.log(ai)/loge2) + 1;
	    long p = (1 << t) - ai;
	    while (it.hasNext()) {
		long aj = it.next();
		if (aj == p) {
		    it.remove();
		    pair++;
		    break;
		}
	    }
	}
	System.out.println(pair);
    }
}

Choices:
- Runtime Error
- Compile Error
- Time 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.TreeMap;

public class Main {

    private int n;
    private long[] 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 = Arrays.stream(br.readLine().split(" ")).mapToLong(Long::parseLong)
		.map(i -> -i).sorted().map(i -> -i).toArray();
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    private void solve() {
	set();
	int pair = 0;
	double loge2 = Math.log(2);
	for (int i=0;i<n;i++) {
	    if (a[i] < 0) continue;
	    int t = (int)(Math.log(a[i])/loge2) + 1;
	    long p = (1 << t) - a[i];
	    for (int j=i+1;j<n;j++) {
		if (a[j] < 0) continue;
		if (a[j] == p) {
		    a[j] = -1;
		    pair++;
		    break;
		}
	    }
	}
	System.out.println(pair);
    }
}

Choices:
- Time Limit Exceeded
- Internal error
- Compile Error
- 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.TreeMap;

public class Main {

    private int n;
    private long[] 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 = Arrays.stream(br.readLine().split(" ")).mapToLong(Long::parseLong)
		.map(i -> -i).sorted().map(i -> -i).toArray();
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    private void solve() {
	set();
	int pair = 0;
	for (int i=0;i<n;i++) {
	    if (a[i] < 0) continue;
	    int t = (int)log2(a[i]) + 1;
	    long p = 1 << t;
	    for (int j=i+1;j<n;j++) {
		if (a[j] < 0) continue;
		if (a[i]+a[j] == p) {
		    a[j] = -1;
		    pair++;
		    break;
		}
	    }
	}
	System.out.println(pair);
    }

    private double log2(double x) {
	return Math.log(x) / Math.log(2);
    }
}

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


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

public class Main implements Runnable {

    private long 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 = Long.parseLong(parts[0]);
	    x = Long.parseLong(parts[1]);
	} catch (IOException e) {
	    e.printStackTrace();
	}
    }

    @Override
    public void run() {
	set();
	long num = 0;
	for (long i=1;i<=x;i++) {
	    if (getBurger(n,i).equals("P")) num++;
	}
	System.out.println(num);
    }

    private String getBurger(long level,long idx) {
	if (level == 0) return "P";
        if (idx == 1) return "B";
        long end = pow(2,level+2)-3;
        long mid = end/2;
        if (idx == mid) return "P";
        if (idx == end) return "B";
        long i = idx < mid ? idx-1 : idx-mid;
        return getBurger(level-1,i);
    }

    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:
- Internal error
- No abnormally found
- Compile Error
- Time Limit Exceeded


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

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:
- Runtime Error
- Compile Error
- No abnormally found
- Time Limit Exceeded