ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: java

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

public class d {
	
	static BufferedReader br;
	static StringTokenizer st;
	static StringBuilder sb = new StringBuilder("");
	
	public static void main (String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		st = new StringTokenizer(br.readLine());
		
		int t = Integer.parseInt(st.nextToken());
		
		for (int i = 0; i < t; i++) {
			st = new StringTokenizer(br.readLine());
			solve();
		}
		
		br.close();
		System.out.print(sb.toString());
	} 
 
	
	static void solve() throws IOException {
		int n = Integer.parseInt(st.nextToken());
		int[] A = new int[n+1];
		
		st = new StringTokenizer(br.readLine());
		
		for (int i = 1; i <= n; i++) {
			A[i] = Integer.parseInt(st.nextToken());
		}
		
		for (int i = 1; i <= n-1; i++) {
			int m = Math.min(A[i], A[i+1]);
			A[i] -= m;
			A[i+1] -= m;
		}
		
		
		for (int i = 1; i <= n-1; i++) {
			if (A[i] > A[i+1]) {
				sb.append("No\n");
				return;
			}
		}
		
		sb.append("Yes\n");
		
	}
	
	
	
}

Solution 2 (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
Problem: 2060D - Subtract Min Sort
Language: java

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

public class Main {
    public static void main(String[] args) {
      Scanner s=new Scanner(System.in);
      int t=s.nextInt();
      while(t-->0){
        int n=s.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
          arr[i]=s.nextInt();
        }
        for(int i=1;i<n;i++){
          int a=Math.min(arr[i],arr[i-1]);
          arr[i-1]-=a;
          arr[i]-=a;
        }
        boolean ans=true;
        for(int i=0;i<n-1;i++){
          if(arr[i]!=0){
            ans=false;
            break;
          }
        }
        if(ans){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
      }
  }
}

Solution 2 (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);
            
        } 
    }
}
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.*;

public class Main {
    public static void main(String[] args) {
      Scanner s=new Scanner(System.in);
      int t=s.nextInt();
      while(t-->0){
        int n=s.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
          arr[i]=s.nextInt();
        }
        for(int i=1;i<n;i++){
          int a=Math.min(arr[i],arr[i-1]);
          arr[i-1]-=a;
          arr[i]-=a;
        }
        boolean ans=true;
        for(int i=0;i<n-1;i++){
          if(arr[i]!=0){
            ans=false;
            break;
          }
        }
        if(ans){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
      }
  }
}
Problem: 2057B - Gorilla and the Exam
Language: java

Solution 1 (runtime: 562 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) {
            int n=sc.nextInt();
            int k=sc.nextInt();
            int[] a=new int[n];
            HashMap<Integer,Integer> mp=new HashMap<>();
            for(int i=0;i<n;i++)
            {
                a[i]=sc.nextInt();
                if(!mp.containsKey(a[i]))
                    mp.put(a[i],1);
                else {
                    mp.put(a[i], mp.get(a[i]) + 1);
                }
            }
            ArrayList<Integer> l=new ArrayList<>();
            for(int e:mp.values())
            {
                l.add(e);
            }
            Collections.sort(l);
            int ans=l.size();
            for(int i:l)
            {
                k-=i;
                if(k<0)
                    break;
                ans--;
            }
            if(ans<1)
                System.out.println(1);
            else System.out.println(ans);

        }

    }
}


Solution 2 (runtime: 639 ms):





import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class TestFile {
	public static void main(String[]args) {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		while( t-- > 0) {
			int n = scanner.nextInt();
			int k = scanner.nextInt();
			int[] arr = new int[n];
			HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
			for(int i=0;i<n;i++) {
				arr[i] = scanner.nextInt();
				if(map.containsKey(arr[i])) {
					map.put(arr[i], map.get(arr[i]) + 1);
				} else {
					map.put(arr[i], 1);
				}
			}
			if(k == 0) {
				System.out.println(map.size());
				continue;
			}
			List<Integer> list = new ArrayList<Integer>();
			for(Map.Entry<Integer, Integer> elEntry : map.entrySet()) {
				list.add(elEntry.getValue());
			}
			list.sort(null);
			//System.out.println(list);
			int count = 1;
			for(int i=0;i<list.size();i++) {
				if(k >= list.get(i)) {
					k -= list.get(i);
					list.set(i, 0);
				} else {
					count = list.size() - i;
					break;
				}
			}
			System.out.println(count);
		}
		scanner.close();
	}
	
}
Problem: 2050C - Uninteresting Number
Language: java

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

public class TLE {
  public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
  static FastReader in = new FastReader();

