ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: java

Solution 1 (runtime: 484 ms):
import java.util.*;

public class C_Uninteresting_Number{
    static HashMap<Integer, Boolean> hm;
    public static boolean func(int num, int two, int three){
        if(num%9==0)return true;
        if(two==0&&three==0)return false;
        if(hm.containsKey(num))return hm.get(num);
        boolean t=false, th=false;
        if(two>0){
            t = func(num+2, two-1, three);
        }
        if(three>0){
            th = func(num+6, two, three-1);
        }
        hm.put(num, t|th);
        return t|th;
    }
    public static void main(String args[]){
        Scanner scn = new Scanner(System.in);
        int t = scn.nextInt();
        while(t-->0){
            String s = scn.next();
            int n = s.length();
            int num = 0;
            int two = 0, three=0;
            for(int i = 0; i < n; i++){
                num += (s.charAt(i)-'0');
                if(s.charAt(i)=='2')two++;
                if(s.charAt(i)=='3')three++;
            }
            hm = new HashMap<>();
            boolean ans = func(num, two, three);
            if(ans)
            System.out.println("YES");
            else System.out.println("NO");
        }
    }
}

Solution 2 (runtime: 296 ms):
import java.util.*;
import java.io.*;

public class Main {
    static Scanner f;
    static PrintWriter out;

    public static void main(String[] args) throws Exception {
        // f = new Scanner(new File("input.txt"));
        // out = new PrintWriter(new File("output.txt"));
        f = new Scanner(System.in);
        out = new PrintWriter(System.out);

        int t = f.nextInt();
        f.nextLine();
        while(t-- > 0) {
            solve();
        }

        out.close();
    }


    public static void solve() {
        String s = f.nextLine();
        int n = s.length();
        int sum = 0;
        int count2 = 0;
        int count3 = 0;
        for(int i = 0; i < n; i++) {
            sum += s.charAt(i)-'0';
            if(s.charAt(i) == '2') {
                count2++;
            } else if(s.charAt(i) == '3') {
                count3++;
            }
        }

        for(int i = 0; i <= Math.min(50, count2); i++) {
            for(int j = 0; j <= Math.min(50, count3); j++) {
                if((sum+2*i+6*j)%9 == 0) {
                    out.println("YES");
                    return;
                }
            }
        }
        out.println("NO");
    }


}
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 375 ms):
import java.util.*;
import java.io.*;

public class Main {
	static InputStream inputStream;
	static OutputStream outputStream;
	static InputReader in;
	static PrintWriter out;
	static int MULTIPLE_TESTACES = 1;
  
	///////////////////////////////////////
	// solution
	///////////////////////////////////////
	static class Solution {
    
    private boolean pos(ArrayList<Long> o){
			int n = o.size();
			ArrayList<Long> a = new ArrayList<Long>();
			for(Long x: o){
				a.add(x);
			}
			for(int i=0; i<n-1;++i){
				long x = a.get(i);
				long y = a.get(i+1);
				long m = Math.min(x, y);
				a.set(i, x-m);
				a.set(i+1, y-m);
			}
			for(int i=0; i<n-1;++i){
				long x = a.get(i);
				long y = a.get(i+1);
				if(x > y)return false;
			}
			return true;
		}
		
		public void solve(int tc) throws IOException{
			int n = in.nextInt();
			ArrayList<Long> a = new ArrayList<Long>();
			for(int i=0; i<n;++i){
				a.add(in.nextLong());
			}
			boolean ans = false;
			ans |= pos(a);
			out.println(ans ? "YES":"NO");
		}	
	}
	
	
	
	
	
	///////////////////////////////////////
	// template
	///////////////////////////////////////
	public static void main(String[] args) throws IOException{
			inputStream = System.in;
			outputStream = System.out;
			in = new InputReader(inputStream);
			out = new PrintWriter(outputStream);
			int tc = 1;
			if(MULTIPLE_TESTACES>0)tc = in.nextInt();
			Solution sol = new Solution();
			for(int i=1; i<=tc;++i){
				 sol.solve(i);
			}
			in.close();
			out.close();
	}
	
