ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: java

Solution 1 (runtime: 452 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 l = sc.nextInt();
      int r = sc.nextInt();
      l--;
      r--;
      int []arr = new int[n];
      for(int i = 0; i < n; i++){
        arr[i] = sc.nextInt();
      }
      List<Integer> left = new ArrayList<>();
      for(int i = 0; i <= r; i++)left.add(arr[i]);
      List<Integer> right = new ArrayList<>();
      for(int i = l; i < n; i++)right.add(arr[i]);
      Collections.sort(left);
      Collections.sort(right);
      long j = 0;
      long h = 0;
      for(int i = 0; i < r-l+1; i++){
        j += (long)left.get(i);
        h += (long)right.get(i);
      }
      System.out.println(Math.min(j,h));
    }
      
    }
}

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: 2063B - Subsequence Update
Language: java

Solution 1 (runtime: 452 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 l = sc.nextInt();
      int r = sc.nextInt();
      l--;
      r--;
      int []arr = new int[n];
      for(int i = 0; i < n; i++){
        arr[i] = sc.nextInt();
      }
      List<Integer> left = new ArrayList<>();
      for(int i = 0; i <= r; i++)left.add(arr[i]);
      List<Integer> right = new ArrayList<>();
      for(int i = l; i < n; i++)right.add(arr[i]);
      Collections.sort(left);
      Collections.sort(right);
      long j = 0;
      long h = 0;
      for(int i = 0; i < r-l+1; i++){
        j += (long)left.get(i);
        h += (long)right.get(i);
      }
      System.out.println(Math.min(j,h));
    }
      
    }
}

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

public class Main
{
	public static void main(String[] args) {
		int t;
		Scanner sc = new Scanner(System.in);
		t = sc.nextInt();
		while(t > 0){
		    int n = sc.nextInt();
		    int l = sc.nextInt();
		    int r = sc.nextInt();
		    l--;
		    r--;
		    List<Integer> arr1 = new ArrayList<>();
		    List<Integer> arr2 = new ArrayList<>();
		    List<Integer> arr3 = new ArrayList<>();
		    for (int i = 0; i < l; i++){
		        arr1.add(sc.nextInt());
		    }
		    for (int i = l; i <= r; i++){
		        arr2.add(sc.nextInt());
		    }
		    for (int i = r + 1; i < n; i++){
		        arr3.add(sc.nextInt());
		    }
		    Collections.sort(arr1);
		    Collections.sort(arr2);
		    Collections.sort(arr3);
		  //  System.out.println(arr1);
		  //  System.out.println(arr2);
		  //  System.out.println(arr3);
		    long sum1 = 0, sum2 = 0;
		    int j = 0;
		    for (int i = arr2.size() - 1; i >= 0; i--){
		        int num1 = arr2.get(i);
		        if (j < arr1.size()){
		            num1 = Math.min(num1, arr1.get(j));
		            j++;
		        }
		        sum1 += num1;
		    }
		    j = 0;
		    for (int i = arr2.size() - 1; i >= 0; i--){
		        int num1 = arr2.get(i);
		        if (j < arr3.size()){
		            num1 = Math.min(num1, arr3.get(j));
		            j++;
		        }
		        sum2 += num1;
		    }
		    long ans = Math.min(sum1, sum2);
		    System.out.println(ans);
		    t--;
		}
	}
}
Problem: 2050C - Uninteresting Number
Language: java

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

public class C_Uninteresting_Number{
    static HashMap<Integer, Boolean> hm;
    public static boolean func(int num, int two, int three){
        if(num%9==0)return true;
        if(two==0&&three==0)return false;
        if(hm.containsKey(num))return hm.get(num);
        boolean t=false, th=false;
        if(two>0){
            t = func(num+2, two-1, three);
        }
        if(three>0){
            th = func(num+6, two, three-1);
        }
        hm.put(num, t|th);
        return t|th;
    }
    public static void main(String args[]){
        Scanner scn = new Scanner(System.in);
        int t = scn.nextInt();
        while(t-->0){
            String s = scn.next();
            int n = s.length();
            int num = 0;
            int two = 0, three=0;
            for(int i = 0; i < n; i++){
                num += (s.charAt(i)-'0');
                if(s.charAt(i)=='2')two++;
                if(s.charAt(i)=='3')three++;
            }
            hm = new HashMap<>();
            boolean ans = func(num, two, three);
            if(ans)
            System.out.println("YES");
            else System.out.println("NO");
        }
    }
}

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

char[] sb = sc.next().toCharArray(); // Using char array for efficiency

int n = sb.length;



int index = 1;

