ShaysXIA/CodeInsightBench huggingface dataset:
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: 546 ms):
#include<bits/stdc++.h>
#define LOCAL
#ifdef LOCAL
#if __has_include("C:\Users\HP\Desktop\Codeforces\template.cpp")
#include "C:\Users\HP\Desktop\Codeforces\template.cpp"
#else
#pragma message("template.cpp not found. Proceeding without it.")
#endif
#else
#define debug(...)
#endif
using namespace std;
#define out(x) cout<<x<<endl
#define in(x)  cin>>x
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define int long long
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<"#"<<x<<endl
#define deb2(x) cout<<"^"<<x<<endl
#define rep(i,x,y) for(int i=x;i<y;i++)
#define nxt cout<<endl;
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vc vector<char>

void solve(){
int n;
in(n);
vi v(n);
rep(i,0,n){
    in(v[i]);
}
if(n==1){
    out(0);
    return;
}
int cnt=0;
vp pp;
map<pair<int,int>,int>mp;
map<pair<int,int>,int>mpp;
for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
        if(v[i]>v[j]){
            cnt++;
            pp.push_back({v[i],v[j]});
        }else{
            cnt+=2;
            pp.push_back({v[i],v[j]});
            pp.push_back({v[j],v[i]});
        }
    }
}
vi tmp(n+1);
for(int i=1;i<=n;i++){
    tmp[i]=i;
}
out(cnt);
set<pair<int,int>>ss;
for(int i=0;i<pp.size();i++){
    ss.insert({pp[i].first,pp[i].second});
}
for(int i=0;i<cnt;i++){ 
    for(auto &it:ss){
        int x = it.first;
        int y = it.second;
        int z2 = tmp[x]-tmp[y];
        if(z2==1){
            cout<<x<<" "<<y<<endl;
            swap(tmp[x],tmp[y]);
            auto it2 = ss.find({x,y});
            ss.erase(it2);
            break;
        }
    }
}
}

signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;
// cin>>t;
while(t--){
solve();
}
}
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: 656 ms):
import java.util.*;

public class Main{

public static void main(String args[]){

Scanner scanner = new Scanner(System.in);

int tests = scanner.nextInt();

while(tests-- > 0){

int n = scanner.nextInt();

int A[] = new int[n];

boolean flag = false;

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

A[i] = scanner.nextInt();

}

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

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

flag = true;

break;

}else{

int temp = A[i];

A[i] -= temp;

A[i + 1] -= temp;

}

}

if(!flag){

System.out.println("YES");

}else{

System.out.println("NO");

}

}

scanner.close();

}



}
Problem: 2063B - Subsequence Update
Language: java

Solution 1 (runtime: 280 ms):
// Problem Page: https://codeforces.com/contest/2063/problem/B



import java.util.*;



public class SubsequenceUpdate {



    public static void main(String[] args) {



        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t-- > 0) {

            solve(sc);

        }

    }



    //subsequence does not have to be contiguous

    static void solve(Scanner sc) {

        int n = sc.nextInt();

        int l = sc.nextInt();

        int r = sc.nextInt();

        int[] a = new int[n];

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

            a[i] = sc.nextInt();

        }

        int[] b = new int[r];

        int[] c = new int[n - l + 1];

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

            b[i] = a[i];

        }

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

            c[i - l + 1] = a[i];

        }

        Arrays.sort(b);

        Arrays.sort(c);

        long sum_b = 0, sum_c = 0;

        for (int i = 0; i <= (r - l); i++) {

            sum_b += b[i];

            sum_c += c[i];

        }

        System.out.println(Math.min(sum_b, sum_c));

    }

}



