ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: java

Solution 1 (runtime: 171 ms):
import java.math.BigInteger;
import java.util.*;

public class Cirno {
    static Scanner sc = new Scanner(System.in);

    static BigInteger bsum = BigInteger.valueOf(Integer.MIN_VALUE);
    static boolean c = true;

    static void diffFinder(BigInteger arr[]) {
        BigInteger sum = BigInteger.ZERO;

        for (int i = 0; i < arr.length; i++) {
            sum = sum.add(arr[i]);
        }
        if (c)
            c = false;
        else
            sum = sum.abs();
        if (sum.compareTo(bsum) > 0) {
            bsum = sum;
        }

        if (arr.length <= 1)
            return;
        else {
            BigInteger sys[] = new BigInteger[arr.length - 1];

            for (int i = 0; i < arr.length - 1; i++) {
                sys[i] = arr[i + 1].subtract(arr[i]);
            }

            diffFinder(sys);
        }
    }

    public static void main(String[] args) {
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            BigInteger arr[] = new BigInteger[n];
            for (int i = 0; i < n; i++) {
                arr[i] = BigInteger.valueOf(sc.nextInt());
            }
            if (n == 1) {
                System.out.println(arr[0]);
            } else {
                diffFinder(arr);
                System.out.println(bsum);
                c = true;
                bsum = BigInteger.valueOf(Integer.MIN_VALUE);
            }
        }
    }
}


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

        }
    }
}
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: 234 ms):
import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.StringTokenizer;



public class round991 {

static class Pair implements Comparable<Pair>{

int a;

long b;

String str;



Pair(int a,long b,String str){

this.a=a;

this.b=b;

this.str=str;

}



public int compareTo(Pair o) {

return Integer.compare(this.a, o.a); // Ascending order by a

}

//

//            public int compareTo(Pair o){

//                return Long.compare(this.b,o.b);

//            }

//

//            public int compareTo(Pair other) {

//                return this.str.compareTo(other.str); // Ascending order by str

//            }

//

}

static class FastReader {

BufferedReader br;

StringTokenizer st;



public FastReader() {

br = new BufferedReader(

new InputStreamReader(System.in));

}



String next() {

while (st == null || !st.hasMoreElements()) {

try {

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

} catch (IOException e) {

e.printStackTrace();

}

}

return st.nextToken();

}



int nextInt() {

return Integer.parseInt(next());

}



long nextLong() {

return Long.parseLong(next());

}



double nextDouble() {

return Double.parseDouble(next());

}



String nextLine() {

String str = "";

try {

if (st.hasMoreTokens()) {

str = st.nextToken("\n");

} else {

str = br.readLine();

}

} catch (IOException e) {

e.printStackTrace();

}

return str;

}

}

static ArrayList<Integer>[] gr;

public static void main(String[] args) {

FastReader sc = new FastReader();

PrintWriter out=new PrintWriter(System.out);

int t = sc.nextInt();

while (t != 0) {

t--;

String str=sc.next();

int[] arr=new int[str.length()];

for (int i = 0; i < arr.length; i++) {

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

}

StringBuilder ans=new StringBuilder("");

for (int i = 0; i < arr.length; i++) {

int dig=arr[i];

int j=i-1;

while (j>=0 && arr[j]<dig-1){

arr[j+1]=arr[j];

--dig;

arr[j]=dig;

--j;

}

//                out.println(st);

}

//            out.println(Arrays.toString(arr));

for (int num:arr) {

ans.append(""+num);

}

out.println(ans);

}

out.flush();

}

}
Problem: 2057C - Trip to the Olympiad
Language: java

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

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt(); // number of test cases
        // int t = 1;
        while (t-- > 0) {
            long l = sc.nextLong();
            long r = sc.nextLong();

            long ans = 0;
            long a = 0;
            long b = 0;
            // long c = 0;
            for(int i = 30;i>=0;i--) {
                long and1 = r & (1 << i);
                long and2 = l & (1 << i);

                if(and1 == and2) {
                    if(and1 >= 1) ans = ans + (1 << i);
                } else {
                    a = ans + (1 << i);
                    b = a - 1;
                    break;
                }
            }
            long c = r;
            if(a == r) {
                c = l;
            }
            System.out.println(a + " " + b + " " + c);
        }
        
    }
}



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

