Question:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        System.out.println(((a * (a-1))/2 + (b * (b-1))/2));
    }

}

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


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

    public static void main(String[] args)
    {
        Scanner in=new Scanner(System.in);
        String S = in.next();
        String T = in.next();
        int count = 0;
        if (S.length() == T.length()){
            for (int i = 0; i < S.length(); i++) {
                if (S.charAt(i) != T.charAt(i)){
                    count++;
                }
            }
            System.out.println(count);
        }
    }
}

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


Question:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        while (x != 0) {
            if (x % 10 == 7) {
                System.out.println("Yes");
                return;
            }
            x /= 10;
        }
        System.out.println("No");
    }

}

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


Question:
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[]args) throws IOException{
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(cin.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
boolean ret = false;
if(a == b)
if(b==c) ret = false;
else ret = true;
if(b==c)
if(a==b) ret = false;
else ret = true;
if(a==c)
if(a==b) ret = false;
else ret = true;
if(ret) System.out.println("Yes");
else System.out.println("No");
}
}

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


Question:
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[]args) throws IOException{
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(cin.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
boolean ret = false;
if(a == b)
if(b==c) ret = false;
else ret = true;
if(b==c)
if(a==b) ret = false;
else ret = true;
if(a==c)
if(a==b) ret = false;
else ret = true;
if(ret) System.out.println("Yes");
else System.out.println("No");
}
}

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


Question:
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[]args) throws IOException{
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(cin.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
boolean ret = false;
if(a == b)
if(b==c) ret = false;
else ret = true;
if(b==c)
if(a==b) ret = false;
else ret = true;
if(a==c)
if(a==b) ret = false;
else ret = true;
if(ret) System.out.println("Yes");
else System.out.println("No");
}
}

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


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

public class Main{

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String info = br.readLine();
		String[] order = info.split(" ");
		int[] numbers = new int[]{Integer.parseInt(order[0]), Integer.parseInt(order[1])};

		if(numbers[0]==numbers[1]) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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


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

public class Main{

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String info = br.readLine();
		String[] order = info.split(" ");
		int[] numbers = new int[]{Integer.parseInt(order[0]), Integer.parseInt(order[1])};

		if(numbers[0]==numbers[1]) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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


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

public class Main{

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String info = br.readLine();
		String[] order = info.split(" ");
		int[] numbers = new int[]{Integer.parseInt(order[0]), Integer.parseInt(order[1])};

		if(numbers[0]==numbers[1]) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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


Question:
import java.util.Scanner;

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

		if(s.equals("SUN")) System.out.println("7");
		else if(s.equals("MON")) System.out.println("6");
		else if(s.equals("TUE")) System.out.println("5");
		else if(s.equals("WED")) System.out.println("4");
		else if(s.equals("THU")) System.out.println("3");
		else if(s.equals("FRI")) System.out.println("2");
		else if(s.equals("SAT")) System.out.println("1");
		}
}

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


Question:
import java.util.Scanner;

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

		if(s.equals("SUN")) System.out.println("7");
		else if(s.equals("MON")) System.out.println("6");
		else if(s.equals("TUE")) System.out.println("5");
		else if(s.equals("WED")) System.out.println("4");
		else if(s.equals("THU")) System.out.println("3");
		else if(s.equals("FRI")) System.out.println("2");
		else if(s.equals("SAT")) System.out.println("1");
		}
}

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


Question:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.ArrayList;
public class Main {

    public static void main(String[] args) {
        FastReader f = new FastReader();

     long n = f.nextLong();
     long q=(long)Math.sqrt(n);
     ArrayList<Long> a1 = new ArrayList<Long>();

     for(long i = 1 ;i <= q ; i++){
         if(n%i==0){
         a1.add(i);
        // long x =(long)(n/i);
         a1.add((long)(n/i));

         }
     }

        long [] arr = new long[a1.size()];
        for(int i= 0;i<arr.length;i++){
            arr[i]=a1.get(i);
        }
     Arrays.sort(arr);
     int mid=(int)arr.length/2;

       System.out.println((arr[mid] + arr[mid-1])-2);

    }
 }

class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

        byte nextByte()
        {
            return Byte.parseByte(next());
        }

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

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

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

}

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


Question:
import java.util.Scanner;
public class Main {
	public static void main(String args[]){//double 处理果盘
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] num = new int[n];
		long sum = 0;
		for (int i=0;i<n;i++){
			num[i] = in.nextInt();
		}

		for (int i=0;i<n;i++){
			for (int j=i+1;j<n;j++){
				sum += num[i]*num[j];
			}
		}
		System.out.println(sum);
	}
}

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


Question:
import java.util.Scanner;

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

        S = in.nextLine();
        T = in.nextLine();

        int correct = 0;
        for (int i = 0; i < T.length(); i++) {
            if (S.charAt(i) == T.charAt(i)) correct++;
        }

        System.out.println(correct);
    }
}

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


Question:
import java.util.Scanner;

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

        S = in.nextLine();
        T = in.nextLine();

        int correct = 0;
        for (int i = 0; i < T.length(); i++) {
            if (S.charAt(i) == T.charAt(i)) correct++;
        }

        System.out.println(correct);
    }
}

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


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

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		long a = input.nextLong();
		long b = input.nextLong();

		if((a+b)%2==0)
			System.out.println((a+b)/2);
		else
			System.out.println("IMPOSSIBLE");

	}

}

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


Question:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner entrada= new Scanner(System.in);
        String str=entrada.next();
        String str2="";
        int p=-2;
        int cont=0;
        for(int i=0; i<str.length();i++){
            char c=str.charAt(i);
            for(int j=0;j<str.length();j++){
                if(str.charAt(j)==(c)){
                    cont+=1;
                }
            }
        }
        if (cont==8){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
        //System.out.println(cont);
    }
}

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


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

public class Main {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int h = in.nextInt(), w = in.nextInt();
        char[][] areaCharred = new char[h][w];
        int[][] horizontalLight = new int[h][w];
        int[][] verticalLight = new int[w][h];
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < h; i++){
            areaCharred[i] = in.next().toCharArray();
        }
        for (int i = 0; i < h; i++){
            int prevH = 0;
            for (int j = 0; j < w; j++){
                if (areaCharred[i][j] == '#'){
                    Arrays.fill(horizontalLight[i], prevH, j, j - prevH);
                    prevH = j + 1;
                }
            }
            Arrays.fill(horizontalLight[i], prevH, w, w - prevH);
        }
        for (int i = 0; i < w; i++){
            int prevV = 0;
            for (int j = 0; j < h; j++){
                if (areaCharred[j][i] == '#') {
                    Arrays.fill(verticalLight[i], prevV, j, j - prevV);
                    prevV = j + 1;
                }
            }
            Arrays.fill(verticalLight[i], prevV, h, h - prevV);
        }
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                max = Math.max(horizontalLight[i][j] + verticalLight[j][i] - 1, max);
            }
        }
        System.out.println(max);
    }
}

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


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

    public static void main(String[] args) {

        Scanner entrada=new Scanner(System.in);
       int x[]=new int[2];
       int x2[]=new int[3];

        for (int i = 0; i < 2; i++) {
            x[i]=entrada.nextInt();
     }

       x2[0]=x[0]+x[0]-1;
       x2[1]=x[0]+x[1];
       x2[2]=x[1]+x[1]-1;

      Arrays.sort(x2);
        System.out.println(x2[2]);
    }

}

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


Question:
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        for(int i=0;i<3;++i){
            a[i] = sc.nextInt();
        }Arrays.sort(a);
        int sum = a[2]*10+a[1]+a[0];
        System.out.println(sum);
    }
}

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


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

