ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: java

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

public class Main {
    public static HashMap<Long,Long> map;
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int tes=1;
        label:while(tes-->0){
           int n=sc.nextInt(),i,j,ans=0;
           int a[]=new int[n+1];
           int idx[]=new int[n+1];
           for(i=1;i<=n;i++) a[i]=sc.nextInt();
           for(i=1;i<=n;i++) idx[a[i]]=i;
           StringBuilder sb=new StringBuilder();
           for(i=1;i<=n;i++){
                for(j=n;j>idx[i];j--){
                    if(a[j]>i) continue;
                    ans++;
                    sb.append(i+" "+a[j]+"\n");
                }
                for(j=idx[i]-1;j>=1;j--){
                    if(a[j]>i) continue;
                    ans++;
                    sb.append(i+" "+a[j]+"\n");
                }
                for(j=1;j<idx[i];j++){
                    if(a[j]>i) continue;
                    ans++;
                    sb.append(a[j]+" "+i+"\n");
                }
           }
           System.out.println(ans+"\n"+sb);
        }
    }
}

Solution 2 (runtime: 1999 ms):
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        List<int[]> res = new ArrayList<>();
        for (int i = n; i >= 1; i--) {
            int j = 0;
            while (arr[j] != i) {
                j++;
            }
            for (int c = j - 1; c >= 0; c--) {
                res.add(new int[]{arr[c], i});
                swap(arr, c, c + 1);
            }
            for (int c = 1; c < i; c++) {
                res.add(new int[]{i, arr[c]});
                swap(arr, c, c - 1);
            }
        }
        System.out.println(res.size());
        for (int i = res.size() - 1; i >= 0; i--) {
            int[] pair = res.get(i);
            System.out.println(pair[0] + " " + pair[1]);
        }
    }
    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 656 ms):
import java.util.*;
public class subtractMinSort {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){

            int n=sc.nextInt();
            int[] arr = new int[n];

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

            boolean flag = true;
            for(int i=0;i<n-1;i++){
                int min = Math.min(arr[i],arr[i+1]);
                arr[i] = arr[i]-min;
                arr[i+1] = arr[i+1]-min;
            }

            for(int i=0;i<n-1;i++){
                if(arr[i]>arr[i+1]){
                    System.out.println("NO");
                    flag = false;
                    break;
                }
            }
            if(flag){
                System.out.println("YES");
            }


        }
    }
}

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

public class Solution {

public static void main(String[] args) {

Scanner scn = new Scanner(System.in);

int cases = scn.nextInt();

while (cases > 0) {

int n = scn.nextInt();

int[] arr = new int[n];

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

arr[i] = scn.nextInt();

}

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

int cur = arr[i];

int next= arr[i+1];

arr[i]-=Math.min(cur,next);

arr[i+1]-=Math.min(cur,next);

}

boolean flag=true;

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

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

flag=false;

break;

}

}

if(flag) System.out.println("YES");

else System.out.println("NO");

cases--;

}

}

}
Problem: 2050D - Digital string maximization
Language: java

Solution 1 (runtime: 296 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[] arr = s.toCharArray();



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

int best = arr[i] - '0', pos = i;



for (int j = i; j < Math.min(i + 10, arr.length); j++) {

if ((arr[j] - '0') - (j - i) > best) {

best = (arr[j] - '0') - (j - i);

pos = j;

}

}



while (pos > i) {

char temp = arr[pos];

arr[pos] = arr[pos - 1];

arr[pos - 1] = temp;

pos--;

}



arr[i] = (char) (best + '0');

}



System.out.println(new String(arr));

}

}

}



Solution 2 (runtime: 609 ms):
import java.math.*;

import java.util.*;



public class Main {

static int N = (int)2e5 + 5;

static int[] a = new int[N];

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int T = sc.nextInt();

while(T-- > 0){

String s = sc.next();

int len = s.length();

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

a[i] = (int)s.charAt(i - 1) - (int)'0';

}

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

int x = a[i], idx = i;

int mx = x, id = -1;

for(int j = i + 1;j <= len && j <= i + 8;j++){

if(a[j] - (j - i) > mx){

mx = a[j] - (j - i);

idx = j;

}

}

for(int j = idx - 1;j >= i;j--){

int t = a[j];

a[j] = a[j + 1] - 1;

a[j + 1] = t;

}

}

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

System.out.print(a[i]);

}

System.out.println();

}

sc.close();

}

}
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: 311 ms):

import java.util.Scanner;

public class Sol {
    static Scanner rd = new Scanner(System.in);
    public static void main(String[] args) {
        int tt = rd.nextInt();
        while (tt-- > 0) {
            new Solution().solve();
        }
    }

    static class Solution {
        void solve() {
            int n = rd.nextInt();
            long[] a = new long[n];

            for (int i = 0; i < n; i++) {
                a[i] = rd.nextInt();
            }
            int len = n;
            if (len == 1) {
                System.out.println(a[0]);
                return;
            }
            long max = getSum(a, n, false);
            while (len > 1) {
                for (int i = 0; i < len - 1; i++) {
                    a[i] = a[i + 1] - a[i];
                }
                len--;
                max = Math.max(Math.max(getSum(a, len, true), getSum(a, len, false)), max);
            }
            System.out.println(max);
        }

