ShaysXIA/CodeInsightBench huggingface dataset:
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: 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: 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: 312 ms):
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
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 n=sc.next();
            long sum=0;
            long cnt1=0;
            long cnt2=0;
            for(long i=0; i<n.length(); i++){
                char ch=n.charAt((int)i);
                if(ch=='2'){
                    cnt1++;
                }
                else if(ch=='3'){
                    cnt2++;
                }
                sum+=(ch-'0');
                sum=sum%9;
            }
                boolean check=false;
                for(int i=0; i<=cnt1; i++){
                    for(int j=0; j<=cnt2; j++){
                        long temp1=sum;
                        temp1=temp1+(i*2)+(j*6);
                        if(temp1%9==0){
                            check=true;
                            break;
                        }
                    }
                    if(check==true){
                        break;
                    }
                }
                if(check==true){
                    System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            t--;
        }
    }
}
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 656 ms):
import java.util.*;
public class subtractMinSort {
    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();
            }

            boolean flag = true;
            for(int i=0;i<n-1;i++){
                int min = Math.min(arr[i],arr[i+1]);
                arr[i] = arr[i]-min;
                arr[i+1] = arr[i+1]-min;
            }

            for(int i=0;i<n-1;i++){
                if(arr[i]>arr[i+1]){
                    System.out.println("NO");
                    flag = false;
                    break;
                }
            }
            if(flag){
                System.out.println("YES");
            }


        }
    }
}

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

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

        }

    }

}

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

Solution 1 (runtime: 702 ms):
import java.util.*;
         
public class CompCode {
    static Scanner sc = new Scanner(System.in);
 
    static int MOD = 998244353; 
 
    public static void main(String... args) {
        int tc = sc.nextInt();
        while(tc-- > 0) {
            int n = sc.nextInt();
            int[] a = new int[n];
            int i;
            for(i=0; i<n; i++) {
                a[i] = sc.nextInt();
            }

            if(n==2) {
                if(a[1]>=a[0]) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
                continue;
            }

            for(i=1; i<n-1; i++) {
                if(a[i]<a[i-1]) {
                    break;
                }
                if(a[i]-a[i-1] > a[i+1]) {
                    break;
                }
                a[i] = a[i]-a[i-1];
                // System.out.print(a[i]+ " ");
            }
            if(i==n-1) {
                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: 2062C - Cirno and Operations
Language: java

Solution 1 (runtime: 280 ms):
import java.util.*;
public class Solution{
    static int max=0;
    public static long sumCalc(ArrayList<Long> list){
        long sum=0;
        int i=1;
                
         while(i<list.size()){
            long v=list.get(i)-list.get(i-1);
            list.set(i-1,v);
            sum+=v;
            i++;
        }
        
        list.remove(list.size()-1);
        
        return sum;
    }
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        
        int t=sc.nextInt();
        
        for(int test=0;test<t;test++){
            int n=sc.nextInt();
            ArrayList<Long> list=new ArrayList<>();
           
            long sum=0;
            for(int i=0;i<n;i++){
                long val=sc.nextLong();
                list.add(val);
                sum+=val;
            }
            
            long max=sum;
            while(list.size()>1){
                long ans=sumCalc(list);
                max=Math.max(ans,max);
                sum=0;
                for(int i=0;i<list.size();i++){
                    sum+=(-1)*list.get(i);
                }
                
                max=Math.max(sum,max);
            }
            
            System.out.println(max);
        }
    }
}

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: 2062C - Cirno and Operations
Language: java

Solution 1 (runtime: 311 ms):

import java.util.Scanner;

public class Sol {
    static Scanner rd = new Scanner(System.in);
    public static void main(String[] args) {
        int tt = rd.nextInt();
        while (tt-- > 0) {
            new Solution().solve();
        }
    }

    static class Solution {
        void solve() {
            int n = rd.nextInt();
            long[] a = new long[n];

            for (int i = 0; i < n; i++) {
                a[i] = rd.nextInt();
            }
            int len = n;
            if (len == 1) {
                System.out.println(a[0]);
                return;
            }
            long max = getSum(a, n, false);
            while (len > 1) {
                for (int i = 0; i < len - 1; i++) {
                    a[i] = a[i + 1] - a[i];
                }
                len--;
                max = Math.max(Math.max(getSum(a, len, true), getSum(a, len, false)), max);
            }
            System.out.println(max);
        }

        long getSum(long[] a, int len, boolean neg) {
            long sum = 0;
            for (int i = 0; i < len; i++) {
                if (neg) {
                    sum += (-1) * a[i];
                } else {
                    sum += a[i];
                }
            }
            return sum;
        }
    }
}


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

public class C_Cirno_and_Operations {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-->0) {
            int n = sc.nextInt();
            long[] arr = new long[n+1];
            for (int i=1; i<=n; i++) {
                arr[i] = sc.nextLong();
            }
            int curr = n;
            long ans = Long.MIN_VALUE;
            for (int i=1; i<=n; i++) {
                long sum = 0;
                for (int j=1; j<=curr; j++) {
                    sum += arr[j];
                }
                if (i==1) {
                    ans = Math.max(ans, sum);
                }
                else ans = Math.max(ans, Math.max(sum,-sum));
                for (int j=1; j<curr; j++) {
                    arr[j] = arr[j+1]-arr[j];
                }
                curr--;
            }
            System.out.println(ans);
        }
        sc.close();
    }
}
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 484 ms):
// Problem Page: https://codeforces.com/contest/2060/problem/D