  public static void main(String[] args) throws Exception {
    int testCases = in.nextInt();
    while (testCases-- > 0) {
      solve();
    }
    out.close();
  }

  private static void solve() {
    long sum = 0;
    String s = in.next();
    int two = 0, three = 0;
    for (char c : s.toCharArray()) {
      sum += c - '0';
      if (c == '2') {
        two++;
      } else if (c == '3') {
        three++;
      }
    }
    for (int t = 0; t <= two; t++) {
      for (int th = 0; th <= three; th++) {
        if ((sum + 2 * t + th * 6) % 9 == 0) {
          System.out.println("YES");
          return;
        }
      }
    }
    System.out.println("NO");

  }

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

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


Solution 2 (runtime: 249 ms):
//package com.aakash.Contest.C991;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class C {
    static BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in));

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

        StringTokenizer s1
                = new StringTokenizer(br.readLine());
        int t = Integer.parseInt(s1.nextToken());
        while (t-- > 0) {
            StringBuilder sb=new StringBuilder(br.readLine());
            int n = sb.length();
            boolean is=solve(sb,n);
            if(is) System.out.println("YES");
            else System.out.println("NO");
        }

    }

    static boolean solve(StringBuilder sb,int n) {
        int two=0,three=0;
        int sum=0;
        for(int i=0;i<n;i++) {
            int curr=sb.charAt(i)-'0';
            if(curr==2) two++;
            if(curr==3) three++;
            sum+=curr;
            sum%=9;
        }
        if((two>=5&&three>=5) ||sum==0) return true;
        sum=9-sum;
        for(int x=0;x<=two;x++) {
            for(int y=0;y<=three;y++) {
                long curr=x*2;
                curr+=y*6;
                if(curr%9==sum) return true;
            }
        }
        return false;
    }
}
Problem: 2050D - Digital string maximization
Language: java

Solution 1 (runtime: 343 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) {

char[] sb = sc.next().toCharArray(); // Using char array for efficiency

int n = sb.length;



int index = 1;

while (index < n) {

if (sb[index] != '0') {

int toPlace = index - 1;

int subtract = 1;



while (toPlace >= 0 && (sb[index] - '0') - subtract > (sb[toPlace] - '0')) {

if (toPlace == 0) break;

toPlace--;

subtract++;

}



if ((sb[index] - '0') - subtract <= (sb[toPlace] - '0')) {

toPlace++;

subtract--;

}



if (toPlace != index) {

char res = (char) ((sb[index] - '0' - subtract) + '0');



// Shift elements manually instead of using `add()` and `remove()`

for (int j = index; j > toPlace; j--) {

sb[j] = sb[j - 1];

}

sb[toPlace] = res;

}

}

index++;

}



System.out.println(new String(sb)); // Fast output

}

}

}



Solution 2 (runtime: 609 ms):
import java.math.*;

import java.util.*;



public class Main {

static int N = (int)2e5 + 5;

static int[] a = new int[N];

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int T = sc.nextInt();

while(T-- > 0){

String s = sc.next();

int len = s.length();

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

a[i] = (int)s.charAt(i - 1) - (int)'0';

}

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

int x = a[i], idx = i;

int mx = x, id = -1;

for(int j = i + 1;j <= len && j <= i + 8;j++){

if(a[j] - (j - i) > mx){

mx = a[j] - (j - i);

idx = j;

}

}

for(int j = idx - 1;j >= i;j--){

int t = a[j];

a[j] = a[j + 1] - 1;

a[j + 1] = t;

}

}

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

System.out.print(a[i]);

}

System.out.println();

}

sc.close();

}

}
Problem: 2057C - Trip to the Olympiad
Language: java

Solution 1 (runtime: 374 ms):
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int tt = sc.nextInt();
        while(tt-->0){
            int l = sc.nextInt(); int r = sc.nextInt();
            int a = pick(l,r);
            System.out.println(a);
            int b = a-1; System.out.println(b);
            int c = l; while (c==a || c==b) c++;
            System.out.println(c); 
        }
        sc.close();
    }

    public static int pick(int l, int r){
        int a = 1;
        while (a<<1 <= r) a=a<<1;

        if ((a&r) == (a&l)) return a+pick(l-a, r-a);
        return a;
    }
} 

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int l = in.nextInt(), r = in.nextInt();

            int a = r;
            int b = 0;

            int x = 0b01111111111111111111111111111111;
            for (int j = 30; j >= 1; j--) {
                x &= ~(1 << j);
                if (inRange(a ^ x, l, r)) {
                    b = a ^ x;
                    break;
                }
            }

            int c = l;
            while (c < r && (c == a || c == b)) c ++;
            System.out.println(a + " " + b + " " + c);
        }
    }

    private static boolean inRange(int num, int l, int r) {
        return num >= l && num <= r;
    }
}
Problem: 2060D - Subtract Min Sort
Language: java

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

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

        outer :
        while(t>0){
            int n = sc.nextInt();

            int[] nums = new int[n];

            for(int i=0;i<n;i++){
                nums[i] = sc.nextInt();
            }

            for(int i = 1 ; i < n ; i++){
                int min = Math.min(nums[i],nums[i-1]);
                nums[i] = nums[i] - min;
                nums[i-1] = nums[i-1] - min;

                if(nums[i-1] > nums[i] ) {
                    System.out.println("NO");
                    t--;
                    continue outer;
                }
            }
            System.out.println("YES");
            t--;
        }
    }
}

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