public class Main
{
    public static void main(String[] argv)
    {
        try{
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        String msg1,msg2;
        msg1=bf.readLine();
        msg2=bf.readLine();
        Solver s = new Solver(msg1,msg2);
        s.solve();
        s.approach();
        }
        catch(IOException e )
        {
            System.exit(0);
        }
    }
}

class Solver
{
    String patten,target;
    boolean winFlag;
    public Solver(String s1,String s2)
    {
        patten=s1;
        target=s2;
        winFlag=false;
    }
    public void solve()
    {
        String tmp = target+target;
        for( int i=0;i<patten.length();i++)
        {
            winFlag=true;
            for(int j=0;j<patten.length();j++)
            {
                if(tmp.charAt(i+j)!=patten.charAt(j))
                    winFlag=false;
            }
            if(winFlag==true)
                break;
        }

    }
    public void approach()
    {
        if(winFlag==true)
            System.out.println("Yes");
        else
            System.out.println("No");

    }

}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		long x,kk,ans;
		int n;
		Scanner in =new Scanner(System.in);
		n=in.nextInt();x=in.nextLong();
		long []  a=new long[n+1000];
		long [][] dp = new long[n+500][n+500];
		for(int i=1;i<=n;i++) {
			a[i]=in.nextLong();
		}
		ans=9000000000000000000L;kk=-1;
		for(int i=1;i<=n;i++) {
			dp[i][0]=a[i];
			for(int k=1;k<n;k++) {
				int pi=i-k;
				if(pi<=0)pi=n+pi;
				if(dp[i][k-1]>=a[pi])dp[i][k]=a[pi];
				else dp[i][k]=dp[i][k-1];
//				if(bal1>a[pi] + ((long)k)*x) {
//					bal1=a[pi]+(k)*x;bal2=k;bal3=a[pi];
//				}
			}
//			if(bal2>kk)kk=bal2;
//			ans+=bal3;

		}
		long sum=0;
		for(int k=0;k<n;k++) {
			sum=0;
			for(int i=1;i<=n;i++) {
				sum+=dp[i][k];
			}
			if(sum+k*x<ans)ans=sum+k*x;
		}
		System.out.println(ans);
	}

}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		long x,kk,ans;
		int n;
		Scanner in =new Scanner(System.in);
		n=in.nextInt();x=in.nextLong();
		long []  a=new long[n+1000];
		long [][] dp = new long[n+500][n+500];
		for(int i=1;i<=n;i++) {
			a[i]=in.nextLong();
		}
		ans=9000000000000000000L;kk=-1;
		for(int i=1;i<=n;i++) {
			dp[i][0]=a[i];
			for(int k=1;k<n;k++) {
				int pi=i-k;
				if(pi<=0)pi=n+pi;
				if(dp[i][k-1]>=a[pi])dp[i][k]=a[pi];
				else dp[i][k]=dp[i][k-1];
//				if(bal1>a[pi] + ((long)k)*x) {
//					bal1=a[pi]+(k)*x;bal2=k;bal3=a[pi];
//				}
			}
//			if(bal2>kk)kk=bal2;
//			ans+=bal3;

		}
		long sum=0;
		for(int k=0;k<n;k++) {
			sum=0;
			for(int i=1;i<=n;i++) {
				sum+=dp[i][k];
			}
			if(sum+k*x<ans)ans=sum+k*x;
		}
		System.out.println(ans);
	}

}

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


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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);

long a=s.nextLong();long b=s.nextLong();
if(a<0&&b<0) {
	long xx=Math.max(a,b)-Math.min(b, a);
	if(xx%2!=0)
	System.out.println("Positive");
	else
		System.out.println("Negative");
	return;
}
else if(a>0&&b>0) {
	System.out.println("Positive");
}else {
	System.out.println("Zero");
}
	}

}

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


Question:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] box = new int[n+1];
        boolean[] flag = new boolean[n+1];
        for(int i = 1; i < n+1; i++){
            box[i] = 1;
            flag[i] = false;
        }
        flag[1] = true;
        for(int i = 0; i < m; i++){
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            if(flag[x] && box[x] == 1){
                flag[x] = false;
                flag[y] = true;
            }else if(flag[x] && box[x] > 1){
                flag[y] = true;
            }
            box[x]--;
            box[y]++;
        }
        int count = 0;
        for(int i = 0; i < n+1; i++){
            if(flag[i])
                count++;
        }
        System.out.println(count);
    }
}

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


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

      System.out.println(ans);
    }
}

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


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in) ;
        int n = sc.nextInt() ;
        BigInteger ans = BigInteger.ONE ;
        BigInteger b[] = new BigInteger[n] ;
        BigInteger cmp = new BigInteger("1000000000000000000") ;
        Boolean zero = false ;
        for (int i = 0 ; i < n ; i ++) {
            b[i] = sc.nextBigInteger() ;
            if(b[i].compareTo(BigInteger.ZERO) == 0) zero = true ;
        }
        if(zero) System.out.println(0);
        else {
            Boolean con = true ;
            for (int i = 0 ; i < n ; i ++) {
                ans = ans.multiply(b[i]) ;
                if(ans.compareTo(cmp) == 1) {
                    con = false ;
                    break ;
                }
            }
            if(con) System.out.println(ans);
            else System.out.println(-1);
        }
    }
}

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


Question:
import java.util.*;

 public class Main {
   	public static void main (String arg[]){
      	Scanner in = new Scanner (System.in);
       	String s = in.nextLine();
      	String t = in.nextLine();

       int count =0;
      for(int i =0; i<3; i++)
      	if (s.charAt(i)==t.charAt(i)){
          count++;
        }

      System.out.println(count);

    }

 }

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


Question:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws InterruptedException {
		FastScanner fs=new FastScanner();
		int n=fs.nextInt(), nQ=fs.nextInt();

		int[] a=fs.readArray(n);
		int[] lastSeen=new int[n+10];
		Arrays.fill(lastSeen, n);
		BIT bit=new BIT(n+100);

		Query[] queries=new Query[nQ];
		ArrayList<Query>[] queriesAt=new ArrayList[n];
		for (int i=0; i<n; i++) queriesAt[i]=new ArrayList<>();
		for (int qq=0; qq<nQ; qq++) {
			int l=fs.nextInt()-1, r=fs.nextInt()-1;
			Query q=new Query(l, r);
			queries[qq]=q;
			queriesAt[l].add(q);
		}

		for (int l=n-1; l>=0; l--) {
			bit.update(lastSeen[a[l]], -1);
			bit.update(l, 1);
			lastSeen[a[l]]=l;

			for (Query qq: queriesAt[l]) {
				qq.ans=bit.read(qq.r);
			}
		}
		PrintWriter out=new PrintWriter(System.out);
		for (Query qq:queries)
			out.println(qq.ans);
		out.close();
	}

	static class Query {
		int l, r, ans;
		public Query(int l, int r) {
			this.l=l;
			this.r=r;
		}
	}

	static class BIT {
		int n;
		int[] tree;

		public BIT(int n) {
			this.n = n;
			tree = new int[n + 2];
		}

		int read(int i) {
			i++;
			int sum = 0;
			while (i > 0) {
				sum += tree[i];
				i -= i & -i;
			}
			return sum;
		}

		void update(int i, int val) {
			i++;
			while (i <= n) {
				tree[i] += val;
				i += i & -i;
			}
		}

		// if the BIT is a freq array, returns the
		// index of the kth item, or n if there are fewer
		// than k items.
		int getKth(int k) {
			int e=Integer.highestOneBit(n), o=0;
			for (; e!=0; e>>=1) {
				if (e+o<=n && tree[e+o]<=k) {
					k-=tree[e+o];
					o+=e;
				}
			}
			return o;
		}

	}

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

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

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

		}

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

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

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

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

}

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