import java.util.*;

public class SubtractMinSort {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            solve(sc);
        }
    }

    static void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }

        if (n == 2) {
            if (a[1] <= a[2]) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
            return;
        }

        String ans = "YES";
        int diff = a[2] - a[1];
        for (int i = 3; i <= n; i++) {
            if ((diff >= 0) && (a[i] >= diff)) {
                diff = a[i] - diff;
            } else {
                ans = "NO";
                break;
            }
        }
        System.out.println(ans);
    }
}


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

import java.math.*;

import java.util.*;



public class Main {

static class IoScanner {

BufferedReader bf;

StringTokenizer st;

BufferedWriter bw;



public IoScanner() {

bf = new BufferedReader(new InputStreamReader(System.in));

st = new StringTokenizer("");

bw = new BufferedWriter(new OutputStreamWriter(System.out));

}



public String nextLine() throws IOException {

return bf.readLine();

}



public String next() throws IOException {

while (!st.hasMoreTokens()) {

st = new StringTokenizer(bf.readLine());

}

return st.nextToken();

}



public char nextChar() throws IOException {

return next().charAt(0);

}



public int nextInt() throws IOException {

return Integer.parseInt(next());

}



public long nextLong() throws IOException {

return Long.parseLong(next());

}



public double nextDouble() throws IOException {

return Double.parseDouble(next());

}



public float nextFloat() throws IOException {

return Float.parseFloat(next());

}



public BigInteger nextBigInteger() throws IOException {

return new BigInteger(next());

}



public BigDecimal nextDecimal() throws IOException {

return new BigDecimal(next());

}

}

static IoScanner sc = new IoScanner();

static PrintWriter out = new PrintWriter(System.out);

static final int mod=(int) (1e9+7);

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

int T = 1;

T = sc.nextInt();

while (T-- > 0) {

solve();

}

out.flush();

}

static void solve() throws IOException {

int n=sc.nextInt();

int[] arr = new int[n];

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

arr[i]=sc.nextInt();

}

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

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

out.println("NO");

return;

}else {

arr[i] -= arr[i - 1];

arr[i-1]=0;

}

}

out.println("YES");

}

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

Solution 1 (runtime: 656 ms):
import java.util.*;
public class subtractMinSort {
    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();
            }

            boolean flag = true;
            for(int i=0;i<n-1;i++){
                int min = Math.min(arr[i],arr[i+1]);
                arr[i] = arr[i]-min;
                arr[i+1] = arr[i+1]-min;
            }

            for(int i=0;i<n-1;i++){
                if(arr[i]>arr[i+1]){
                    System.out.println("NO");
                    flag = false;
                    break;
                }
            }
            if(flag){
                System.out.println("YES");
            }


        }
    }
}

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

import java.math.*;

import java.util.*;



public class Main {

static class IoScanner {

BufferedReader bf;

StringTokenizer st;

BufferedWriter bw;



public IoScanner() {

bf = new BufferedReader(new InputStreamReader(System.in));

st = new StringTokenizer("");

bw = new BufferedWriter(new OutputStreamWriter(System.out));

}



public String nextLine() throws IOException {

return bf.readLine();

}



public String next() throws IOException {

while (!st.hasMoreTokens()) {

st = new StringTokenizer(bf.readLine());

}

return st.nextToken();

}



public char nextChar() throws IOException {

return next().charAt(0);

}



public int nextInt() throws IOException {

return Integer.parseInt(next());

}



public long nextLong() throws IOException {

return Long.parseLong(next());

}



public double nextDouble() throws IOException {

return Double.parseDouble(next());

}



public float nextFloat() throws IOException {

return Float.parseFloat(next());

}



public BigInteger nextBigInteger() throws IOException {

return new BigInteger(next());

}



public BigDecimal nextDecimal() throws IOException {

return new BigDecimal(next());

}

}

static IoScanner sc = new IoScanner();

static PrintWriter out = new PrintWriter(System.out);

static final int mod=(int) (1e9+7);

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

int T = 1;

T = sc.nextInt();

while (T-- > 0) {

solve();

}

out.flush();

}

static void solve() throws IOException {

int n=sc.nextInt();

int[] arr = new int[n];

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

arr[i]=sc.nextInt();

}

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

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

out.println("NO");

return;

}else {

arr[i] -= arr[i - 1];

arr[i-1]=0;

}

}

out.println("YES");

}

}