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

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

Solution 2 (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");
        }
    }
}
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: 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: 2057C - Trip to the Olympiad
Language: java

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

    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int tsts=sc.nextInt();
        for(int t=0;t<tsts;t++){
            int l=sc.nextInt();
            int r=sc.nextInt();
            // int a=sc.nextInt();
            // int b=sc.nextInt();
            // int r2=sc.nextInt();
            // StringBuilder s=new StringBuilder(sc.next());
            // String a=sc.next();
            // String b=sc.next();
            // String c=sc.next();

            // int[] a=new int[n];
            // for(int i=0;i<n;i++){
            //     a[i]=sc.nextInt();
            // }
            // int[] b=new int[n];
            // for(int i=0;i<n;i++){
            //     b[i]=sc.nextInt();
            // }
            // long x=sc.nextLong();
            // long m=sc.nextLong();
            // long r=sc.nextInt();
            // long c=sc.nextInt();
            int n=l^r;
            int i=0;
            while(n>0){
                n=n>>1;
                i++;
            }
            i--;
            int a=l|((1<<i)-1),b=a+1,c=(a==l)?r:l;
            System.out.println(a+" "+b+" "+c);
        }    
    }
}

Solution 2 (runtime: 281 ms):
import java.util.*;
public class ProblemC {

    static long mod = (long)(1e9+7);

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0) {
            int l = sc.nextInt();
            int r = sc.nextInt();
       
            int num = 0;
            for(int i =30;i>=0;i--) {
                if(((l&(1<<i))>0 && (r&(1<<i))>0)) {
                    num|=(1<<i);
                } else if(((l&(1<<i))==0 && (r&(1<<i))==0)) {
                    continue;
                } else {
                    num|=(1<<i);
                    break;
                }
            }

            int a = num;
            int b = num-1;
            int c = (l==b) ? r : l;
            System.out.println(a+" "+b+" "+c);
        }
    }
}
Problem: 2060D - Subtract Min Sort
Language: java

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


Solution 2 (runtime: 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: 2057C - Trip to the Olympiad
Language: java

Solution 1 (runtime: 249 ms):
import java.util.*;
public class triptotheolympiad {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int testCase = 0; testCase < t; testCase++){
            long l = sc.nextLong();
            long r = sc.nextLong();

            String lBinary = Long.toBinaryString(l);
            String rBinary = Long.toBinaryString(r);

            int bit = -1;
            if(lBinary.length() < rBinary.length()){
                bit = rBinary.length() - 1;
            }else{
                //System.out.println(lBinary + " " + rBinary);
                for(int i = 0; i < rBinary.length(); i++){
                    if(lBinary.charAt(i) == rBinary.charAt(i)){
                        continue;
                    }else{
                        bit = rBinary.length() - i - 1;
                        break;
                    }
                }
            }

            long val = (long) Math.pow(2, bit);
            long firstNumber = (r / val) * val;

            long secondNumber = firstNumber - 1;
            long thirdNumber = 0;
            if(firstNumber == r){
                thirdNumber = r - 2;
            }else{
                thirdNumber = r;
            }

            System.out.println(firstNumber + " " + secondNumber + " " + thirdNumber);
        }

    }
}


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

public class C{
    public static boolean powerOf2(int n){
        if(n==1) return false;
        int a = 1;
        while(a<n) a = a*2;
        if(a==n) return true;
        return false;
    }
    public static void main(String...args){
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        while(t>0){
            t--;

            int l = sc.nextInt();
            int r = sc.nextInt();

            int mid = 0;
            boolean smallerThanr = false, greaterThanl = false;

            int start = 30;
            int i = start;
            while(i>=0){
                int lbit = (((1<<i)&l)>>i);
                int rbit = (((1<<i)&r)>>i);
                if(lbit != rbit) break;
                mid += (lbit<<i);
                i--;
            }
            // System.out.println(mid);

            start = i;
            for(i=start; i>=0; i--){
                int lbit = (((1<<i)&l)>>i);
                int rbit = (((1<<i)&r)>>i);
                int mBit = 0;

                if(lbit==1 || rbit==1) mBit=0;
                else mBit = 1;
                mid += (mBit<<i);
            }
            // System.out.println(mid);

            
            i = start;
            while(i>=0 && mid <= l){
                int mBit = (((1<<i)&mid)>>i);
                // System.out.println(i + " " + mBit + " " + mid);
                if(mBit==0 && ((mid + (1<<i)) < r)){
                    mid += (1<<i);
                }
                i--;
            }
            System.out.println(l + " " + mid + " " + r);
        }
    }
}
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: 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: 2060D - Subtract Min Sort
Language: java

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

        }

    }

}



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: 2057C - Trip to the Olympiad
Language: java