Question:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws InterruptedException {
		FastScanner fs=new FastScanner();
		int n=fs.nextInt(), nQ=fs.nextInt();

		int[] a=fs.readArray(n);
		int[] lastSeen=new int[n+10];
		Arrays.fill(lastSeen, n);
		BIT bit=new BIT(n+100);

		Query[] queries=new Query[nQ];
		ArrayList<Query>[] queriesAt=new ArrayList[n];
		for (int i=0; i<n; i++) queriesAt[i]=new ArrayList<>();
		for (int qq=0; qq<nQ; qq++) {
			int l=fs.nextInt()-1, r=fs.nextInt()-1;
			Query q=new Query(l, r);
			queries[qq]=q;
			queriesAt[l].add(q);
		}

		for (int l=n-1; l>=0; l--) {
			bit.update(lastSeen[a[l]], -1);
			bit.update(l, 1);
			lastSeen[a[l]]=l;

			for (Query qq: queriesAt[l]) {
				qq.ans=bit.read(qq.r);
			}
		}
		PrintWriter out=new PrintWriter(System.out);
		for (Query qq:queries)
			out.println(qq.ans);
		out.close();
	}

	static class Query {
		int l, r, ans;
		public Query(int l, int r) {
			this.l=l;
			this.r=r;
		}
	}

	static class BIT {
		int n;
		int[] tree;

		public BIT(int n) {
			this.n = n;
			tree = new int[n + 2];
		}

		int read(int i) {
			i++;
			int sum = 0;
			while (i > 0) {
				sum += tree[i];
				i -= i & -i;
			}
			return sum;
		}

		void update(int i, int val) {
			i++;
			while (i <= n) {
				tree[i] += val;
				i += i & -i;
			}
		}

		// if the BIT is a freq array, returns the
		// index of the kth item, or n if there are fewer
		// than k items.
		int getKth(int k) {
			int e=Integer.highestOneBit(n), o=0;
			for (; e!=0; e>>=1) {
				if (e+o<=n && tree[e+o]<=k) {
					k-=tree[e+o];
					o+=e;
				}
			}
			return o;
		}

	}

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

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

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

		}

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

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

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

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

}

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


Question:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws InterruptedException {
		FastScanner fs=new FastScanner();
		int n=fs.nextInt(), nQ=fs.nextInt();

		int[] a=fs.readArray(n);
		int[] lastSeen=new int[n+10];
		Arrays.fill(lastSeen, n);
		BIT bit=new BIT(n+100);

		Query[] queries=new Query[nQ];
		ArrayList<Query>[] queriesAt=new ArrayList[n];
		for (int i=0; i<n; i++) queriesAt[i]=new ArrayList<>();
		for (int qq=0; qq<nQ; qq++) {
			int l=fs.nextInt()-1, r=fs.nextInt()-1;
			Query q=new Query(l, r);
			queries[qq]=q;
			queriesAt[l].add(q);
		}

		for (int l=n-1; l>=0; l--) {
			bit.update(lastSeen[a[l]], -1);
			bit.update(l, 1);
			lastSeen[a[l]]=l;

			for (Query qq: queriesAt[l]) {
				qq.ans=bit.read(qq.r);
			}
		}
		PrintWriter out=new PrintWriter(System.out);
		for (Query qq:queries)
			out.println(qq.ans);
		out.close();
	}

	static class Query {
		int l, r, ans;
		public Query(int l, int r) {
			this.l=l;
			this.r=r;
		}
	}

	static class BIT {
		int n;
		int[] tree;

		public BIT(int n) {
			this.n = n;
			tree = new int[n + 2];
		}

		int read(int i) {
			i++;
			int sum = 0;
			while (i > 0) {
				sum += tree[i];
				i -= i & -i;
			}
			return sum;
		}

		void update(int i, int val) {
			i++;
			while (i <= n) {
				tree[i] += val;
				i += i & -i;
			}
		}

		// if the BIT is a freq array, returns the
		// index of the kth item, or n if there are fewer
		// than k items.
		int getKth(int k) {
			int e=Integer.highestOneBit(n), o=0;
			for (; e!=0; e>>=1) {
				if (e+o<=n && tree[e+o]<=k) {
					k-=tree[e+o];
					o+=e;
				}
			}
			return o;
		}

	}

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

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

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

		}

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

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

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

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

}

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


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

public class Main {

