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

Solution 1 (runtime: 328 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 n=sc.next();
	        int s=0;
	        HashMap<Integer,Integer>hm=new HashMap();
	        for(int i=0;i<n.length();i++){
	            s+=n.charAt(i)-'0';
	            if((n.charAt(i)-'0')==3)
	            hm.put(6,hm.getOrDefault(6,0)+1);
	            else if((n.charAt(i)-'0')==2)
	            hm.put(2,hm.getOrDefault(2,0)+1);

	            
	        }

            int f=0;
	        if(s%9==0)
	        		System.out.println("YES");
	        		else{
	        		    for(int i=0;i<=hm.getOrDefault(2,0);i++){
	        		        if(f==1)
	        		        break;
	        		        
	        		        for(int j=0;j<=hm.getOrDefault(6,0);j++){
	        		            if((s+i*2+j*6)%9==0)
	        		            {
	        		                f=1;
	        		                break;
	        		            }
	        		        }
	        		    }
	        		    System.out.println((f==1)?"YES":"NO");
	                    }



	        
	    }
	}
}


Solution 2 (runtime: 312 ms):
import java.util.*;
public class practice {
    public static boolean unintrestingNumber(String n){
        int count = 0;
        int count2 = 0;
        int count3 = 0;
        for(int i = 0; i<n.length();i++){
            String Snum = String.valueOf(n.charAt(i));
            int num = Integer.parseInt(Snum);
            count+=num;
            if (num == 2){
                count2++;
            }
            if (num == 3){
                count3++;
            }
        }
        int newSum = count;
        for (int i = 0; i <= Math.min(9, count2); i++) {
            for (int j = 0; j <= Math.min(9, count3); j++) {
                if ((newSum + i * 2 + j * 6) % 9 == 0) {
                    return true; 
                }
            }
        }
        return false;
    }
    
    public static void main(String[] args){
        Scanner myScan = new Scanner(System.in);
        int testcases = myScan.nextInt();
        for (int i = 0; i<=testcases; i++){
            String test = myScan.nextLine();
            if (!"".equals(test)){
                if(unintrestingNumber(test)){
                    System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }
        }
    }
}
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: 484 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 ar[]=new int[n];
            for(int i=0;i<n;i++)
            {
                ar[i]=sc.nextInt();
            }
            boolean flag=false;
            for(int i=0;i+1<n;i++)
            {
                if(ar[i]<=ar[i+1])
                {
                    ar[i+1]=ar[i+1]-ar[i];
                    ar[i]-=ar[i];
                }
                else
                {
                    flag=true;
                    break;
                }
            }
            if(flag)
            {
                System.out.println("NO");
            }
            else
            {
                System.out.println("YES");
            }
        }
    }
}
Problem: 2063B - Subsequence Update
Language: java

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

public final class F1{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-- != 0){
			int n = sc.nextInt();
			int l = sc.nextInt();
			int r = sc.nextInt();
			int[] arr = new int[n];
			int[] left = new int[r];
			int[] right = new int[n-l+1];
			for(int i = 0; i < arr.length; i++){
				arr[i] = sc.nextInt();
			}
			for(int i = 0; i < left.length; i++){
				left[i] = arr[i];
			}
			for(int i = 0; i < right.length; i++){
				right[i] = arr[l-1+i];
			}
			Arrays.sort(left);
			Arrays.sort(right);
			long sum1 = 0;
			long sum2 = 0; 
			for(int i = 0 ; i <= r - l; i++){
				sum1 += (long)left[i];
				sum2 += (long)right[i];
			}
			System.out.println(Math.min(sum1, sum2));
		}
	}		
}

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



