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

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

public class number {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            String n = sc.next(); 
            int[] digits = new int[n.length()];
            int sum = 0;
            int twocount = 0;
            int threecount = 0;

            for (int i = 0; i < n.length(); i++) {
                digits[i] = n.charAt(i) - '0';
                sum += digits[i];
                if (digits[i] == 2) twocount++;
                if (digits[i] == 3) threecount++;
            }
            boolean flag=false;
            for (int i = 0; i <= Math.min(8, twocount); i++) {
                for (int j = 0; j <= Math.min(8, threecount); j++) {
                    if ((sum + i * 2 + j * 6) % 9 == 0) {
                        flag=true;
                        break;
                    }
                }
            }
            System.out.println(flag?"YES":"NO");
        }
    }
}


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

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


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

public class Main
{
    private static void solve(Scanner in)
    {
        int n = in.nextInt();

        long[] a = new long[n];

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

        long ans = 0;

        for (long el : a)
            ans += el;

        for (int it = 1; it < n; it++)
        {
            ans = Math.max(ans, Math.abs(a[n - it] - a[0]));

            for (int i = 0; i + it < n; i++)
                a[i] = a[i + 1] - a[i];
        }

        System.out.println(ans);
    }

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

        int t = in.nextInt();

        for (int test = 0; test < t; test++)
            solve(in);
        
        in.close();
    }
}
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: 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();
    }
}
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: 483 ms):
import java.util.*;

public class question {
    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();
            }

            int help = 0 ;

            for(int i = 0 ; i < n-1 ; i++){
                int a = arr[i];
                int b = arr[i+1];

                if(a > b){
                    System.out.println("NO");
                    help++;
                    break;
                }else{

                    arr[i+1] = arr[i+1] - arr[i];
                    arr[i] = 0 ;
                    //System.out.println(arr[i+1]);
                }
            }


            if(help == 0){
                System.out.println("YES");
            }

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

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

Solution 2 (runtime: 765 ms):


import java.util.Deque;

import java.util.LinkedList;

import java.util.Scanner;

import javax.print.DocPrintJob;













public class SumTo {

    private static boolean  Solution(int[]a,int n){

        Deque<Integer>dq=new LinkedList<>();

        for(int num:a){

            dq.add(num);

        }

        while(dq.size()>1){

            if(((LinkedList<Integer>) dq).get(0)>((LinkedList<Integer>) dq).get(1)){

                return false;

            }

            else if(((LinkedList<Integer>) dq).get(0)<((LinkedList<Integer>) dq).get(1)){

                int first = dq.removeFirst();

                int second = dq.removeFirst();

                dq.addFirst(second - first);



            }else{

                dq.pollFirst();

                dq.pollFirst();

            }

        }

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

            }

            System.out.println(Solution(a,n)?"Yes":"NO");

        }

    }

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

Solution 1 (runtime: 343 ms):
import java.util.*;
public class CF_1001_3 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            ArrayList<Long> list=new ArrayList<>();
            long sum=0;
            long max=Long.MIN_VALUE;
            for(int i=0;i<n;i++){
                list.add((long) sc.nextInt());
                sum+=list.get(i);
            }
            max=Math.max(max,sum);
            for(int i=0;i<n-1;i++){
                long sum1=0;
                ArrayList<Long> temp1=new ArrayList<>();
                for(int j=1;j<list.size();j++){
                    temp1.add(list.get(j)-list.get(j-1));
                    sum1+=list.get(j)-list.get(j-1);
                }
                long sum2=0;
                Collections.reverse(list);
                ArrayList<Long> temp2=new ArrayList<>();
                for(int j=1;j<list.size();j++){
                    temp2.add(list.get(j)-list.get(j-1));
                    sum2+=list.get(j)-list.get(j-1);
                }
                list.clear();
                if(sum1>sum2){
                    max=Math.max(max,sum1);
                    for(int j=0;j<temp1.size();j++){
                        list.add(temp1.get(j));
                    }
                }else{
                    max=Math.max(max,sum2);
                    for(int j=0;j<temp2.size();j++){
                        list.add(temp2.get(j));
                    }
                }
            }
            System.out.println(max);

        }
    }
}


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

public class Main
{
    private static void solve(Scanner in)
    {
        int n = in.nextInt();

        long[] a = new long[n];

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

        long ans = 0;

        for (long el : a)
            ans += el;

        for (int it = 1; it < n; it++)
        {
            ans = Math.max(ans, Math.abs(a[n - it] - a[0]));

            for (int i = 0; i + it < n; i++)
                a[i] = a[i + 1] - a[i];
        }

        System.out.println(ans);
    }

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

        int t = in.nextInt();

        for (int test = 0; test < t; test++)
            solve(in);
        
        in.close();
    }
}
Problem: 2057B - Gorilla and the Exam
Language: java

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

public class cfhello2025B 
{
    public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ret[] = new int[n];
        for(int i = 0;i<n;i++)
        {
            int size = sc.nextInt();
            int k = sc.nextInt();
            int temp[] = new int[size];
            Map<Integer,Integer> store = new HashMap<>();
            for(int j = 0;j<size;j++)
            {
                temp[j] = sc.nextInt();
                if(store.containsKey(temp[j]))
                {
                    store.put(temp[j],store.get(temp[j])+1);
                }
                else
                {
                    store.put(temp[j],1);
                }
            }
            PriorityQueue<Integer> occ = new PriorityQueue<>();
            for (Map.Entry<Integer, Integer> entry : store.entrySet()) 
            {
                occ.add(entry.getValue());
            }
            while(k!=0)
            {
                if(occ.size() == 0)
                {
                    break;
                }
                int smallest = occ.poll();
                if(k>=smallest)
                {
                    k-=smallest;
                }
                else
                {
                    occ.add(smallest);
                    break;
                }
            }
            ret[i] = occ.size();
            if(occ.size() == 0)
            {
                ret[i] = 1;
            }
        }
        for(int i = 0;i<ret.length;i++)
        {
            System.out.println(ret[i]);
        }
    }
}


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: 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: 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: 2050C - Uninteresting Number
Language: java

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


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: 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: 312 ms):
import java.util.*;
public class cirnoop2
{
   public static void main(String args[])
   {
       Scanner in = new Scanner(System.in);
       int t=in.nextInt();
       while(t!=0)
       {
           t--;
           int n=in.nextInt();
           long arr[]=new long[n];
           int i,j;
           long s=0,max=0;
           
           for(i=0;i<n;i++)
           {
               arr[i]=in.nextInt();
               s=s+arr[i];
           }
           if(n==1)
           {
               System.out.println(arr[0]);
           }          
           else
           {
           
           max=Math.max(s,-(long)Math.pow(10,18));
           while(n>=1)
           {
               
               
               --n;
               
               s=0;
               
               for(i=0;i<n;i++)
               {
                   arr[i]=arr[i+1]-arr[i];
                   s=s+arr[i];
               }
               arr[n]=0;
               
              
               s=Math.abs(s);
               max=Math.max(s,max);
           }
           System.out.println(max);
           }
           
   }
}
}
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: 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");
            }


        }
    }
}