    static BigDecimal MAX = new BigDecimal(1_000_000_000_000_000_000L);
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        boolean hasZero = false;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
            if(a[i] == 0) hasZero = true;
        }
        if(hasZero){
            System.out.println(0);
        }else{
            BigDecimal d = new BigDecimal(a[0]);
            boolean over = false;
            for (int i = 1; i < n; i++) {
                d = d.multiply(new BigDecimal(a[i]));
                if(d.compareTo(MAX) == 1){
                    over = true;break;
                }
            }
            if(over) System.out.println(-1);
            else System.out.println(d.longValue());
        }
        sc.close();

    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        Arrays.fill(a, -1);
        boolean ans = true;
        for (int i = 0; i < m; i++) {
            int s = sc.nextInt()-1;
            int c = sc.nextInt();
            if(a[s] < 0) a[s] = c;
            else if(a[s] != c) {
                ans = false; break;
            }
        }
        if(ans){
            if(n == 1){
                System.out.println(a[0] < 0 ? 0 : a[0]);
            }else if(n == 2){
                if(a[0] == 0)System.out.println(-1);
                else {
                    int t = a[0] < 0 ? 1 : a[0];
                    t *= 10;
                    t += a[1] < 0 ? 0 : a[1];
                    System.out.println(t);
                }
            }else{
                if(a[0] == 0)System.out.println(-1);
                else{
                    int t = a[0] < 0 ? 100 : a[0]*100;
                    t += a[1] < 0 ? 0 : a[1]*10;
                    t += a[2] < 0 ? 0 : a[2];
                    System.out.println(t);
                }
            }
        }else System.out.println(-1);
        sc.close();

    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p = 0;
        int q = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            p += x * Math.pow(10, n - i -1);
        }
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            q += x * Math.pow(10, n - i -1);
        }
        List<Integer> a = new ArrayList<>();
        dfs(a, n, 1, 0, 0);
        Collections.sort(a);
        int b = 0;
        int c = 0;
        for (int i = 0; i < a.size(); i++) {
            if(a.get(i) == p) b = i;
            if(a.get(i) == q) c = i;
        }
        System.out.println(Math.abs(b-c));
        sc.close();

    }

    private static void dfs(List<Integer> a, int n, int x, int sum, int bit) {
        for (int i = 0; i < n; i++) {
            if((bit >> i & 1) == 1)continue;
            int y = sum + x * (int)Math.pow(10, n - i -1);
            if(x == n) a.add(y);
            else {
                bit |= 1 << i;
                dfs(a, n, x+1, y, bit);
                bit ^= 1 << i;
            }
        }
    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long diff = b-a;
        long ans = 0L;
        if(diff % 2L == 0){
            ans = diff / 2L;
        }else{
            long h = (n+1L)/2L;
            if(b <= h){
                ans = b-1L;
            }else if(h < a){
                ans = n-a;
            }else if(n-a < b-1L){
                ans = n-a;
            }else{
                ans = b-1L;
            }
            if(1 < b-a) ans -= (b-a-1L)/2L;
        }
        System.out.println(ans);
        sc.close();

    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();
        int[][] e = new int[m*2][3];
        for (int i = 0; i < m*2; i+=2) {
            e[i][0] = sc.nextInt()-1;
            e[i][1] = sc.nextInt()-1;
            e[i][2] = sc.nextInt();
            e[i+1][0] = e[i][1];
            e[i+1][1] = e[i][0];
            e[i+1][2] = e[i][2];
        }
        long[][] w1 = warshallFloyd(n, e);
        int[][] e2 = new int[n*n][3];
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(i == j)continue;
                if(w1[i][j] <= l) {
                    e2[cnt++] = new int[]{i, j, 1};
                }
            }
        }
        int[][] e3 = Arrays.copyOf(e2, cnt);
        long[][] w2 = warshallFloyd(n, e3);
        StringBuilder sb = new StringBuilder();
        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int s = sc.nextInt()-1;
            int t = sc.nextInt()-1;
            sb.append(w2[s][t] == Integer.MAX_VALUE ? -1 : w2[s][t]-1).append("\n");
        }
        System.out.print(sb.toString());
        sc.close();

    }

    public static int[][][] buildWeightedGraph(int n, int[][] edges){
        int m = edges.length;
        int[][][] graph = new int[n][][];
        int[] deg = new int[n];
        for (int i = 0; i < m; i++) {
            deg[ edges[i][0] ]++;
            deg[ edges[i][1] ]++;
        }
        for (int i = 0; i < n; i++) {
            graph[i] = new int[deg[i]][2];
        }
        for (int i = 0; i < m; i++) {
            int a = edges[i][0];
            int b = edges[i][1];
            int c = edges[i][2];
            graph[a][--deg[a]][0] = b;
            graph[a][deg[a]][1] = c;
            graph[b][--deg[b]][0] = a;
            graph[b][deg[b]][1] = c;
        }

        return graph;
    }

    public static long[][] warshallFloyd(int n, int[][] edge){
        long[][] d = new long[n][n];
        for (int i = 0; i < n; i++) Arrays.fill(d[i], Integer.MAX_VALUE);
        for(int i = 0; i < n; i++) d[i][i] = 0;
        for (int i = 0; i < edge.length; i++) {
            d[edge[i][0]][edge[i][1]] = edge[i][2];
        }
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        return d;
    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();
        int[][] e = new int[m*2][3];
        for (int i = 0; i < m*2; i+=2) {
            e[i][0] = sc.nextInt()-1;
            e[i][1] = sc.nextInt()-1;
            e[i][2] = sc.nextInt();
            e[i+1][0] = e[i][1];
            e[i+1][1] = e[i][0];
            e[i+1][2] = e[i][2];
        }
        long[][] w1 = warshallFloyd(n, e);
        int[][] e2 = new int[n*n][3];
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(i == j)continue;
                if(w1[i][j] <= l) {
                    e2[cnt++] = new int[]{i, j, 1};
                }
            }
        }
        int[][] e3 = Arrays.copyOf(e2, cnt);
        long[][] w2 = warshallFloyd(n, e3);
        StringBuilder sb = new StringBuilder();
        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int s = sc.nextInt()-1;
            int t = sc.nextInt()-1;
            sb.append(w2[s][t] == Integer.MAX_VALUE ? -1 : w2[s][t]-1).append("\n");
        }
        System.out.print(sb.toString());
        sc.close();

    }

    public static int[][][] buildWeightedGraph(int n, int[][] edges){
        int m = edges.length;
        int[][][] graph = new int[n][][];
        int[] deg = new int[n];
        for (int i = 0; i < m; i++) {
            deg[ edges[i][0] ]++;
            deg[ edges[i][1] ]++;
        }
        for (int i = 0; i < n; i++) {
            graph[i] = new int[deg[i]][2];
        }
        for (int i = 0; i < m; i++) {
            int a = edges[i][0];
            int b = edges[i][1];
            int c = edges[i][2];
            graph[a][--deg[a]][0] = b;
            graph[a][deg[a]][1] = c;
            graph[b][--deg[b]][0] = a;
            graph[b][deg[b]][1] = c;
        }

        return graph;
    }

    public static long[][] warshallFloyd(int n, int[][] edge){
        long[][] d = new long[n][n];
        for (int i = 0; i < n; i++) Arrays.fill(d[i], Integer.MAX_VALUE);
        for(int i = 0; i < n; i++) d[i][i] = 0;
        for (int i = 0; i < edge.length; i++) {
            d[edge[i][0]][edge[i][1]] = edge[i][2];
        }
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        return d;
    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        long ans = 0L;
        String f = null, m = null, b = null;
        for (int i = 1; i < s.length(); i++) {
            if(s.charAt(0) != s.charAt(i)){
                f = s.substring(0, i);
                s = s.substring(i);
                break;
            }
        }
        if(f == null){
            long sum = s.length() * k;
            ans = sum / 2;
        }else{
            for (int i = 1; i < s.length(); i++) {
                if(s.charAt(s.length()-1) != s.charAt(s.length()-1-i)){
                    b = s.substring(s.length()-i);
                    m = s.substring(0, s.length()-i);
                    break;
                }else if(i == s.length()-1){
                    b = s;
                }
            }
            if(m == null){
                ans = ((f.length()/2) + (b.length()/2)) * k;
            }else{
                long mc = 0L, tmp = 1;
                for (int i = 1; i < m.length(); i++) {
                    if(m.charAt(i-1) == m.charAt(i)){
                        tmp++;
                    }else{
                        mc += tmp/2;
                        tmp = 1;
                    }
                }
                mc += tmp/2;
                if(f.charAt(0) == b.charAt(0)){
                    ans = mc * k;
                    ans += f.length()/2 + b.length()/2;
                    ans += ( (f.length() + b.length()) / 2 ) * (k-1);
                }else{
                    ans = ( (f.length()/2) + (b.length()/2) + mc ) * k;
                }
            }
        }
        System.out.println(ans);
        sc.close();

    }

}

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


Question:
import java.util.*;

public class Main {

    static HashSet<Integer> q;
    static HashMap<Integer, ArrayDeque<Integer>> map;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            ArrayDeque<Integer> deq = new ArrayDeque<>(n-1);
            for (int j = 0; j < n-1; j++) {
                deq.add(sc.nextInt()-1);
            }
            map.put(i, deq);
        }
        int ans = 0;
        q = new HashSet<>();
        for (int i = 0; i < n; i++) {
            check(i,q);
        }
        while(!q.isEmpty()){
            ans++;
            HashSet<Integer> nexq = new HashSet<>();
            for(int i : q){
                int a = i / 10000;
                int b = i % 10000;
                map.get(a).poll();
                map.get(b).poll();
            }
            for(int i : q){
                int a = i / 10000;
                int b = i % 10000;
                check(a, nexq);
                check(b, nexq);
            }
            q = nexq;
        }
        boolean able = true;
        for (int i = 0; i < n; i++) {
            if(0 < map.get(i).size()){
                able = false;
                break;
            }
        }
        System.out.println(able ? ans : -1);
        sc.close();

    }

    private static void check(int i , HashSet<Integer> set){
        if(map.get(i).isEmpty()) return;
        int x = map.get(i).peek();
        if(map.get(x).isEmpty() || map.get(x).peek() != i) return;
        int tmp = i * 10000 + x;
        if(x < i) tmp = x * 10000 + i;
        set.add(tmp);
    }

}

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


Question:
import java.util.*;

public class Main {