Solution 1 (runtime: 171 ms):
import java.math.BigInteger;
import java.util.*;

public class Cirno {
    static Scanner sc = new Scanner(System.in);

    static BigInteger bsum = BigInteger.valueOf(Integer.MIN_VALUE);
    static boolean c = true;

    static void diffFinder(BigInteger arr[]) {
        BigInteger sum = BigInteger.ZERO;

        for (int i = 0; i < arr.length; i++) {
            sum = sum.add(arr[i]);
        }
        if (c)
            c = false;
        else
            sum = sum.abs();
        if (sum.compareTo(bsum) > 0) {
            bsum = sum;
        }

        if (arr.length <= 1)
            return;
        else {
            BigInteger sys[] = new BigInteger[arr.length - 1];

            for (int i = 0; i < arr.length - 1; i++) {
                sys[i] = arr[i + 1].subtract(arr[i]);
            }

            diffFinder(sys);
        }
    }

    public static void main(String[] args) {
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            BigInteger arr[] = new BigInteger[n];
            for (int i = 0; i < n; i++) {
                arr[i] = BigInteger.valueOf(sc.nextInt());
            }
            if (n == 1) {
                System.out.println(arr[0]);
            } else {
                diffFinder(arr);
                System.out.println(bsum);
                c = true;
                bsum = BigInteger.valueOf(Integer.MIN_VALUE);
            }
        }
    }
}


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

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

public class Main {
	static InputStream inputStream;
	static OutputStream outputStream;
	static InputReader in;
	static PrintWriter out;
	static int MULTIPLE_TESTACES = 1;
  
	///////////////////////////////////////
	// solution
	///////////////////////////////////////
	static class Solution {
    
    private boolean pos(ArrayList<Long> o){
			int n = o.size();
			ArrayList<Long> a = new ArrayList<Long>();
			for(Long x: o){
				a.add(x);
			}
			for(int i=0; i<n-1;++i){
				long x = a.get(i);
				long y = a.get(i+1);
				long m = Math.min(x, y);
				a.set(i, x-m);
				a.set(i+1, y-m);
			}
			for(int i=0; i<n-1;++i){
				long x = a.get(i);
				long y = a.get(i+1);
				if(x > y)return false;
			}
			return true;
		}
		
		public void solve(int tc) throws IOException{
			int n = in.nextInt();
			ArrayList<Long> a = new ArrayList<Long>();
			for(int i=0; i<n;++i){
				a.add(in.nextLong());
			}
			boolean ans = false;
			ans |= pos(a);
			out.println(ans ? "YES":"NO");
		}	
	}
	
	
	
	
	
	///////////////////////////////////////
	// template
	///////////////////////////////////////
	public static void main(String[] args) throws IOException{
			inputStream = System.in;
			outputStream = System.out;
			in = new InputReader(inputStream);
			out = new PrintWriter(outputStream);
			int tc = 1;
			if(MULTIPLE_TESTACES>0)tc = in.nextInt();
			Solution sol = new Solution();
			for(int i=1; i<=tc;++i){
				 sol.solve(i);
			}
			in.close();
			out.close();
	}
	
	static class InputReader {
		BufferedReader reader;
		StringTokenizer st;
		public InputReader(InputStream in){
			reader = new BufferedReader(new InputStreamReader(in));
			st = null;
		}
		
		public String next() throws IOException{
			while(st == null || !st.hasMoreTokens()){
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}
		
		public Long nextLong() throws IOException{
			return Long.parseLong(next());
		}
		
		public Integer nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		
		public void close() throws IOException{
			reader.close();
		}
	}
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        outer :
        while(t>0){
            int n = sc.nextInt();

            int[] nums = new int[n];

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

            for(int i = 1 ; i < n ; i++){
                int min = Math.min(nums[i],nums[i-1]);
                nums[i] = nums[i] - min;
                nums[i-1] = nums[i-1] - min;

                if(nums[i-1] > nums[i] ) {
                    System.out.println("NO");
                    t--;
                    continue outer;
                }
            }
            System.out.println("YES");
            t--;
        }
    }
}
Problem: 2062C - Cirno and Operations
Language: java

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