	static class InputReader {
		BufferedReader reader;
		StringTokenizer st;
		public InputReader(InputStream in){
			reader = new BufferedReader(new InputStreamReader(in));
			st = null;
		}
		
		public String next() throws IOException{
			while(st == null || !st.hasMoreTokens()){
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}
		
		public Long nextLong() throws IOException{
			return Long.parseLong(next());
		}
		
		public Integer nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		
		public void close() throws IOException{
			reader.close();
		}
	}
}


Solution 2 (runtime: 639 ms):
import java.util.Scanner;



public class Main {

    static  boolean check(int[] arr){

        for (int i = 0; i < arr.length-1; i++) {

            if (arr[i]>arr[i+1]) return  false;

        }

        return true;

    }

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t = sc.nextInt();

        while(t-->0) {

            int n = sc.nextInt();

            int[] a =new int[n];

            for (int i = 0; i < n; i++) {

                a[i]= sc.nextInt();

            }

            boolean flag=false;

            int i =0;

            while (i< n-1){

                int min=Math.min(a[i],a[i+1]);

                a[i]=a[i]-min;

                a[i+1]=a[i+1]-min;

                i++;

            }

            if (check(a)) System.out.println("YES");

            else System.out.println("NO");

        }

    }

}
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 671 ms):
import java.util.*;
 
public class bit {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            int arr[] = new int[n];
            for(int i=0;i<n;i++){
                arr[i]=sc.nextInt();
            }
            String ans = "YES";
            if(arr[0]>arr[1]){
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n-1;i++){
                if(arr[i]>arr[i+1]){
                    ans = "NO";
                    break;
                }else{
                    arr[i+1]-=arr[i];
                    arr[i]-=arr[i];
                }
            }
            System.out.println(ans);
            
        } 
    }
}




Solution 2 (runtime: 359 ms):




import java.io.*;

import java.util.*;



public class Main{

	static StreamTokenizer cins=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

	static PrintWriter cout=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	static int cin()throws Exception {

		cins.nextToken();

		return (int)cins.nval;

	}

	static void solve() throws Exception{

		int n=cin();

		int a[]=new int[n+1];

		for(int i=1;i<=n;i++) {

			a[i]=cin();

		}

		

		for(int i=1;i+1<=n;i++) {

			int now=Math.min(a[i],a[i+1]);

			a[i]-=now;

			a[i+1]-=now;

			if(a[i]>a[i+1]) {

				cout.println("no");

				cout.flush();

				return;

			}

		}

		cout.println("Yes");

		cout.flush();

	}

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

		int t=cin();

		while(t--!=0)solve();

	}

}
Problem: 2050D - Digital string maximization
Language: java

Solution 1 (runtime: 312 ms):
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            String s=sc.next();
            char[] res=s.toCharArray();
            for(int i=1;i<s.length();i++){
                if(res[i]>res[i-1]){
                    while(i>0 && res[i]>res[i-1] && res[i]-res[i-1]>1){
                        res[i]--;
                        char temp=res[i];
                        res[i]=res[i-1];
                        res[i-1]=temp;
                        i--;
                    }
                }
            }
            String str=new String(res);
            System.out.println(str);
        }
        sc.close();
    }
}

Solution 2 (runtime: 234 ms):
import java.util.Scanner;

public class D_2050 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        sc.nextLine();
        while (t-- > 0) {
            String s = sc.nextLine();
            char[] arr = s.toCharArray();
            int swapcount = 1;
            int ans = 0;
            while (swapcount != 0) {
                int sw = 0;
                for (int i = 1; i < arr.length; i++) {
                    char a = (char) (arr[i] - 1);
                    char b = arr[i - 1];
                    if ((arr[i] != '1' || arr[i] != '0') && a - b > 0) {
                        if (arr[i] > arr[i - 1]) {
                            swap(i - 1, i, arr);
                            sw++;
                        }
                    }
                }

                if (sw == 0) {
                    break;
                }
            }
            System.out.println(new String(arr));
        }
    }

    public static void swap(int i, int j, char[] arr) {
        arr[j] = (char) (arr[j] - 1);
        char t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    }
}
Problem: 2050C - Uninteresting Number
Language: java