    static HashSet<Integer> q;
    static HashMap<Integer, ArrayDeque<Integer>> map;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            ArrayDeque<Integer> deq = new ArrayDeque<>(n-1);
            for (int j = 0; j < n-1; j++) {
                deq.add(sc.nextInt()-1);
            }
            map.put(i, deq);
        }
        int ans = 0;
        q = new HashSet<>();
        for (int i = 0; i < n; i++) {
            check(i,q);
        }
        while(!q.isEmpty()){
            ans++;
            HashSet<Integer> nexq = new HashSet<>();
            for(int i : q){
                int a = i / 10000;
                int b = i % 10000;
                map.get(a).poll();
                map.get(b).poll();
            }
            for(int i : q){
                int a = i / 10000;
                int b = i % 10000;
                check(a, nexq);
                check(b, nexq);
            }
            q = nexq;
        }
        boolean able = true;
        for (int i = 0; i < n; i++) {
            if(0 < map.get(i).size()){
                able = false;
                break;
            }
        }
        System.out.println(able ? ans : -1);
        sc.close();

    }

    private static void check(int i , HashSet<Integer> set){
        if(map.get(i).isEmpty()) return;
        int x = map.get(i).peek();
        if(map.get(x).isEmpty() || map.get(x).peek() != i) return;
        int tmp = i * 10000 + x;
        if(x < i) tmp = x * 10000 + i;
        set.add(tmp);
    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int mod = 1_000_000_007;
        int n = sc.nextInt();
        int k = sc.nextInt();
        int r = n - k + 1;
        int b = k - 1;
        Combination conR = new Combination(r, mod);
        Combination conB = new Combination(b, mod);
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= k; i++) {
            long tmp = 0L;
            if (i - 1 <= n - k) {
                tmp = ( conB.comb(b, i - 1) * conR.comb(r, i)) % mod;
            }
            sb.append(tmp).append("\n");
        }
        System.out.println(sb.toString());
        sc.close();

    }

}

class Combination {

    /** factorial:階乗 */
    private long fac[];
    /** inverse:逆元（ここでは、fac[i]をMOD-2乗したものをMODで割った余り） */
    private long inv[];
    /** 除数 */
    private int mod;

    /**
     * コンストラクタ
     * @param size 組み合わせの対象となる個数
     * @param mod 除数
     */
    public Combination(int size, int mod) {
        this.fac = new long[size + 1];
        this.inv = new long[size + 1];
        this.mod = mod;

        this.fac[0] = 1;
        this.inv[0] = 1;

        for (int i = 1; i <= size; i++) {
            fac[i] = (fac[i - 1] * i) % mod;
            inv[i] = modPow(fac[i], (int) mod - 2) % mod;
        }
    }

    /**
     * n個の中からr個選ぶ組み合わせの数（nCr）をmodで割った余りを算出する
     * @param n 元の集合の要素数
     * @param r 組み合わせる要素数
     * @return nCr % mod
     */
    public long comb(int n, int r) {
        return fac[n] * inv[r] % mod * inv[n - r] % mod;
    }

    /**
     * base^exp をmodで割った余りを算出する
     * @param base 基数
     * @param exp 指数
     * @return base^exp % mod
     */
    private long modPow(long base, int exp) {
        long ret = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) {
                ret = ret * base % mod;
            }
            base = base * base % mod;
            exp >>= 1;
        }
        return ret;
    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] a = new long[n];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
        Arrays.sort(a);
        long[][] b = new long[m][2];
        for (int i = 0; i < m; i++) {
            b[i][0] = sc.nextLong();
            b[i][1] = sc.nextLong();
        }
        Arrays.sort(b, (x, y) -> Long.compare(y[1], x[1]));
        boolean end = false;
        int idx = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < b[i][0]; j++) {
                if(idx <= n-1 && a[idx] < b[i][1]){
                    a[idx] = b[i][1];
                    idx++;
                }else{
                    end = true;
                    break;
                }
            }
            if(end) break;
        }
        for (int i = 0; i < n; i++) ans += a[i];
        System.out.println(ans);
        sc.close();

    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] a = new long[n];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
        Arrays.sort(a);
        long[][] b = new long[m][2];
        for (int i = 0; i < m; i++) {
            b[i][0] = sc.nextLong();
            b[i][1] = sc.nextLong();
        }
        Arrays.sort(b, (x, y) -> Long.compare(y[1], x[1]));
        boolean end = false;
        int idx = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < b[i][0]; j++) {
                if(idx <= n-1 && a[idx] < b[i][1]){
                    a[idx] = b[i][1];
                    idx++;
                }else{
                    end = true;
                    break;
                }
            }
            if(end) break;
        }
        for (int i = 0; i < n; i++) ans += a[i];
        System.out.println(ans);
        sc.close();

    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int k = sc.nextInt();
        long[] a = new long[x];
        long[] b = new long[y];
        long[] c = new long[z];
        for (int i = 0; i < x; i++) a[i] = sc.nextLong();
        for (int i = 0; i < y; i++) b[i] = sc.nextLong();
        for (int i = 0; i < z; i++) c[i] = sc.nextLong();
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        long[] sum = new long[110000];
        int cnt = 0;
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                for (int l = 0; l < z; l++) {
                    if((i+1)*(j+1)*(l+1) >k) break;
                    sum[cnt++] = a[x-1-i] + b[y-1-j] + c[z-1-l];
                }
            }
        }
        Arrays.sort(sum);
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < k; i++) {
            ans.append(sum[sum.length -1 - i] + "\n");
        }

        System.out.println(ans);
        sc.close();
    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int k = sc.nextInt();
        long[] a = new long[x];
        long[] b = new long[y];
        long[] c = new long[z];
        for (int i = 0; i < x; i++) a[i] = sc.nextLong();
        for (int i = 0; i < y; i++) b[i] = sc.nextLong();
        for (int i = 0; i < z; i++) c[i] = sc.nextLong();
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        long[] sum = new long[110000];
        int cnt = 0;
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                for (int l = 0; l < z; l++) {
                    if((i+1)*(j+1)*(l+1) >k) break;
                    sum[cnt++] = a[x-1-i] + b[y-1-j] + c[z-1-l];
                }
            }
        }
        Arrays.sort(sum);
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < k; i++) {
            ans.append(sum[sum.length -1 - i] + "\n");
        }

        System.out.println(ans);
        sc.close();
    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int k = sc.nextInt();
        long[] a = new long[x];
        long[] b = new long[y];
        long[] c = new long[z];
        for (int i = 0; i < x; i++) a[i] = sc.nextLong();
        for (int i = 0; i < y; i++) b[i] = sc.nextLong();
        for (int i = 0; i < z; i++) c[i] = sc.nextLong();
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        long[] sum = new long[110000];
        int cnt = 0;
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                for (int l = 0; l < z; l++) {
                    if((i+1)*(j+1)*(l+1) >k) break;
                    sum[cnt++] = a[x-1-i] + b[y-1-j] + c[z-1-l];
                }
            }
        }
        Arrays.sort(sum);
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < k; i++) {
            ans.append(sum[sum.length -1 - i] + "\n");
        }

        System.out.println(ans);
        sc.close();
    }

}

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


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

public class Main {

    static final int[] vol = new int[]{0,2,5,5,4,5,6,3,7,6};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[M];
        for (int i = 0; i < M; i++) {
            A[i] = sc.nextInt();
        }
        // dp[i]：ちょうどｉ本のマッチを使って作れる整数の最大の桁数
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MIN_VALUE);
        dp[0] = 0;
        for (int i = 2; i <= N; i++) {
            for(int a : A){
                if(i >= vol[a]) dp[i] = Math.max(dp[i], dp[i - vol[a]] + 1);
            }
        }
        Arrays.sort(A);
        StringBuilder sb = new StringBuilder();
        while(N > 0){
            for (int i = M-1; i >= 0; i--) {
                if(N - vol[A[i]] >= 0 && dp[N] - 1 == dp[N - vol[A[i]]]){
                    sb.append(A[i]);
                    N -= vol[A[i]];
                    break;
                }
            }
        }

        System.out.println(sb.toString());
        sc.close();

    }

}

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


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

public class Main {