public class div2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int i = 0 ; i<t ; i++){
            int n = sc.nextInt();

            int[] arr = new int[n];
            for(int j = 0 ; j < n ; j++){
                arr[j] = sc.nextInt();
            }

            int ind = 0;
            boolean flag = true;
            while(ind < n-1){
                if(arr[ind] <= arr[ind+1]){
                    arr[ind+1] -= arr[ind];
                    arr[ind] = 0;
                    ind++;
                }
                else {
                    flag = false;
                    break;
                }
            }
            if(!flag) System.out.println("NO");
            else System.out.println("YES");
        }
    }
}
Problem: 2050C - Uninteresting Number
Language: java

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


}

Solution 2 (runtime: 327 ms):
import java.util.*;
public class temp{
    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[] c=s.toCharArray();
            int[] fre=new int[10];
            int sum=0;
            for(int i=0;i<c.length;i++){
                int cr=c[i]-'0';
                fre[cr]++;
                sum+=cr;
                if(sum>9)sum=sum%10+sum/10;
            }
            int f=-1;
            if(sum==0 || sum==9)f=1;
            else{
                int[][] dp=new int[Math.min(10,fre[2]+1)][Math.min(10,fre[3]+1)];
                for(int i=0;i<dp.length;i++)
                    Arrays.fill(dp[i],-1);
                int ans=solve(sum,dp,1,1);
                if(ans==0)f=1;
            }
            if(f==1)System.out.println("YES");
            else System.out.println("NO");
        }
    }
    public static int solve(int sum,int[][] dp,int i,int j){
        if(sum==0){return 0;}
        if(i==dp.length && j==dp[0].length)return 1;
        if(i<dp.length && j<dp[0].length && dp[i][j]!=-1)return dp[i][j];
        if((i<dp.length && solve((sum+2)%9,dp,i+1,j)==0) || (j<dp[0].length && solve((sum+6)%9,dp,i,j+1)==0)){
            if(i<dp.length && j<dp[0].length)dp[i][j]=0;
            return 0;}
        if(i<dp.length && j<dp[0].length)dp[i][j]=1;
        return 1;
    }
}
Problem: 2060D - Subtract Min Sort
Language: java

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



public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt(); // Number of test cases

        

        while (t-- > 0) {

            int n = sc.nextInt(); // Length of sequence

            int[] a = new int[n];

            

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

                a[i] = sc.nextInt();

            }



            // Simulating the operation

            boolean possible = true;

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

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

                a[i] -= minValue;

                a[i + 1] -= minValue;

            }



            // Check if the array is now non-decreasing

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

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

                    possible = false;

                    break;

                }

            }



            System.out.println(possible ? "YES" : "NO");

        }



        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: 687 ms):
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    static long mod = 1000000007;
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
        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();
            }
            boolean ans = true;     
            for(int i=0;i<n-1;i++){
                int x = Math.min(arr[i],arr[i+1]);
                arr[i]-=x;
                arr[i+1]-=x;
                if(arr[i]>arr[i+1]){
                    ans = false;
                    break;
                }
            }
            
            if(ans){
                System.out.println("YES");
            }
            else{
                System.out.println("NO");
            }
        }
	}
}

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

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

        outer :
        while(t>0){
            int n = sc.nextInt();

            int[] nums = new int[n];

            for(int i=0;i<n;i++){
                nums[i] = sc.nextInt();
            }

            for(int i = 1 ; i < n ; i++){
                int min = Math.min(nums[i],nums[i-1]);
                nums[i] = nums[i] - min;
                nums[i-1] = nums[i-1] - min;

                if(nums[i-1] > nums[i] ) {
                    System.out.println("NO");
                    t--;
                    continue outer;
                }
            }
            System.out.println("YES");
            t--;
        }
    }
}