Solution 1 (runtime: 249 ms):
import java.util.*;
public class triptotheolympiad {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int testCase = 0; testCase < t; testCase++){
            long l = sc.nextLong();
            long r = sc.nextLong();

            String lBinary = Long.toBinaryString(l);
            String rBinary = Long.toBinaryString(r);

            int bit = -1;
            if(lBinary.length() < rBinary.length()){
                bit = rBinary.length() - 1;
            }else{
                //System.out.println(lBinary + " " + rBinary);
                for(int i = 0; i < rBinary.length(); i++){
                    if(lBinary.charAt(i) == rBinary.charAt(i)){
                        continue;
                    }else{
                        bit = rBinary.length() - i - 1;
                        break;
                    }
                }
            }

            long val = (long) Math.pow(2, bit);
            long firstNumber = (r / val) * val;

            long secondNumber = firstNumber - 1;
            long thirdNumber = 0;
            if(firstNumber == r){
                thirdNumber = r - 2;
            }else{
                thirdNumber = r;
            }

            System.out.println(firstNumber + " " + secondNumber + " " + thirdNumber);
        }

    }
}


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

public class DigitalStringMaximization{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] result = new String[n];
		for(int i = 0; i < n; i++){
			result[i]= maximize(sc.next());
		}
		Arrays.stream(result).forEach(System.out::println);
	}
	
	private static String maximize(String str){
		char[] chars = str.toCharArray();
		int num;
		for(int i = 1; i < chars.length; i++){
			num = chars[i] - '0';
			for(int j = num; j >= 0; j--){
				if( i - j < 0) continue;
				if(chars[ i - j ] < (char)(chars[i] - j)){
					char temp = (char)(chars[i] - j);
					for(int k = i; k > i - j; k--){
						chars[k] = chars[k - 1];
					}
					chars[i - j] = temp;
					break;
				}
			}
		} 
		return new String(chars);
	}
	
	
}

/*
i = 1 51476
i = 2 53176
i = 3 53616 55316
I = 4 55316
i = 5 55351 55431
19


*/
Problem: 2050E - Three Strings
Language: java

Solution 1 (runtime: 234 ms):
import java.util.Scanner;
public class Main{
	private static int solve(String a, String b, String c, int ai, int bi, int ci, int[][] dp) {
		if (ai==a.length()) {
			int diff = 0;
			for(int i=bi;i<b.length();i++) {
				diff += (b.charAt(i)==c.charAt(ci++)?0:1);
			}
			return diff;
		}
		if (bi==b.length()) {
			int diff = 0;
			for(int i=ai;i<a.length();i++) {
				diff += (a.charAt(i)==c.charAt(ci++)?0:1);
			}
			return diff;
		}
		if (dp[ai][bi]!=-1) {
			return dp[ai][bi];
		}
		// take from a
		int takeFromA = solve(a, b, c, ai+1, bi, ci+1,dp) + (a.charAt(ai)==c.charAt(ci)?0:1);
		int takeFromB = solve(a, b, c, ai, bi+1, ci+1,dp) + (b.charAt(bi)==c.charAt(ci)?0:1);
		return dp[ai][bi] = Math.min(takeFromA, takeFromB);
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while (t-->0) {
			String a,b,c;
			a = sc.next();
			b = sc.next();
			c = sc.next();
			int dp[][] = new int[a.length()][b.length()];
			for (int i=0;i<dp.length;i++) {
				for(int j=0;j<dp[i].length;j++) {
					dp[i][j] = -1;
				}
			}
			System.out.println(solve(a,b,c,0,0,0,dp));
		}
	}
}

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



public class Main{

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int t = scanner.nextInt();

        scanner.nextLine(); // Consume the newline



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

            String a = scanner.nextLine();

            String b = scanner.nextLine();

            String c = scanner.nextLine();



            System.out.println(minChanges(a, b, c));

        }

    }



    private static int minChanges(String a, String b, String c) {

        int lenA = a.length();

        int lenB = b.length();

        int lenC = c.length();



        int[][] dp = new int[lenA + 1][lenB + 1];

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

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

                dp[i][j] = Integer.MAX_VALUE;

            }

        }

        dp[0][0] = 0;



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

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

                if (i > 0) {

                    dp[i][j] = Math.min(dp[i][j], dp[i - 1][j] + (a.charAt(i - 1) != c.charAt(i + j - 1) ? 1 : 0));

                }

                if (j > 0) {

                    dp[i][j] = Math.min(dp[i][j], dp[i][j - 1] + (b.charAt(j - 1) != c.charAt(i + j - 1) ? 1 : 0));

                }

            }

        }



        return dp[lenA][lenB];

    }

}





// a9JHz5LCXExByemFvIG