Solution 1 (runtime: 265 ms):
import java.io.*;
import java.util.*;

public class Main{

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		int t = Integer.parseInt(br.readLine());

		while(t-- > 0){
			String num = br.readLine();
			char[] s = num.toCharArray();
			boolean[] dp = new boolean[9];
			dp[0] = true;

			for(char c: s){
				boolean[] ndp = new boolean[9];
				for(int i = 0; i < 9; i++){
					if(dp[i]){
						int digit = c - '0';
						while(digit <= 9){
							ndp[(i+digit)%9] = true;
							if(digit <= 1) break;
							digit *= digit;
						}
					}
				}
				dp = ndp;
			}

			bw.write(dp[0] ? "YES\n" : "NO\n");

		}

		bw.flush();
		br.close();
		bw.close();
		
	}

}

Solution 2 (runtime: 484 ms):
import java.util.*;

public class C_Uninteresting_Number{
    static HashMap<Integer, Boolean> hm;
    public static boolean func(int num, int two, int three){
        if(num%9==0)return true;
        if(two==0&&three==0)return false;
        if(hm.containsKey(num))return hm.get(num);
        boolean t=false, th=false;
        if(two>0){
            t = func(num+2, two-1, three);
        }
        if(three>0){
            th = func(num+6, two, three-1);
        }
        hm.put(num, t|th);
        return t|th;
    }
    public static void main(String args[]){
        Scanner scn = new Scanner(System.in);
        int t = scn.nextInt();
        while(t-->0){
            String s = scn.next();
            int n = s.length();
            int num = 0;
            int two = 0, three=0;
            for(int i = 0; i < n; i++){
                num += (s.charAt(i)-'0');
                if(s.charAt(i)=='2')two++;
                if(s.charAt(i)=='3')three++;
            }
            hm = new HashMap<>();
            boolean ans = func(num, two, three);
            if(ans)
            System.out.println("YES");
            else System.out.println("NO");
        }
    }
}
Problem: 2062C - Cirno and Operations
Language: java

Solution 1 (runtime: 327 ms):
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

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

    int t = sc.nextInt();
    for (int tc = 0; tc < t; ++tc) {
      int n = sc.nextInt();
      int[] a = new int[n];
      for (int i = 0; i < a.length; ++i) {
        a[i] = sc.nextInt();
      }

      System.out.println(solve(a));
    }

    sc.close();
  }

  static long solve(int[] a) {
    long[] values = Arrays.stream(a).asLongStream().toArray();

    long result = Arrays.stream(values).sum();
    while (values.length != 1) {
      long[] values_ = values;
      values =
          IntStream.range(0, values.length - 1)
              .mapToLong(i -> values_[i + 1] - values_[i])
              .toArray();

      result = Math.max(result, Math.abs(Arrays.stream(values).sum()));
    }

    return result;
  }
}


Solution 2 (runtime: 187 ms):
// package recurison;

import java.io.*;
import java.util.*;

