ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057C - Trip to the Olympiad
Language: java

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


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

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

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

Solution 2 (runtime: 484 ms):
import java.util.*;
public class 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: 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: 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: 2050C - Uninteresting Number
Language: java

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

public class Main {
    static Scanner in;

    public static void main(String[] args) {
        int t = 1;
        in = new Scanner(System.in);
        t = in.nextInt();
        while (t-- > 0) {
            solve();
        }
        in.close();
    }

    static void solve() {
        String n = in.next(); 
        int sum = 0, two = 0, three = 0;

        for (char c : n.toCharArray()) {
            int digit = c - '0'; 
            sum += digit;
            if (digit == 2) two++;
            if (digit == 3) three++;
        }

        int remain = 9-sum % 9;
        if (remain == 9 || canReach(remain, two, three)) System.out.println("YES");
        else System.out.println("NO");
        return;
    }

    public static boolean canReach(int r, int maxTwo, int maxThree) {
        for (int x = 0; x <= maxTwo; x++) {
            for (int y = 0; y <= maxThree; y++) {
                if ((2 * x + 6 * y) % 9 == r) {
                    return true;
                }
            }
        }
        return false;
    }

    static int[] readArray(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) arr[i] = in.nextInt();
        return arr;
    }
}

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

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

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

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

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

Solution 1 (runtime: 234 ms):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;

    public static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    public static int nextLong() throws IOException {
        return Integer.parseInt(next());
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        int t = nextInt();
        while (t-- > 0) {
            run();
        }
    }

    public static void run() throws IOException {
        int n = nextInt();
        long[] arr = new long[n];
        int new_len = n;
        for(int i = 0;i<n;i++){
            arr[i] = nextLong();
        }
        long min = Long.MIN_VALUE;
        for(int i = 0;i<n;i++){
            long sum = 0;
            for(int j=0;j<new_len;j++){
                sum+=arr[j];
            }
            if(i==0){
                min = Math.max(min,sum);
            }
            else{
                min = Math.max(min,Math.max(sum,-sum));
            }
            for(int j = 0;j<n-1;j++){
                arr[j] = arr[j+1]-arr[j];
            }
            new_len--;
        }
        System.out.println(min);
    }
}


Solution 2 (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);
        }
    }
}
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: 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: 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: 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: 2050D - Digital string maximization
Language: java

Solution 1 (runtime: 312 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 s=sc.next();
            char[] res=s.toCharArray();
            for(int i=1;i<s.length();i++){
                if(res[i]>res[i-1]){
                    while(i>0 && res[i]>res[i-1] && res[i]-res[i-1]>1){
                        res[i]--;
                        char temp=res[i];
                        res[i]=res[i-1];
                        res[i-1]=temp;
                        i--;
                    }
                }
            }
            String str=new String(res);
            System.out.println(str);
        }
        sc.close();
    }
}

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

    }
}