Solution 2 (runtime: 467 ms):
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class SubsequenceUpdate {
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int tests = Integer.parseInt(scanner.nextLine());
    while (tests > 0){
      int n = scanner.nextInt();
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      long[] arr = new long[n];
      for (int i = 0; i < arr.length; i++){
        arr[i] = scanner.nextLong();
      }

      ArrayList<Long> toL = new ArrayList<>();
      ArrayList<Long> toR = new ArrayList<>();
      for (int i = 0; i < r; i++){
        toR.add(arr[i]);
      }
      for (int i = l - 1; i < n; i++){
        toL.add(arr[i]);
      }

      Collections.sort(toL);
      Collections.sort(toR);

      long sumOne = 0;
      for (int i = 0; i < r - l + 1; i++){
        sumOne += toL.get(i);
      }

      long sumTwo = 0;
      for (int i = 0; i < r - l + 1; i++){
        sumTwo += toR.get(i);
      }

      System.out.println(Math.min(sumTwo, sumOne));
      tests--;
    }
  }
}
Problem: 2049B - pspspsps
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 test = sc.nextInt();

		for (int z = 0; z < test; z++) {



			int n = sc.nextInt();

			String s= sc.next();

			int counts=0;

			int countp=0;

			int lasts =0;

			int firstp=Integer.MAX_VALUE;

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

			    if(s.charAt(i)=='s'){

			        counts++;

			        lasts=i;

			    }else if(s.charAt(i)=='p'){

			        countp++;

			        firstp=Math.min(firstp,i);

			    }

			}

			if(firstp<lasts){

			    System.out.println("NO");

			}

			else if(countp>1 && counts>1){

			    System.out.println("NO");

			}

			else if(countp==1 && counts>1){

			    if(s.charAt(n-1)=='p'){

			        System.out.println("YES");

			    }else{

			        System.out.println("NO");

			    }

			    

			}else if(countp==0 && counts>1){

			    System.out.println("YES");

			}

			

			else if (countp>1 && counts==1){

			    if(s.charAt(0)=='s'){

			        System.out.println("YES");

			    }else{

			        System.out.println("NO");

			    }

			}

			else if(countp==1 && counts==1){

			    if(s.charAt(0)=='s' || s.charAt(s.length()-1)=='p'){

			        System.out.println("YES");

			    }else{

			        System.out.println("NO");

			    }

			}

			else if(countp==0 && counts==1){

			    System.out.println("YES");

			}

			else{

			    System.out.println("YES");

			}

			

		}

	}

}

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

public class psp {
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        int tc = sc.nextInt();
        for(int i = 0; i < tc; i++){
            int n = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            String[] ps = new String[n];
            for(int j = 0; j < n; j++){
                ps[j] = s.substring(j, j+1);
            }
            //set up

            //test1
            String r = "yes";
            boolean pe = false;
            for(int j = 0; j < n; j++){
                if(ps[j].equals("p")){
                    pe = true;
                }
                if(pe && ps[j].equals("s")){
                    r = "no";
                    break;
                }
            }
            boolean se = false;
            for(int j = 1; j < n-1; j++){
                if(ps[j].equals("s")){
                    se = true;
                }
                if(se && ps[j].equals("p")){
                    r = "no";
                    break;
                }
            }
            System.out.println(r);
        }
    }
    
}
Problem: 2060D - Subtract Min Sort
Language: java

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

Solution 2 (runtime: 359 ms):




import java.io.*;

import java.util.*;



public class Main{

	static StreamTokenizer cins=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

	static PrintWriter cout=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	static int cin()throws Exception {

		cins.nextToken();

		return (int)cins.nval;

	}

	static void solve() throws Exception{

		int n=cin();

		int a[]=new int[n+1];

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

			a[i]=cin();

		}

		

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

			int now=Math.min(a[i],a[i+1]);

			a[i]-=now;

			a[i+1]-=now;

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

				cout.println("no");

				cout.flush();

				return;

			}

		}

		cout.println("Yes");

		cout.flush();

	}

	public static void main(String[] args)throws Exception{

		int t=cin();

		while(t--!=0)solve();

	}

}
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: 467 ms):
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class SubsequenceUpdate {
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int tests = Integer.parseInt(scanner.nextLine());
    while (tests > 0){
      int n = scanner.nextInt();
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      long[] arr = new long[n];
      for (int i = 0; i < arr.length; i++){
        arr[i] = scanner.nextLong();
      }

      ArrayList<Long> toL = new ArrayList<>();
      ArrayList<Long> toR = new ArrayList<>();
      for (int i = 0; i < r; i++){
        toR.add(arr[i]);
      }
      for (int i = l - 1; i < n; i++){
        toL.add(arr[i]);
      }

      Collections.sort(toL);
      Collections.sort(toR);

      long sumOne = 0;
      for (int i = 0; i < r - l + 1; i++){
        sumOne += toL.get(i);
      }

      long sumTwo = 0;
      for (int i = 0; i < r - l + 1; i++){
        sumTwo += toR.get(i);
      }

      System.out.println(Math.min(sumTwo, sumOne));
      tests--;
    }
  }
}
Problem: 2057C - Trip to the Olympiad
Language: java

Solution 1 (runtime: 390 ms):
import java.util.Scanner;