public class ddd {
	public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- > 0) {
        	int n = sc.nextInt();
        	ArrayList<Long> ll = new ArrayList<>();
        	long ans = 0;
        	for(int i = 0; i < n; i++) {
        		long a = sc.nextInt();
        		ll.add(a);
        		ans += a;
        	}
        	
        	while(n-- > 1) {
        		ArrayList<Long> arr = new ArrayList<>();
        		for(int i = 1; i < ll.size(); i++) {
        			arr.add(ll.get(i)-ll.get(i-1));
        		}
        		
        		long sum = 0;
        		for(long i : arr) sum += i;
        		ans = Math.max(ans, Math.abs(sum));
        		ll = new ArrayList<>(arr);
        	}
        	
        	System.out.println(ans);
        }
    }
}
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 655 ms):
import java.util.*;
import java.lang.*;
import java.math.BigInteger;
import java.io.*;
public class cf{
    // public static long gcd(long a,long b){
    //     while(a!=0 && b!=0){
    //         if(a<b){
    //             b=b%a;
    //         }else{
    //             a=a%b;
    //         }
    //     }
    //     if(a!=0){
    //         return a;
    //     }else{
    //         return b;
    //     }
    // }  
    // public static long lcm(long a,long b){
    //     return (a/gcd(a,b))*b;
    // }

    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int tsts=sc.nextInt();
        for(int t=0;t<tsts;t++){
            int n=sc.nextInt();
            // int k=sc.nextInt();
            // int a4=sc.nextInt();
            // int a5=sc.nextInt();
            // int r2=sc.nextInt();
            // StringBuilder s=new StringBuilder(sc.next());
            // String a=sc.next();
            // String b=sc.next();
            // String c=sc.next();
            int[] a=new int[n];
            for(int i=0;i<n;i++){
                a[i]=sc.nextInt();
            }
            // int[] b=new int[n];
            // for(int i=0;i<n;i++){
            //     b[i]=sc.nextInt();
            // }
            // long n=sc.nextLong();
            // long k=sc.nextLong();
            // long r=sc.nextInt();
            // long c=sc.nextInt();
            for(int i=0;i<n-1;i++){
                int temp=Math.min(a[i],a[i+1]);
                a[i]-=temp;
                a[i+1]-=temp;
            }
            int[] b=new int[n];
            for(int i=0;i<n;i++){
                b[i]=a[i];
            }
            Arrays.sort(b);
            boolean flag=true;
            for(int i=0;i<n;i++){
                if(a[i]!=b[i]){
                    flag=false;
                    break;
                }
            }
            if(flag) System.out.println("Yes");
            else System.out.println("No");
        }    
    }
}

Solution 2 (runtime: 686 ms):
import java.util.*;



public class mywork {

public static boolean isPrime(int n) {

if (n <= 1) {

return false;

}

for (int i = 2; i * i <= n; i++) {

if (n % i == 0) {

return false;

}

}

return true;

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

long T = sc.nextLong();

while (T-- > 0) {

int N = sc.nextInt();

int A[] = new int[N];

for(int i = 0;i<N;i++){

A[i] = sc.nextInt();

}

int flag = 0;

for(int i = 0;i<N-1;i++){

if(A[i+1]<A[i]){

flag=1;

break;

}

int min = Math.min(A[i+1],A[i]);

A[i+1]= A[i+1]-min;

A[i]= A[i]-min;

}

if(flag==1){

System.out.println("NO");

}else{

System.out.println("YES");

}



}

}

}
Problem: 2050E - Three Strings
Language: java

Solution 1 (runtime: 233 ms):
import java.util.Scanner;

public class Main {
    private static final int MAX_LEN = 2003; // Ensure larger array size for safety

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        scanner.nextLine(); // Consume the newline character

        while (t-- > 0) {
            String a = scanner.nextLine();
            String b = scanner.nextLine();
            String c = scanner.nextLine();

            int n = a.length();
            int m = b.length();
            int[][] dp = new int[n + 1][m + 1]; // Use n + 1 and m + 1 for proper indexing

            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= m; j++) {
                    dp[i][j] = MAX_LEN; // Initialize with a large value
                }
            }

            dp[0][0] = 0;

            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= m; j++) {
                    if (i > 0) {
                        dp[i][j] = Math.min(dp[i][j], dp[i - 1][j] + (a.charAt(i - 1) != c.charAt(i + j - 1) ? 1 : 0));
                    }
                    if (j > 0) {
                        dp[i][j] = Math.min(dp[i][j], dp[i][j - 1] + (b.charAt(j - 1) != c.charAt(i + j - 1) ? 1 : 0));
                    }
                }
            }

            System.out.println(dp[n][m]);
        }
        scanner.close(); // Close the scanner to avoid resource leaks
    }
}