while (index < n) {

if (sb[index] != '0') {

int toPlace = index - 1;

int subtract = 1;



while (toPlace >= 0 && (sb[index] - '0') - subtract > (sb[toPlace] - '0')) {

if (toPlace == 0) break;

toPlace--;

subtract++;

}



if ((sb[index] - '0') - subtract <= (sb[toPlace] - '0')) {

toPlace++;

subtract--;

}



if (toPlace != index) {

char res = (char) ((sb[index] - '0' - subtract) + '0');



// Shift elements manually instead of using `add()` and `remove()`

for (int j = index; j > toPlace; j--) {

sb[j] = sb[j - 1];

}

sb[toPlace] = res;

}

}

index++;

}



System.out.println(new String(sb)); // Fast output

}

}

}
Problem: 2050C - Uninteresting Number
Language: java

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

public class TLE {
  public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
  static FastReader in = new FastReader();

  public static void main(String[] args) throws Exception {
    int testCases = in.nextInt();
    while (testCases-- > 0) {
      solve();
    }
    out.close();
  }

  private static void solve() {
    long sum = 0;
    String s = in.next();
    int two = 0, three = 0;
    for (char c : s.toCharArray()) {
      sum += c - '0';
      if (c == '2') {
        two++;
      } else if (c == '3') {
        three++;
      }
    }
    for (int t = 0; t <= two; t++) {
      for (int th = 0; th <= three; th++) {
        if ((sum + 2 * t + th * 6) % 9 == 0) {
          System.out.println("YES");
          return;
        }
      }
    }
    System.out.println("NO");

  }

  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 {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


Solution 2 (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;
    }
}
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: 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);
            }
        }
    }
}
Problem: 2052A - Adrenaline Rush
Language: java

Solution 1 (runtime: 2124 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();
        }
        solve(n , arr);
    }
    static void solve(int n, int[] arr) {
        List<String> list = new ArrayList<>();
        for(int i = n-1; i >= 0; i--) {
            int maxElement = i+1;
            int index = 0;
            for(int j = 0; j < n; j++) {
                if(arr[j] == maxElement) {
                    index = j;
                    break;
                }
            }
            //take front
            for(int j = index; j >= 1; j--) {
                list.add(arr[j-1]+ " " + arr[j]);
                int temp = arr[j];
                arr[j] = arr[j-1];
                arr[j-1] = temp;
            }
            //take back
            for(int j = 0; j < i; j++) {
                list.add(arr[j]+ " " + arr[j+1]);
                int temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
        Collections.reverse(list);
        System.out.println(list.size());
        for(String s : list) {
            System.out.println(s);
        }
    }
}

Solution 2 (runtime: 1983 ms):
import java.util.*;
public class AdrenalinRush{
public static void print(Object print){
    System.out.print(print);
}
public static void println(Object print){
    System.out.println(print);
}
public static void println(){
    System.out.println();
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    HashMap<Integer, Integer> map = new HashMap<>();
    HashMap<Integer, Integer> map2 = new HashMap<>();
    ArrayList<int[]> arr = new ArrayList<>();
    int ans=0;
    for(int i=0; i<n; i++){
        a[i]=sc.nextInt();
        map.put(i, a[i]);
        map2.put(i+1, n-i-1);
        b[i]=n-i;
    }
    for(int i=1; i<=n; i++){
        for(int j=i+1; j<=n; j++){
            arr.add(new int[]{j, i});
            // println(j+" "+i);
        }
    }
    ans+=n*(n-1)/2;
    for(int j=n-1; j>=0; j--){
        int tar = map.get(j);
        int curr = map2.get(tar);
        for(int i=curr; i<j; i++){
            ans++;
            // println(b[i+1]+" "+b[i]);
            arr.add(new int[]{b[i+1], b[i]});
            int temp=b[i];
            b[i]=b[i+1];
            b[i+1]=temp;
            map2.put(b[i], i);
            map2.put(b[i+1], i+1);
        }
    }
    println(ans);
    for(int[] i: arr){
        println(i[0]+" "+i[1]);
    }

}
}
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: 327 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 str = sc.next();

            int n = str.length();

            int arr[] = new int[n];



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

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

            }

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

                int idx = i;

                while (idx >= 1 && arr[idx] > 0 && arr[idx] > arr[idx - 1] + 1) {

                    int temp = arr[idx];

                    arr[idx] = arr[idx - 1];

                    arr[idx - 1] = temp - 1;

                    idx--; 

                }

            }

            StringBuilder sb = new StringBuilder(n);

            for (int a : arr) {

                sb.append(a);

            }

            System.out.println(sb);

        }

    }

}
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: 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--;
        }
    }
}