Solution 2 (runtime: 140 ms):
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;



public class Main {
    static int MOD = (int) (1e9+7);
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out, false);
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
    static List<Long> list = new ArrayList<>();
    public static void main(String[] args) throws Exception {

        Main main = new Main();
        int T = in.nextInt();
        while (T-- > 0){
            main.solve();
        }
        out.flush();
    }

    void solve() {
        int n = in.nextInt();
        List<Long> list = new ArrayList<>();
        long sum = 0;
        for (int i = 0; i < n; i++) {
            long t = in.nextInt();
            list.add(t);
            sum += t;
        }
        long max = sum;
        while (list.size() > 1){
            List<Long> list0 = new ArrayList<>();
            sum = 0;
            for (int i = 1; i < list.size(); i++) {
                long t = list.get(i) - list.get(i - 1);
                list0.add(t);
                sum += t;
            }
            if(sum < 0) sum *= -1;
            max = Math.max(max, sum);
            list = list0;

        }
        out.println(max);
    }





}
Problem: 2050C - Uninteresting Number
Language: java

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

public class Main{

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		int t = Integer.parseInt(br.readLine());

		while(t-- > 0){
			String num = br.readLine();
			char[] s = num.toCharArray();
			boolean[] dp = new boolean[9];
			dp[0] = true;

			for(char c: s){
				boolean[] ndp = new boolean[9];
				for(int i = 0; i < 9; i++){
					if(dp[i]){
						int digit = c - '0';
						while(digit <= 9){
							ndp[(i+digit)%9] = true;
							if(digit <= 1) break;
							digit *= digit;
						}
					}
				}
				dp = ndp;
			}

			bw.write(dp[0] ? "YES\n" : "NO\n");

		}

		bw.flush();
		br.close();
		bw.close();
		
	}

}

Solution 2 (runtime: 327 ms):
import java.util.*;
public class temp{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        sc.nextLine();
        while(t-->0){
            String s=sc.nextLine();
            char[] c=s.toCharArray();
            int[] fre=new int[10];
            int sum=0;
            for(int i=0;i<c.length;i++){
                int cr=c[i]-'0';
                fre[cr]++;
                sum+=cr;
                if(sum>9)sum=sum%10+sum/10;
            }
            int f=-1;
            if(sum==0 || sum==9)f=1;
            else{
                int[][] dp=new int[Math.min(10,fre[2]+1)][Math.min(10,fre[3]+1)];
                for(int i=0;i<dp.length;i++)
                    Arrays.fill(dp[i],-1);
                int ans=solve(sum,dp,1,1);
                if(ans==0)f=1;
            }
            if(f==1)System.out.println("YES");
            else System.out.println("NO");
        }
    }
    public static int solve(int sum,int[][] dp,int i,int j){
        if(sum==0){return 0;}
        if(i==dp.length && j==dp[0].length)return 1;
        if(i<dp.length && j<dp[0].length && dp[i][j]!=-1)return dp[i][j];
        if((i<dp.length && solve((sum+2)%9,dp,i+1,j)==0) || (j<dp[0].length && solve((sum+6)%9,dp,i,j+1)==0)){
            if(i<dp.length && j<dp[0].length)dp[i][j]=0;
            return 0;}
        if(i<dp.length && j<dp[0].length)dp[i][j]=1;
        return 1;
    }
}
Problem: 2063B - Subsequence Update
Language: java

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

public class CF_1000_B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int test_cases = sc.nextInt();
        while (test_cases-- > 0) {
            int n = sc.nextInt();
            int l = sc.nextInt();
            int r = sc.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = sc.nextInt();
            int[] arr1 = Arrays.copyOfRange(arr, 0, r);
            int[] arr2 = Arrays.copyOfRange(arr, l - 1, arr.length);
            Arrays.sort(arr1);
            Arrays.sort(arr2);
            long min1 = 0;
            long min2 = 0;
            for (int i = 0; i < r - l + 1; i++) {
                min1 += arr1[i];
                min2 += arr2[i];
            }
            sb.append(Math.min(min1, min2)).append("\n");
        }
        sc.close();
        System.out.println(sb.toString());
    }
}

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