Solution 2 (runtime: 327 ms):
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int tes=sc.nextInt();
        StringBuilder sb=new StringBuilder();
        label:while(tes-->0){
            String a=sc.next(),b=sc.next(),c=sc.next();
            Integer dp[][]=new Integer[a.length()+1][b.length()+1];
            System.out.println(c.length()-memo(a,b,c,0,0,dp));
        }
        System.out.println(sb);
    }
    public static int memo(String a,String b,String c,int i,int j,Integer dp[][]){
        if(i==a.length() && j==b.length()) return 0;
        int ans=0;
        if(dp[i][j]!=null) return dp[i][j];
        if(i<a.length()) ans=Math.max(ans,((a.charAt(i)==c.charAt(i+j))?1:0)+memo(a,b,c,i+1,j,dp));
        if(j<b.length()) ans=Math.max(ans,((b.charAt(j)==c.charAt(i+j))?1:0)+memo(a,b,c,i,j+1,dp));
        //System.out.println(i+" "+j+" "+ans);
        return dp[i][j]=ans;
    }
}
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 702 ms):
import java.util.*;
public class subtractminsort {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        for(int l=0;l<t;l++){
            int n=sc.nextInt();
            int arr[]=new int[n];
            for(int i=0;i<n;i++){
                arr[i]=sc.nextInt();
            }
            String res="YES";
            int a=Math.min(arr[0],arr[1]);
            arr[0]-=a;
            arr[1]-=a;
            if(arr[0]>arr[1]){
                res="NO";
            }
            if(res=="YES"){
                for(int i=1;i<n-1;i++){
                int min=Math.min(arr[i],arr[i+1]);
                arr[i]-=min;
                arr[i+1]-=min;
                if(arr[i-1]>arr[i]){
                    res="NO";
                    break;
                }
            }
            if(arr[n-2]>arr[n-1]){
                res="NO";
            }
        }
            System.out.println(res);
          
        }
        sc.close();
    }
}


Solution 2 (runtime: 468 ms):
import java.util.*;

public class Solution {

public static void main(String[] args) {

Scanner scn = new Scanner(System.in);

int cases = scn.nextInt();

while (cases > 0) {

int n = scn.nextInt();

int[] arr = new int[n];

for(int i=0;i<n;i++){

arr[i] = scn.nextInt();

}

for(int i=0;i<n-1;i++){

int cur = arr[i];

int next= arr[i+1];

arr[i]-=Math.min(cur,next);

arr[i+1]-=Math.min(cur,next);

}

boolean flag=true;

for(int i=0;i<n-1;i++){

if(arr[i]>arr[i+1]) {

flag=false;

break;

}

}

if(flag) System.out.println("YES");

else System.out.println("NO");

cases--;

}

}

}
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 484 ms):
import java.util.*;
public class Fi {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int o=0;o<t;o++){
            int n = sc.nextInt();
            int result = 1;
            int arr[] = new int[n];
            for(int i=0;i<n;i++){
                arr[i] = sc.nextInt();
                if(i>0 && arr[i-1]>arr[i]){
                    result = 0;
                }else if(i>0 && arr[i-1]<=arr[i]){
                    arr[i] -=arr[i-1];
                    arr[i-1] = 0;
                }
            }
            if(result==0){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
          
        }
    }
}
//4
//1 4 3 2

Solution 2 (runtime: 702 ms):
import java.util.*;
public class subtractminsort {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        for(int l=0;l<t;l++){
            int n=sc.nextInt();
            int arr[]=new int[n];
            for(int i=0;i<n;i++){
                arr[i]=sc.nextInt();
            }
            String res="YES";
            int a=Math.min(arr[0],arr[1]);
            arr[0]-=a;
            arr[1]-=a;
            if(arr[0]>arr[1]){
                res="NO";
            }
            if(res=="YES"){
                for(int i=1;i<n-1;i++){
                int min=Math.min(arr[i],arr[i+1]);
                arr[i]-=min;
                arr[i+1]-=min;
                if(arr[i-1]>arr[i]){
                    res="NO";
                    break;
                }
            }
            if(arr[n-2]>arr[n-1]){
                res="NO";
            }
        }
            System.out.println(res);
          
        }
        sc.close();
    }
}