public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        

        int t = sc.nextInt();



        while(t-- > 0) {

            solve();

        }

    }



    static void solve() {

        int n = sc.nextInt();

        int l = sc.nextInt() - 1;

        int r = sc.nextInt() - 1;



        int[] a = new int[n];



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



        Queue<Integer> before = new PriorityQueue<>();

        Queue<Integer> after = new PriorityQueue<>();

        Queue<Integer> res1 = new PriorityQueue<>(Collections.reverseOrder());

        Queue<Integer> res2 = new PriorityQueue<>(Collections.reverseOrder());



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

            if (i < l) before.add(a[i]);

            else if (i > r) after.add(a[i]);

            else {

                res1.add(a[i]);

                res2.add(a[i]);

            }

        }



        while(!before.isEmpty() && before.peek() < res1.peek()) {

            res1.add(before.poll());

            res1.poll();

        }



        long  sum = 0;

        while(!res1.isEmpty()) sum += res1.poll();



        while(!after.isEmpty() && after.peek() < res2.peek()) {

            res2.add(after.poll());

            res2.poll();

        }

        long sum2 = 0;

        while(!res2.isEmpty()) sum2 += res2.poll();



        System.out.println(Math.min(sum, sum2));

    }

}
Problem: 2062C - Cirno and Operations
Language: java

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

public class Main {


    public static void main(String[] args) {
        int t=1;
        Scanner sc = new Scanner(System.in);
        t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            long[] arr=new long[n];
            long ans=0;
            for(int i=0;i<n;i++){
                arr[i]=sc.nextInt();
                ans+=arr[i];
            }

            while(n>1){
                ans=Math.max(ans,Math.abs(arr[n-1]-arr[0]));
                for (int i = 0; i < n-1; i++) {
                    arr[i]=arr[i+1]-arr[i];
                }
                n--;
            }
            System.out.println(ans);
        }
    }
}


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

    }

}
Problem: 2050B - Transfusion
Language: java

Solution 1 (runtime: 639 ms):
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;

public class Main
{
	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
		int o=sc.nextInt();
		sc.nextLine();
// HashMap<Integer,Integer> map=new HashMap<>();

// int[] arr1=new int[o];
		for(int pp=0;pp<o;pp++){
		  int a =sc.nextInt();
		  //int b=sc.nextInt();
		  ////int c=sc.nextInt();
		  ////int d=sc.nextInt();
		  ////int e=sc.nextInt();
		  sc.nextLine();
		  int[] arr=new int[a];
		  long sum=0;
		  long sum1=0;
		  long sum2=0;
		  int odd=(a+1)/2;
		  int even=a/2;
		  for(int i=0;i<a;i++){
		      
		      int xx=sc.nextInt();
		      arr[i]=xx;
		      sum=sum+xx;
		      if(i%2==0){
		      sum1=sum1+xx;}
		      else{
		          sum2=sum2+xx;
		      }
		  }
		  long mod=sum/a;
		  if(sum%a!=0){
		      System.out.println("NO");
		      continue;
		  }
		  if(a==2){
		      if((arr[0]!=arr[1])){
		      System.out.println("NO");
		      continue;
		         }
		      else{
		      System.out.println("YES");
		      continue;
		       }
		  }
		
		  if(a==3){
		      if(arr[1]!=mod){
		      System.out.println("NO");
		      continue;
		      }
		  else{
		      System.out.println("YES");
		      continue;
		       }}
		  if(a>3){
		      if(sum1==(odd*mod)&&(sum2==(even*mod))){
		          System.out.println("YES");
		      continue;
		        }
		      else{
		          System.out.println("NO");
		          continue;
		  
		      }
		  }
		  
		}
		
		
		
}}


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



public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        int ai = sc.nextInt();

        while(ai-- > 0) xiao();

    }

    static int n;

    public static void xiao() {

        n = sc.nextInt();

        long sum1 = 0,sum2 = 0;

        long cnt1 = 0,cnt2 = 0;

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

            if(i % 2 == 1){

                cnt1++;

                sum1 += sc.nextLong();

            }

             else {

                sum2 += sc.nextLong();

                cnt2++;

            } 

        }

        if(sum1 % cnt1 == 0 && sum2 % cnt2 == 0 && sum1 / cnt1 == sum2 / cnt2)

            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: 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: 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: 687 ms):


import java.util.*;



public class AS {



    public static void main(String[] args) {



        Scanner s = new Scanner(System.in);



        int t = s.nextInt();

        s.nextLine();



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



            int c = s.nextInt();

            s.nextLine();



            int[] arr = new int[c];



            for (int j = 0; j < c; j++) {



                arr[j] = s.nextInt();

            }

            s.nextLine();



            boolean flag = true;

            for (int j = 0; j < c - 1; j++) {



                int temp = Math.min(arr[j], arr[j + 1]);

                arr[j] -= temp;

                arr[j + 1] -= temp;



                if (arr[j] > 0) {

                    flag = false;

                    break;

                }

            }



            if (flag)

                System.out.println("yes");

            else

                System.out.println("no");



        }