    static final int[] vol = new int[]{0,2,5,5,4,5,6,3,7,6};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[M];
        for (int i = 0; i < M; i++) {
            A[i] = sc.nextInt();
        }
        // dp[i]：ちょうどｉ本のマッチを使って作れる整数の最大の桁数
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MIN_VALUE);
        dp[0] = 0;
        for (int i = 2; i <= N; i++) {
            for(int a : A){
                if(i >= vol[a]) dp[i] = Math.max(dp[i], dp[i - vol[a]] + 1);
            }
        }
        Arrays.sort(A);
        StringBuilder sb = new StringBuilder();
        while(N > 0){
            for (int i = M-1; i >= 0; i--) {
                if(N - vol[A[i]] >= 0 && dp[N] - 1 == dp[N - vol[A[i]]]){
                    sb.append(A[i]);
                    N -= vol[A[i]];
                    break;
                }
            }
        }

        System.out.println(sb.toString());
        sc.close();

    }

}

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


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

public class Main {

    static final int[] vol = new int[]{0,2,5,5,4,5,6,3,7,6};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[M];
        for (int i = 0; i < M; i++) {
            A[i] = sc.nextInt();
        }
        // dp[i]：ちょうどｉ本のマッチを使って作れる整数の最大の桁数
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MIN_VALUE);
        dp[0] = 0;
        for (int i = 2; i <= N; i++) {
            for(int a : A){
                if(i >= vol[a]) dp[i] = Math.max(dp[i], dp[i - vol[a]] + 1);
            }
        }
        Arrays.sort(A);
        StringBuilder sb = new StringBuilder();
        while(N > 0){
            for (int i = M-1; i >= 0; i--) {
                if(N - vol[A[i]] >= 0 && dp[N] - 1 == dp[N - vol[A[i]]]){
                    sb.append(A[i]);
                    N -= vol[A[i]];
                    break;
                }
            }
        }

        System.out.println(sb.toString());
        sc.close();

    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        boolean able = true;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if(i < a[i]) able = false;
            if(0 < i && a[i-1] < a[i] && 1 < a[i] - a[i-1]) able = false;
        }
        if(!able){
            System.out.println(-1);
        }else{
            long ans = 0L;
            int[] b = new int[n];
            Arrays.fill(b, -1);
            for (int i = n-1; i > 0; i--) {
                if(b[i] != a[i]){
                    ans += a[i];
                }
                b[i-1] = a[i] - 1;
            }
            System.out.println(ans);

        }
        sc.close();

    }

}

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


Question:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        boolean able = true;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if(i < a[i]) able = false;
            if(0 < i && a[i-1] < a[i] && 1 < a[i] - a[i-1]) able = false;
        }
        if(!able){
            System.out.println(-1);
        }else{
            long ans = 0L;
            int[] b = new int[n];
            Arrays.fill(b, -1);
            for (int i = n-1; i > 0; i--) {
                if(b[i] != a[i]){
                    ans += a[i];
                }
                b[i-1] = a[i] - 1;
            }
            System.out.println(ans);

        }
        sc.close();

    }

}

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


Question:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int R  = sc.nextInt();
        if (R < 1200){
            System.out.println("ABC");
        }
        else if (1200 <= R && R < 2800){
            System.out.println("ARC");
        }else{
            System.out.println("AGC");
        }
    }

}

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


Question:
import java.util.Scanner;

public class Main {

    public static String Y = "Yes";
    public static String N = "No";
    public static String I = "IMPOSSIBLE";
    public static String B = "Bad";
    public static String G = "Good";
    public static long MOD = (long) (Math.pow(10, 9) + 7);
    public static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        String s = n();
        int n = s.length();
        int[] mod = new int[2019];
        mod[0]++;

        int keta = 1;
        int top = 0;
        int now = 0;

        for (int i = n - 1; i >= 0; i--) {
            top = s.charAt(i) - '0';

            now = top * keta + now;
            now %= 2019;
            mod[now]++;

            keta *= 10;
            keta %= 2019;
        }

        long ans = 0l;
        for (int count : mod) {
            if (count > 1) {
                count--;
                ans += count * (count + 1) / 2l;
            }
        }
        out(ans);

    }

    public static int count(String search, String text) {

        int nsearch = search.length();
        int ntext = text.length();
        int count = 0;

        for (int i = 0; i <= ntext - nsearch + 1; i++) {
            for (int j = i + nsearch - 1; j < ntext; j++) {
                if (search.equals(text.substring(i, j + 1))) {
                    count++;
                }
            }
        }

        return count;
    }

    /*
     * 以下メソッド集
     */
    static int ni() {

        return sc.nextInt();
    }

    static long nl() {

        return sc.nextLong();
    }

    static String n() {

        return sc.next();
    }

    static char[] nc() {

        return sc.next().toCharArray();
    }

    static int kaijo(int n) {

        if (n == 0 || n == 1) {
            return 1;
        } else {
            return n * kaijo(n - 1);
        }
    }

    static int fib(int n) {

        return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
    }

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

    static void out(char info) {

        System.out.println(info);
    }

    static void outn(String info) {

        System.out.print(info);
    }

    static void outn(int info) {

        System.out.print(info);
    }

    static void outn(double info) {

        System.out.print(info);
    }

    static void outn(long info) {

        System.out.print(info);
    }

    static void outn(char info) {

        System.out.print(info);
    }

    static int max(int a, int b) {

        return Math.max(a, b);
    }

    static long max(long a, long b) {

        return Math.max(a, b);
    }

    static int min(int a, int b) {

        return Math.min(a, b);
    }

    static long min(long a, long b) {

        return Math.min(a, b);
    }
}

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


Question:
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		long numR = 0;
		long numG = 0;
		long numB = 0;
		long ans = 0;
		for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if (c == 'R') {
				numR++;
			} else if (c == 'G') {
				numG++;
			} else {
				numB++;
			}
		}
		// 組み合わせの数を計算
		ans = numR * numG * numB;
		for (int a = 1; a < N; a++) {
			for (int sa = 1; a + sa * 2 <= N; sa++) {
				if (S.charAt(a - 1) != S.charAt(a + sa - 1) && S.charAt(a - 1) != S.charAt(a + sa * 2 - 1)
						&& S.charAt(a + sa - 1) != S.charAt(a + sa * 2 - 1)) {
					ans--;
				}
			}
		}
		System.out.println(ans);
	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

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

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

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

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		long numR = 0;
		long numG = 0;
		long numB = 0;
		long ans = 0;
		for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if (c == 'R') {
				numR++;
			} else if (c == 'G') {
				numG++;
			} else {
				numB++;
			}
		}
		// 組み合わせの数を計算
		ans = numR * numG * numB;
		for (int a = 1; a < N; a++) {
			for (int sa = 1; a + sa * 2 <= N; sa++) {
				if (S.charAt(a - 1) != S.charAt(a + sa - 1) && S.charAt(a - 1) != S.charAt(a + sa * 2 - 1)
						&& S.charAt(a + sa - 1) != S.charAt(a + sa * 2 - 1)) {
					ans--;
				}
			}
		}
		System.out.println(ans);
	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

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

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

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

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}

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


Question:
import java.util.Scanner;

public class Main {

    public static String Y = "Yes";
    public static String N = "No";
    public static long MOD = (long) (Math.pow(10, 9) + 7);
    public static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        int n = ni(); // 長さ
        int q = ni(); // 問い
        String s = n();

        int[] acindex = new int[n];
        int account = 0;
        acindex[0] = account;

        // ACの最初のAのindexを取得
        for (int i = 1; i < n; i++) {

            char a = s.charAt(i - 1);
            char c = s.charAt(i);
            if (a == 'A' && c == 'C') {
                account++;
                acindex[i] = account;
            } else {
                acindex[i] = account;
            }
        }