        long getSum(long[] a, int len, boolean neg) {
            long sum = 0;
            for (int i = 0; i < len; i++) {
                if (neg) {
                    sum += (-1) * a[i];
                } else {
                    sum += a[i];
                }
            }
            return sum;
        }
    }
}
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: 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: 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: 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: 2050D - Digital string maximization
Language: java

Solution 1 (runtime: 983 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));
        PrintWriter pw = new PrintWriter(System.out);
        int t = Integer.parseInt(br.readLine());
        char[] string;
        TreeSet<Integer> unused;
        ArrayList<Integer> used;
        while(t-- > 0)
        {
            char[] c = br.readLine().toCharArray();
            unused = new TreeSet<>();
            string = new char[c.length];
            for(int i = 0; i < c.length; i++)
            {
                unused.add(i);
            }
            for(int i = 0; i < c.length; i++)
            {
                int max = -1;
                int index = -1;
                int size = unused.size();
                used = new ArrayList<>();
                for(int j = 0; j < Math.min(size, 10); j++)
                {
                    int a = unused.pollFirst();
                    if(c[a] - 48 - j > max)
                    {
                        index = a;
                        max = c[a] - 48 - j;
                    }
                    used.add(a);
                }
                unused.addAll(used);
                unused.remove(index);
                string[i] = (char)(max + 48);
            }
            pw.println(new String(string));
        }
        pw.close();

    }
}

Solution 2 (runtime: 296 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[] arr = s.toCharArray();



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

int best = arr[i] - '0', pos = i;



for (int j = i; j < Math.min(i + 10, arr.length); j++) {

if ((arr[j] - '0') - (j - i) > best) {

best = (arr[j] - '0') - (j - i);

pos = j;

}

}



while (pos > i) {

char temp = arr[pos];

arr[pos] = arr[pos - 1];

arr[pos - 1] = temp;

pos--;

}



arr[i] = (char) (best + '0');

}



System.out.println(new String(arr));

}

}

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



public class Main {

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

    public static void main(String[] args) {

        

        int t = sc.nextInt();



        while(t-- > 0) {

            solve();

        }

    }



    static void solve() {

        int n = sc.nextInt();

        int l = sc.nextInt() - 1;

        int r = sc.nextInt() - 1;



        int[] a = new int[n];



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



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

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

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

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



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

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

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

            else {

                res1.add(a[i]);

                res2.add(a[i]);

            }

        }



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

            res1.add(before.poll());

            res1.poll();

        }



        long  sum = 0;

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



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

            res2.add(after.poll());

            res2.poll();

        }

        long sum2 = 0;

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



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

    }

}
Problem: 2050D - Digital string maximization
Language: java

Solution 1 (runtime: 983 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));
        PrintWriter pw = new PrintWriter(System.out);
        int t = Integer.parseInt(br.readLine());
        char[] string;
        TreeSet<Integer> unused;
        ArrayList<Integer> used;
        while(t-- > 0)
        {
            char[] c = br.readLine().toCharArray();
            unused = new TreeSet<>();
            string = new char[c.length];
            for(int i = 0; i < c.length; i++)
            {
                unused.add(i);
            }
            for(int i = 0; i < c.length; i++)
            {
                int max = -1;
                int index = -1;
                int size = unused.size();
                used = new ArrayList<>();
                for(int j = 0; j < Math.min(size, 10); j++)
                {
                    int a = unused.pollFirst();
                    if(c[a] - 48 - j > max)
                    {
                        index = a;
                        max = c[a] - 48 - j;
                    }
                    used.add(a);
                }
                unused.addAll(used);
                unused.remove(index);
                string[i] = (char)(max + 48);
            }
            pw.println(new String(string));
        }
        pw.close();

    }
}

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

public class DigitalStringMaximization {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(in.readLine());

        int t = Integer.parseInt(tokenizer.nextToken());

        while (t-- > 0) {
            tokenizer = new StringTokenizer(in.readLine());
            char[] c = tokenizer.nextToken().toCharArray();

            for (int i = c.length - 1; i > 0; i--) {
                if (c[i] > c[i - 1] + 1) {
                    operation(c, i);
                    i += 9;
                    if (i > c.length) {
                        i = c.length;
                    }
                }
            }

            System.out.println(new String(c));
        }
    }

//    public static int findLast(char[] c) {
//        for (int i = c.length - 1; i > 0; i--) {
//            if (c[i] > c[i - 1] + 1) {
//                return i + 1;
//            }
//        }
//        return c.length;
//    }

    public static void operation(char[] c, int i) {
        int cur = c[i];
        int left = c[i - 1];
        c[i - 1] = (char) (cur - 1);
        c[i] = (char) left;
    }
}
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: 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: 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: 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();

    }

}