        s.close();

    }

}
Problem: 2062C - Cirno and Operations
Language: java

Solution 1 (runtime: 187 ms):
// "static void main" must be defined in a public class.
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner Sc = new Scanner(System.in);
        int t = Sc.nextInt();
        Sc.nextLine();
        for(int i=0; i<t; i++) {
            int n = Sc.nextInt();
            long[] arr = new long[n];
            for(int j=0; j<n; j++) {
                arr[j] = Sc.nextInt();
            }
            Solution s1 = new Solution();
            System.out.println(s1.maxSum(arr));
        }
    }
}

class Solution {
    public long maxSum(long[] arr) {
        if(arr.length == 1)
            return arr[0];
        int n = arr.length;
        long sum = 0;
        for(int i=0; i<n; i++) {
            sum += arr[i];
        }
        while(n > 1) {
            long temp = 0;
            for(int i=0; i<n-1; i++) {
                arr[i] = arr[i] - arr[i+1];
                temp = temp + arr[i];
            }
            sum = Math.max(sum, Math.abs(temp));
            n--;
        }
        return Math.max(sum, Math.abs(arr[0]));
    }
}


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

public class Main {


    public static void main(String[] args) {
        int t=1;
        Scanner sc = new Scanner(System.in);
        t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            long[] arr=new long[n];
            long ans=0;
            for(int i=0;i<n;i++){
                arr[i]=sc.nextInt();
                ans+=arr[i];
            }

            while(n>1){
                ans=Math.max(ans,Math.abs(arr[n-1]-arr[0]));
                for (int i = 0; i < n-1; i++) {
                    arr[i]=arr[i+1]-arr[i];
                }
                n--;
            }
            System.out.println(ans);
        }
    }
}
Problem: 2050D - Digital string maximization
Language: java

Solution 1 (runtime: 186 ms):
import java.util.*;
public class practt {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String r = sc.nextLine();
        String[] arr = new String[n];
        for(int ifg = 0; ifg < n; ifg++){
            String temp = sc.next();
            int[] tt = new int[temp.length()];
            for(int i = 0; i < temp.length(); i++){
                tt[i] = (int)temp.charAt(i)-'0';
            }
            int fault =  1;
            while(fault!=0){
                int cnt = 0;
                //System.out.println("hi");
                for(int i = 1;i < tt.length;i++){
                    //System.out.println("hii");
                    if(tt[i-1]<(tt[i]-1)){
                        int s = tt[i-1];
                        tt[i-1]=tt[i]-1;
                        tt[i]=s;
                        cnt++;
                    }
                }
                fault=cnt;
            }
            StringBuilder ans = new StringBuilder();
            for(int i=0;i<tt.length;i++){
                ans.append((char)(tt[i]+'0'));
            }
            arr[ifg] = ans.toString();
        }
        for(String a:arr){
            System.out.println(a);
        }

    }
}


Solution 2 (runtime: 327 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 str = sc.next();

            int n = str.length();

            int arr[] = new int[n];



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

                arr[i] = str.charAt(i) - '0';

            }

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

                int idx = i;

                while (idx >= 1 && arr[idx] > 0 && arr[idx] > arr[idx - 1] + 1) {

                    int temp = arr[idx];

                    arr[idx] = arr[idx - 1];

                    arr[idx - 1] = temp - 1;

                    idx--; 

                }

            }

            StringBuilder sb = new StringBuilder(n);

            for (int a : arr) {

                sb.append(a);

            }

            System.out.println(sb);

        }

    }

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

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

public class Main{

public static void main(String args[]){

Scanner scanner = new Scanner(System.in);

int tests = scanner.nextInt();

while(tests-- > 0){

int n = scanner.nextInt();

int A[] = new int[n];

boolean flag = false;

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

A[i] = scanner.nextInt();

}

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

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

flag = true;

break;

}else{

int temp = A[i];

A[i] -= temp;

A[i + 1] -= temp;

}

}

if(!flag){

System.out.println("YES");

}else{

System.out.println("NO");

}

}

scanner.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--;

}

}

}