        for (int i = 0; i < q; i++) {
            int l = ni();
            int r = ni();

            out(acindex[r - 1] - acindex[l - 1]);
        }

    }

    /*
     * 以下メソッド集
     */

    static int ketasuu(int n) {

        String str = "" + n;
        return str.length();
    }

    static int abcount(String str) {

        int count = 0;
        int len = str.length();
        for (int i = 0; i < len - 1; i++) {
            if ("AB".equals(str.substring(i, i + "AB".length()))) {
                count++;
            }
        }
        return count;
    }

    static int ni() {

        return sc.nextInt();
    }

    static long nl() {

        return sc.nextLong();
    }

    static double nd() {

        return sc.nextDouble();
    }

    static String n() {

        return sc.next();
    }

    static char[] nc() {

        return sc.next().toCharArray();
    }

    static int kaijo(int n) {

        if (n == 0 || n == 1) {
            return 1;
        } else {
            return n * kaijo(n - 1);
        }
    }

    static int fib(int n) {

        return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
    }

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

    static void out(char info) {

        System.out.println(info);
    }

    static void out(Object obj) {

        System.out.println(obj.toString());
    }

    static void outn(String info) {

        System.out.print(info);
    }

    static void outn(int info) {

        System.out.print(info);
    }

    static void outn(double info) {

        System.out.print(info);
    }

    static void outn(long info) {

        System.out.print(info);
    }

    static void outn(char info) {

        System.out.print(info);
    }

    static double max(double d, double e) {

        return Math.max(d, e);
    }

    static long max(long a, long b) {

        return Math.max(a, b);
    }

    static double min(double d, double e) {

        return Math.min(d, e);
    }

    static long min(long a, long b) {

        return Math.min(a, b);
    }
}

class XY {

    int h;
    int c;

    XY(int h, int c) {
        this.h = h;
        this.c = c;
    }
}

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


Question:
import java.util.Scanner;

public class Main {

    public static String Y = "Yes";
    public static String N = "No";
    public static long MOD = (long) (Math.pow(10, 9) + 7);
    public static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        int n = ni(); // 長さ
        int q = ni(); // 問い
        String s = n();

        int[] acindex = new int[n];
        int account = 0;
        acindex[0] = account;

        // ACの最初のAのindexを取得
        for (int i = 1; i < n; i++) {

            char a = s.charAt(i - 1);
            char c = s.charAt(i);
            if (a == 'A' && c == 'C') {
                account++;
                acindex[i] = account;
            } else {
                acindex[i] = account;
            }
        }

        for (int i = 0; i < q; i++) {
            int l = ni();
            int r = ni();

            out(acindex[r - 1] - acindex[l - 1]);
        }

    }

    /*
     * 以下メソッド集
     */

    static int ketasuu(int n) {

        String str = "" + n;
        return str.length();
    }

    static int abcount(String str) {

        int count = 0;
        int len = str.length();
        for (int i = 0; i < len - 1; i++) {
            if ("AB".equals(str.substring(i, i + "AB".length()))) {
                count++;
            }
        }
        return count;
    }

    static int ni() {

        return sc.nextInt();
    }

    static long nl() {

        return sc.nextLong();
    }

    static double nd() {

        return sc.nextDouble();
    }

    static String n() {

        return sc.next();
    }

    static char[] nc() {

        return sc.next().toCharArray();
    }

    static int kaijo(int n) {

        if (n == 0 || n == 1) {
            return 1;
        } else {
            return n * kaijo(n - 1);
        }
    }

    static int fib(int n) {

        return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
    }

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

    static void out(char info) {

        System.out.println(info);
    }

    static void out(Object obj) {

        System.out.println(obj.toString());
    }

    static void outn(String info) {

        System.out.print(info);
    }

    static void outn(int info) {

        System.out.print(info);
    }

    static void outn(double info) {

        System.out.print(info);
    }

    static void outn(long info) {

        System.out.print(info);
    }

    static void outn(char info) {

        System.out.print(info);
    }

    static double max(double d, double e) {

        return Math.max(d, e);
    }

    static long max(long a, long b) {

        return Math.max(a, b);
    }

    static double min(double d, double e) {

        return Math.min(d, e);
    }

    static long min(long a, long b) {

        return Math.min(a, b);
    }
}

class XY {

    int h;
    int c;

    XY(int h, int c) {
        this.h = h;
        this.c = c;
    }
}

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


Question:
import java.util.Scanner;

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

		System.out.println(T/X);
	}
}

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


Question:
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int[] a = new int[n];
		int index = 0;
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
			if (a[i] == 1)
				index = i;
		}
		int ans = 0;
		loop: while (true) {
			int i = 0;
			while (a[i] != 1)
				i++;
			if (i == 0) {
				while (i < n && a[i] == 1)
					i++;
				if (i == n) break loop;
				for (int j = i - 1; j < Math.min(i - 1 + k, n); j++)
					a[j] = 1;
			}
			else {
				int s = i - k + 1;
				if (s < 0) s = 0;
				else {
					while (s % (k - 1) != 0)
						s++;
				}
				for (int j = s; j < Math.min(s + k, n); j++) {
					a[j] = 1;
				}
			}
			ans++;
		}
		System.out.println(ans);
	}
}

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


Question:
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] p = new int[n + 1];
		for (int i = 1; i <= n; i++)
			p[Integer.parseInt(sc.next())] = i;
		int max = 1;
		int tem = 1;
		for (int i = 2; i <= n; i++) {
			if (p[i] < p[i - 1])
				tem = 1;
			else
				tem++;
			max = Math.max(max, tem);
		}
		System.out.println(n - max);
	}
}

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


Question:
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] p = new int[n + 1];
		for (int i = 1; i <= n; i++)
			p[Integer.parseInt(sc.next())] = i;
		int max = 1;
		int tem = 1;
		for (int i = 2; i <= n; i++) {
			if (p[i] < p[i - 1])
				tem = 1;
			else
				tem++;
			max = Math.max(max, tem);
		}
		System.out.println(n - max);
	}
}

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


Question:
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] p = new int[n + 1];
		for (int i = 1; i <= n; i++)
			p[Integer.parseInt(sc.next())] = i;
		int max = 1;
		int tem = 1;
		for (int i = 2; i <= n; i++) {
			if (p[i] < p[i - 1])
				tem = 1;
			else
				tem++;
			max = Math.max(max, tem);
		}
		System.out.println(n - max);
	}
}

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


Question:
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.equals("zyxwvutsrqponmlkjihgfedcba")) {
			System.out.println("-1");
			return;
		}
		String[] a = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
		String[] t = s.split("");
		if (s.length() == 26) {
			for (int i = 24; i >= 0; i--) {
				for (int j = 0; j < 26; j++) {
					boolean exist = false;
					for (int k = 0; k < i; k++) {
						if (a[j].equals(t[k])) {
							exist = true;
							break;
						}
					}
					if (!exist) {
						if (s.charAt(i) < a[j].charAt(0)) {
							System.out.println(s.substring(0, i) + a[j]);
							return;
						}
					}
				}
			}
		}
		for (int i = 0; i < a.length; i++) {
			boolean exist = false;
			for (int j = 0; j < t.length; j++) {
				if (a[i].equals(t[j])) {
					exist = true;
					break;
				}
			}
			if (!exist) {
				System.out.println(s + a[i]);
				return;
			}
		}
	}
}

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


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

public class Main {
   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      int D = input.nextInt();
      int T = input.nextInt();
      int S = input.nextInt();

      if(D > T*S) {
         System.out.println("No");
      }  else {
         System.out.println("Yes");
      }
      input.close();

   }

}

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


Question:
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {

    	FastScanner scan = new FastScanner();

    	int n = scan.nextInt();
    	long count = 0;

    outer:	for(int i = 1; i<n; i++) {
    		for(int j=1; j<n; j++) {
    			if(i * j < n) count++;
    			else continue outer;
    		}
    	}

    	System.out.println(count);

    }

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

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

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

    }

}

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