public class C2057 {
    static boolean solve(int l, int r, int val) {
        boolean ok = false;
        for (int i = 29; i >= 0; i--) {
            int x = 1 << i;
            if (x > l && x < r) {
                System.out.printf("%d %d %d\n", val + x - 1, val + x, val + x + 1);
                ok = true;
                break;
            } else if (x > l && x == r) {
                System.out.printf("%d %d %d\n", val + x - 2, val + x - 1, val + x);
                ok = true;
                break;
            }
        }
        return ok;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int l = sc.nextInt(), r = sc.nextInt();
            if (solve(l, r, 0))
                continue;
            int val = 0;
            for (int i = 29; i >= 0; i--) {
                int x = 1 << i;
                if ((l & x) == (r & x)) {
                    val += (l & x);
                    continue;
                }
                solve(l - val, r - val, val);
                break;
            }
        }
        sc.close();
    }
}


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

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            long l=sc.nextLong();
            long r=sc.nextLong();
            long a=0;
            long b=0;
            long c=0;
            long ans=0;
            for(int i=30;i>=0;i--){
                long x=(l&(1L<<i))!=0?1:0;
                long y=(r&(1L<<i))!=0?1:0;
                if(x==y){
                    ans+=x*(1L<<i);
                }else{
                    a=ans+(1L<<i);
                    b=a-1;
                    break;
                }
            }
            for(long i=l;i<=r;i++){
                if(a!=i&&b!=i){
                    c=i;
                    break;
                }
            }
            System.out.println(a+" "+b+" "+c);
        }
    }
}
Problem: 2050B - Transfusion
Language: java

Solution 1 (runtime: 718 ms):
#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <set>

#include <map>



using namespace std;

using ll = long long;

using vi = vector<int>;

using vvi = vector<vector<int>>;



void solve()

{



    ll n;

    cin >> n;

    vector<ll> a(n);



    ll summ = 0;

    for (ll i = 0; i < n; i++)

    {

        cin >> a[i];

        summ += a[i];

    }



    if (summ % n != 0)

    {

        cout << "NO\n";

        return;

    }



    ll v = summ / n;

    for (ll i = 1; i < n - 1; i++)

    {

        if (a[i - 1] < v)

        {

            ll op = v - a[i - 1];

            if (a[i + 1] < op)

            {

                cout << "NO\n";

                return;

            }

            else

            {

                a[i - 1] = v;

                a[i + 1] -= op;

            }

        }

        else

        {

            ll op = a[i - 1] - v;

            a[i + 1] += op;

            a[i - 1] = v;

        }

    }



    // for(auto num : a) cout << num << " ";

    // cout << "\n";



    if (a[n - 1] == v && a[n - 2] == v)

        cout << "YES\n";

    else

        cout << "NO\n";

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);



    int t = 1;

    cin >> t;

    while (t--)

        solve();

}

Solution 2 (runtime: 328 ms):
import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.util.*;



public class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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



        while (t-->0)

        {

            

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

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

            int k=0;

            int[] a=new int[n];

            // Set<Integer> set=new HashSet<>();

            long evensum=0,oddsum=0;

            while(st.hasMoreTokens())

            {

                a[k]=Integer.parseInt(st.nextToken());



                if(k%2==0)

                    evensum+=a[k];

                else

                    oddsum+=a[k];

                k++;

            }



            if(evensum%((n+1)/2)!=0 || oddsum%(n/2)!=0 || evensum/((n+1)/2)!=oddsum/(n/2))

                System.out.println("No");

            else

                System.out.println("Yes");

            



            



        }

    }

}



// class ListComparator implements Comparator<List<Integer>>

// {

//     int index=0;

//     public ListComparator(int i)

//     {

//         index=i;

//     }



//     @Override

//     public int compare(List<Integer> o1,List<Integer> o2)

//     {

//         return Integer.compare(o1.get(index), o2.get(index));

//     }



// }
Problem: 2060D - Subtract Min Sort
Language: java

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

        }
    }
}


Solution 2 (runtime: 687 ms):


import java.util.*;



public class AS {



    public static void main(String[] args) {



        Scanner s = new Scanner(System.in);



        int t = s.nextInt();

        s.nextLine();



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



            int c = s.nextInt();

            s.nextLine();



            int[] arr = new int[c];



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



                arr[j] = s.nextInt();

            }

            s.nextLine();



            boolean flag = true;

            for (int j = 0; j < c - 1; j++) {



                int temp = Math.min(arr[j], arr[j + 1]);

                arr[j] -= temp;

                arr[j + 1] -= temp;



                if (arr[j] > 0) {

                    flag = false;

                    break;

                }

            }



            if (flag)

                System.out.println("yes");

            else

                System.out.println("no");



        }



        s.close();

    }

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

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

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

public class D_2050 {
    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[] arr = s.toCharArray();
            int swapcount = 1;
            int ans = 0;
            while (swapcount != 0) {
                int sw = 0;
                for (int i = 1; i < arr.length; i++) {
                    char a = (char) (arr[i] - 1);
                    char b = arr[i - 1];
                    if ((arr[i] != '1' || arr[i] != '0') && a - b > 0) {
                        if (arr[i] > arr[i - 1]) {
                            swap(i - 1, i, arr);
                            sw++;
                        }
                    }
                }

                if (sw == 0) {
                    break;
                }
            }
            System.out.println(new String(arr));
        }
    }

    public static void swap(int i, int j, char[] arr) {
        arr[j] = (char) (arr[j] - 1);
        char t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    }
}