Question:
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner file = new Scanner(System.in);
      	String s = file.next(), t = file.next();
      	System.out.println(s.equals(t.substring(0, t.length() - 1)) ? "Yes" : "No");
      	file.close();
    }
}

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


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

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

		int ans = a/111;
		if(a%111 != 0) {
			ans+= 1;
		}

		System.out.println(ans*111);
	}

}

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


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

	public static void main(String[] args) { //
		Scanner input = new Scanner(System.in);
		long A = input.nextLong();
		String S = input.next();
		String whole = S.substring(0,1);
		String decimal = S.substring(2,4);
		long B = Long.parseLong(whole);
		long C = Long.parseLong(decimal);
		long D = B*100+C;
		long ans = A*D;
		ans/=100;
		System.out.println(ans);
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int[] vis = new int[2000001];
		int N = input.nextInt();
		long cnt = 0;
		for (int i = 1; i <= N; i++) {
			int x = input.nextInt();
			if (i+x<=200000) vis[i+x]++;
			if (i-x>=0) cnt+=vis[i-x];
		}
		System.out.println(cnt);
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int[] vis = new int[2000001];
		int N = input.nextInt();
		long cnt = 0;
		for (int i = 1; i <= N; i++) {
			int x = input.nextInt();
			if (i+x<=200000) vis[i+x]++;
			if (i-x>=0) cnt+=vis[i-x];
		}
		System.out.println(cnt);
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int[] vis = new int[2000001];
		int N = input.nextInt();
		long cnt = 0;
		for (int i = 1; i <= N; i++) {
			int x = input.nextInt();
			if (i+x<=200000) vis[i+x]++;
			if (i-x>=0) cnt+=vis[i-x];
		}
		System.out.println(cnt);
	}
}

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


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

	public static void main(String[] args) {
		long mod = (long)(1e9+7);
		Scanner input = new Scanner(System.in);
		boolean valid = false;
		int K = input.nextInt();
		int A = input.nextInt();
		int B = input.nextInt();
		for (int i = A; i <= B; i++) {
			if (i%K==0) {
				valid = true;
				break;
			}
		}
		System.out.println(valid?"OK":"NG");
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String s = input.next();
		long[] dp = new long[2019]; //stores remainder from 0-2018
		int cur = Integer.parseInt(s.substring(s.length()-1,s.length()));
		dp[cur]++;
		dp[0]=1;
		long cnt = 0;
		long pow_10 = 10;
		long div = 2019;
		//(2019 does not share any divisors with 10 (the base),
		//therefore storing remainder trick works.
		for (int i = s.length()-2; i >= 0; i--) {
			long digit = Long.parseLong(s.substring(i,i+1));
			cur+=digit*pow_10;
			pow_10*=10;
			pow_10%=div;
			cur%=div;
			dp[cur]++;
		}
		for (int i = 0; i < 2019; i++) {
			cnt+=(dp[i])*(dp[i]-1)/2;
		}
		System.out.println(cnt);
	}
}

Choices:
- No abnormally found
- Runtime Error
- 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);
		String s = input.next();
		long[] dp = new long[2019]; //stores remainder from 0-2018
		int cur = Integer.parseInt(s.substring(s.length()-1,s.length()));
		dp[cur]++;
		dp[0]=1;
		long cnt = 0;
		long pow_10 = 10;
		long div = 2019;
		//(2019 does not share any divisors with 10 (the base),
		//therefore storing remainder trick works.
		for (int i = s.length()-2; i >= 0; i--) {
			long digit = Long.parseLong(s.substring(i,i+1));
			cur+=digit*pow_10;
			pow_10*=10;
			pow_10%=div;
			cur%=div;
			dp[cur]++;
		}
		for (int i = 0; i < 2019; i++) {
			cnt+=(dp[i])*(dp[i]-1)/2;
		}
		System.out.println(cnt);
	}
}

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


Question:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) { //No TLE!!
		Scanner input = new Scanner(System.in);
		int N = Integer.parseInt(input.nextLine());
		String S = input.nextLine();
		int[][] counts = counters(S,N);
		/*for (int i = 0; i < N; i++) {
			System.out.println(counts[i][0]+" "+counts[i][1]+" "+counts[i][2]);
		}*/
		long cnt=0;
		for (int gap = 1; gap <= N; gap++) {
			for (int start = 0; start < N-gap; start++) {
				int middle = start+gap;
				if (S.charAt(start)!=S.charAt(middle)) {
					if (S.charAt(start)=='R'&&S.charAt(middle)=='G'||S.charAt(start)=='G'&&S.charAt(middle)=='R') {
						cnt+=counts[N-1][2]-counts[middle][2];
						if (middle+gap<N) {
							if (S.charAt(middle+gap)=='B'&& cnt>0) cnt--;
						}
					}
					if (S.charAt(start)=='R'&&S.charAt(middle)=='B'||S.charAt(start)=='B'&&S.charAt(middle)=='R') {
						cnt+=counts[N-1][1]-counts[middle][1];
						if (middle+gap<N) {
							if (S.charAt(middle+gap)=='G') cnt--;
						}
					}
					if (S.charAt(start)=='B'&&S.charAt(middle)=='G'||S.charAt(start)=='G'&&S.charAt(middle)=='B') {
						cnt+=counts[N-1][0]-counts[middle][0];
						if (middle+gap<N) {
							if (S.charAt(middle+gap)=='R') cnt--;
						}
					}
				}
			}
		}
		System.out.println(cnt);
	}
	public static int[][] counters(String S, int N){ //1st slot = i; 2,3,4 slot = R,G,B cnt
		int[][] counts = new int[N][3];
		int cntR = 0;
		int cntG = 0;
		int cntB = 0;
		for (int i = 0; i < N; i++) {
			if (S.charAt(i)=='R') cntR++;
			if (S.charAt(i)=='G') cntG++;
			if (S.charAt(i)=='B') cntB++;
			counts[i][0]=cntR;
			counts[i][1]=cntG;
			counts[i][2]=cntB;
		}
		return counts;
	}
}

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


Question:
import java.util.Scanner;

public class Main {

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

Choices:
- Internal error
- No abnormally found
- Memory Limit Exceeded
- Compile 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[] dp = new int[N+1];
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = input.nextInt();
			dp[arr[i]]++;
		}
		long TOTAL = 0;
		for (int i = 1; i <= N; i++) {
			TOTAL+=C2(dp[i]);
		}
		for (int k = 0; k < N; k++) {
			long Temp = TOTAL-C2(dp[arr[k]]);
			Temp+=C2(dp[arr[k]]-1);
			System.out.println(Temp);
		}
	}
	public static long C2(long N) {
		return N*(N-1)/2;
	}
}

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


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

	public static void main(String[] args) {
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long H = I.nextLong();
		int N = I.nextInt();
		for (int i = 0; i < N; i++) {
			long cur = I.nextLong();
			H-=cur;
		}
		O.pln(H<=0?"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:
- Compile Error
- Runtime 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);
		int N = input.nextInt();
		int M = input.nextInt();
		long ans = 0;
		ArrayList<Long> deductions = new ArrayList<Long>();
		for (int i = 0; i < N; i++) {
			long x = input.nextLong();
			ans+=x;
			while (x>0) {
				long sub = x-x/2;
				deductions.add(sub);
				x/=2;
			}
		}
		Collections.sort(deductions);
		int index = deductions.size()-1;
		int cnt = 0;
		while (cnt < M) {
			ans-=deductions.get(index);
			cnt++;
			index--;
			if (index==-1) break;
		}
		System.out.println(ans);
	}
}

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


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 (N==1) System.out.println(1);
		else {
			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:
- Memory Limit Exceeded
- No abnormally found
- Runtime Error
- Time Limit Exceeded


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

	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;
			N=Math.max(N, 0);
			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:
- Memory Limit Exceeded
- No abnormally found
- Time Limit Exceeded
- Runtime Error


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

public class Main {

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

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

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

  }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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