ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

bool can_transform(int n, int m, vector<ll> &a, vector<ll> &b) {
    ll sum_a = 0, sum_b = 0;
    for(auto &x : a) sum_a += x;
    for(auto &x : b) sum_b += x;
    if(sum_a != sum_b) return false;
    // Sort a in descending order
    sort(a.begin(), a.end(), greater<ll>());
    // Sort b in descending order
    sort(b.begin(), b.end(), greater<ll>());
    // Initialize priority queue with b's elements
    priority_queue<ll> pq;
    for(auto &x : b) pq.push(x);
    // Pointer for a's elements
    int a_ptr = 0;
    while(!pq.empty()) {
        ll y = pq.top(); pq.pop();
        if(a_ptr < n && a[a_ptr] == y) {
            a_ptr++;
        }
        else {
            if(y < 2) {
                return false;
            }
            // Split y into two parts
            ll x, y_x;
            if(y % 2 == 0) {
                x = y / 2;
                y_x = y / 2;
            }
            else {
                x = y / 2;
                y_x = y - x;
            }
            if(abs(x - y_x) > 1) {
                return false;
            }
            pq.push(x);
            pq.push(y_x);
        }
    }
    if(a_ptr == n) return true;
    else return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        int n, m;
        cin >> n >> m;
        vector<ll> a(n);
        for(auto &x : a) cin >> x;
        vector<ll> b(m);
        for(auto &x : b) cin >> x;
        bool res = can_transform(n, m, a, b);
        if(res) cout << "Yes\n";
        else cout << "No\n";
    }
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define lld long double
#define vll vector<long long int>
#define vlld vector<long double>
#define vi vector<int>
#define vsort sort(v.begin(),v.end())
#define print cout << fixed << setprecision(0) << 
#define vvv(x,y)  vector<vector<int>>vec((x),vector<int>((y)))

int main()
{
    //code here
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vll a(n);
        int i;
        ll ans=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            ans+=a[i];
        }
        ans=abs(ans);
        for(i=1;i<n;i++)
        {
            ll sum=0;
            for(int j=0;j<n-i;j++)
            {
                a[j]=a[j]-a[j+1];
                sum+=a[j];
            }
            ans=max(ans,abs(sum));
            a.pop_back();
        }
        cout<<ans<<endl;
    }
    
}



Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define lld long double
#define vll vector<long long int>
#define vlld vector<long double>
#define vi vector<int>
#define vsort sort(v.begin(),v.end())
#define print cout << fixed << setprecision(0) << 
#define vvv(x,y)  vector<vector<int>>vec((x),vector<int>((y)))

int main()
{
    //code here
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vll a(n);
        int i;
        ll ans=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            ans+=a[i];
        }
        if(a.size()>1)
        ans=abs(ans);
        for(i=1;i<n;i++)
        {
            ll sum=0;
            for(int j=0;j<n-i;j++)
            {
                a[j]=a[j]-a[j+1];
                sum+=a[j];
            }
            if(a.size()>1)
            ans=max(ans,abs(sum));
            else
            ans=max(ans,sum);
            a.pop_back();
        }
        cout<<ans<<endl;
    }
    
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define lld long double
#define vll vector<long long int>
#define vlld vector<long double>
#define vi vector<int>
#define vsort sort(v.begin(),v.end())
#define print cout << fixed << setprecision(0) << 
#define vvv(x,y)  vector<vector<int>>vec((x),vector<int>((y)))

int main()
{
    //code here
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vll a(n);
        int i;
        ll ans=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            ans+=a[i];
        }
        ans=abs(ans);
        for(i=1;i<n;i++)
        {
            ll sum=0;
            for(int j=0;j<n-i;j++)
            {
                a[j]=a[j]-a[j+1];
                sum+=a[j];
            }
            ans=max(ans,abs(sum));
            a.pop_back();
        }
        cout<<ans<<endl;
    }
    
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define lld long double
#define vll vector<long long int>
#define vlld vector<long double>
#define vi vector<int>
#define vsort sort(v.begin(),v.end())
#define print cout << fixed << setprecision(0) << 
#define vvv(x,y)  vector<vector<int>>vec((x),vector<int>((y)))

int main()
{
    //code here
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vll a(n);
        int i;
        ll ans=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            ans+=a[i];
        }
        if(a.size()>1)
        ans=abs(ans);
        for(i=1;i<n;i++)
        {
            ll sum=0;
            for(int j=0;j<n-i;j++)
            {
                a[j]=a[j]-a[j+1];
                sum+=a[j];
            }
            if(a.size()>1)
            ans=max(ans,abs(sum));
            else
            ans=max(ans,sum);
            a.pop_back();
        }
        cout<<ans<<endl;
    }
    
}



Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define lld long double
#define vll vector<long long int>
#define vlld vector<long double>
#define vi vector<int>
#define vsort sort(v.begin(),v.end())
#define print cout << fixed << setprecision(0) << 
#define vvv(x,y)  vector<vector<int>>vec((x),vector<int>((y)))

int main()
{
    //code here
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vll a(n);
        int i;
        ll ans=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            ans+=a[i];
        }
        // if(a.size()>1)
        // ans=abs(ans);
        for(i=1;i<n;i++)
        {
            ll sum=0;
            for(int j=0;j<n-i;j++)
            {
                a[j]=a[j]-a[j+1];
                sum+=a[j];
            }
            if(a.size()>1)
            ans=max(ans,abs(sum));
            else
            ans=max(ans,sum);
            a.pop_back();
        }
        cout<<ans<<endl;
    }
    
}
Problem: 2052A - Adrenaline Rush
Language: Java 21

Previous submission (verdict: Wrong answer on test 1):
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);        
        int n = sc.nextInt();
        int[] a = new int[n + 1];
        int[] b = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            b[i] = i;
        }
        Queue<Integer> k = new LinkedList<>();
        int ans = 0;       
        int[] position = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            position[a[i]] = i;
        }
        for (int i = n; i >= 1; i--) {
            int targetPos = position[a[i]];
            if (targetPos != i) {
                for (int j = targetPos; j < i; j++) {
                    k.add(b[j]);
                    k.add(b[j + 1]);
                    int temp = b[j];
                    b[j] = b[j + 1];
                    b[j + 1] = temp;
                    ans++;
                }
            }
        }
        System.out.println(ans);
        while (!k.isEmpty()) {
            System.out.print(k.poll() + " ");
            System.out.println(k.poll());
        }sc.close();
    }
}


Submission (verdict: Wrong answer on test 1):
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n + 1]; // Input array
        int[] b = new int[n + 1]; // Sorted array
        int[] pos = new int[n + 1]; // Position array

        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
            b[i] = i;
            pos[i] = i; // Initial position of element `i` is `i`
        }

        Queue<Integer> k = new LinkedList<>();
        int ans = 0;

        for (int i = n; i >= 1; i--) {
            int currentPos = pos[a[i]]; // Get the current position of a[i]
            while (currentPos > i) { // Swap until it's in the correct position
                k.add(currentPos);
                k.add(currentPos - 1);

                // Perform the adjacent swap in `b`
                int temp = b[currentPos];
                b[currentPos] = b[currentPos - 1];
                b[currentPos - 1] = temp;

                // Update the positions
                pos[b[currentPos]] = currentPos;
                pos[b[currentPos - 1]] = currentPos - 1;

                currentPos--; // Move the element closer to its target
                ans++;
            }
        }

        // Print results
        System.out.println(ans);
        while (!k.isEmpty()) {
            System.out.print(k.poll() + " ");
            System.out.println(k.poll());
        }
        sc.close();
    }
}
Problem: 2052A - Adrenaline Rush
Language: Java 21

Previous submission (verdict: Time limit exceeded on test 44):
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);        
        int n = sc.nextInt();
        int[] a = new int[1005];
        int[] b = new int[1005];        
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }        
        for (int i = 1; i <= n; i++) {
            b[i] = i;
        }        
        Queue<Integer> k = new LinkedList<>();
        int ans = 0;        
        for (int i = n; i >= 1; i--) {
            for (int j = 1; j <= n; j++) {
                if (b[j] == a[i]) {
                    for (int t = j; t > 1; t--) {
                        k.add(b[t]);
                        k.add(b[t - 1]);
                        int temp = b[t];
                        b[t] = b[t - 1];
                        b[t - 1] = temp;
                        ans++;
                    }break;
                }
            }
        }        
        System.out.println(ans);       
        while (!k.isEmpty()) {
            System.out.print(k.poll() + " ");
            System.out.println(k.poll());
        }sc.close();
    }
}



Submission (verdict: Wrong answer on test 1):
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);        
        int n = sc.nextInt();
        int[] a = new int[n + 1];
        int[] b = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            b[i] = i;
        }
        Queue<Integer> k = new LinkedList<>();
        int ans = 0;       
        int[] position = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            position[a[i]] = i;
        }
        for (int i = n; i >= 1; i--) {
            int targetPos = position[a[i]];
            if (targetPos != i) {
                for (int j = targetPos; j < i; j++) {
                    k.add(b[j]);
                    k.add(b[j + 1]);
                    int temp = b[j];
                    b[j] = b[j + 1];
                    b[j + 1] = temp;
                    ans++;
                }
            }
        }
        System.out.println(ans);
        while (!k.isEmpty()) {
            System.out.print(k.poll() + " ");
            System.out.println(k.poll());
        }sc.close();
    }
}
Problem: 2052A - Adrenaline Rush
Language: Java 21

Previous submission (verdict: Wrong answer on test 1):
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n + 1]; // Input array
        int[] b = new int[n + 1]; // Sorted array
        int[] pos = new int[n + 1]; // Position array

        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
            b[i] = i;
            pos[i] = i; // Initial position of element `i` is `i`
        }

        Queue<Integer> k = new LinkedList<>();
        int ans = 0;

        for (int i = n; i >= 1; i--) {
            int currentPos = pos[a[i]]; // Get the current position of a[i]
            while (currentPos > i) { // Swap until it's in the correct position
                k.add(currentPos);
                k.add(currentPos - 1);

                // Perform the adjacent swap in `b`
                int temp = b[currentPos];
                b[currentPos] = b[currentPos - 1];
                b[currentPos - 1] = temp;

                // Update the positions
                pos[b[currentPos]] = currentPos;
                pos[b[currentPos - 1]] = currentPos - 1;

                currentPos--; // Move the element closer to its target
                ans++;
            }
        }

        // Print results
        System.out.println(ans);
        while (!k.isEmpty()) {
            System.out.print(k.poll() + " ");
            System.out.println(k.poll());
        }
        sc.close();
    }
}



Submission (verdict: Accepted):
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: 2052A - Adrenaline Rush
Language: Java 21


Submission (verdict: Time limit exceeded on test 44):
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);        
        int n = sc.nextInt();
        int[] a = new int[1005];
        int[] b = new int[1005];        
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }        
        for (int i = 1; i <= n; i++) {
            b[i] = i;
        }        
        Queue<Integer> k = new LinkedList<>();
        int ans = 0;        
        for (int i = n; i >= 1; i--) {
            for (int j = 1; j <= n; j++) {
                if (b[j] == a[i]) {
                    for (int t = j; t > 1; t--) {
                        k.add(b[t]);
                        k.add(b[t - 1]);
                        int temp = b[t];
                        b[t] = b[t - 1];
                        b[t - 1] = temp;
                        ans++;
                    }break;
                }
            }
        }        
        System.out.println(ans);       
        while (!k.isEmpty()) {
            System.out.print(k.poll() + " ");
            System.out.println(k.poll());
        }sc.close();
    }
}
Problem: 2050D - Digital string maximization
Language: Java 8

Previous submission (verdict: Time limit exceeded on test 6):
import java.util.*;

public class DigitalStringMaximization{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++){
			System.out.println(maximize(sc.next()));
		}
	}
	
	private static String maximize(String str){
		for(int i = 1; i < str.length(); i++){
			for(int j = i; j >= 1; j--){
				if(str.charAt(j) - str.charAt(j-1) > 1)
					str = perform(str, j);
				else break;
			}
				
		}
		return str;
	}
	
	private static String perform(String str, int i){
		int j = i - 1;
		char[] chars = str.toCharArray();
		chars[i] = (char)(chars[i] - 1);
		char temp = chars[i];
		chars[i] = chars[j];
		chars[j] = temp;
		return new String(chars);
	}
}

/*
i = 1 51476
i = 2 53176
i = 3 53616 55316
I = 4 55316
i = 5 55351 55431
*/


Submission (verdict: Accepted):
import java.util.*;

public class DigitalStringMaximization{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] result = new String[n];
		for(int i = 0; i < n; i++){
			result[i]= maximize(sc.next());
		}
		Arrays.stream(result).forEach(System.out::println);
	}
	
	private static String maximize(String str){
		char[] chars = str.toCharArray();
		int num;
		for(int i = 1; i < chars.length; i++){
			num = chars[i] - '0';
			for(int j = num; j >= 0; j--){
				if( i - j < 0) continue;
				if(chars[ i - j ] < (char)(chars[i] - j)){
					char temp = (char)(chars[i] - j);
					for(int k = i; k > i - j; k--){
						chars[k] = chars[k - 1];
					}
					chars[i - j] = temp;
					break;
				}
			}
		} 
		return new String(chars);
	}
	
	
}

/*
i = 1 51476
i = 2 53176
i = 3 53616 55316
I = 4 55316
i = 5 55351 55431
19


*/
Problem: 2050D - Digital string maximization
Language: Java 8

Previous submission (verdict: Time limit exceeded on test 6):
import java.util.*;

public class DigitalStringMaximization{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] result = new String[n];
		for(int i = 0; i < n; i++){
			result[i] = maximize(sc.next());
		}
		Arrays.stream(result).forEach(System.out::println);
	}
	
	private static String maximize(String str){
		for(int i = 1; i < str.length(); i++){
			for(int j = i; j >= 1; j--){
				if(str.charAt(j) - str.charAt(j-1) > 1)
					str = perform(str, j);
				else break;
			}
				
		}
		return str;
	}
	
	private static String perform(String str, int i){
		int j = i - 1;
		char[] chars = str.toCharArray();
		chars[i] = (char)(chars[i] - 1);
		char temp = chars[i];
		chars[i] = chars[j];
		chars[j] = temp;
		return new String(chars);
	}
}

/*
i = 1 51476
i = 2 53176
i = 3 53616 55316
I = 4 55316
i = 5 55351 55431
*/


Submission (verdict: Time limit exceeded on test 6):
import java.util.*;

public class DigitalStringMaximization{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++){
			System.out.println(maximize(sc.next()));
		}
	}
	
	private static String maximize(String str){
		for(int i = 1; i < str.length(); i++){
			for(int j = i; j >= 1; j--){
				if(str.charAt(j) - str.charAt(j-1) > 1)
					str = perform(str, j);
				else break;
			}
				
		}
		return str;
	}
	
	private static String perform(String str, int i){
		int j = i - 1;
		char[] chars = str.toCharArray();
		chars[i] = (char)(chars[i] - 1);
		char temp = chars[i];
		chars[i] = chars[j];
		chars[j] = temp;
		return new String(chars);
	}
}

/*
i = 1 51476
i = 2 53176
i = 3 53616 55316
I = 4 55316
i = 5 55351 55431
*/
Problem: 2050D - Digital string maximization
Language: Java 8


Submission (verdict: Time limit exceeded on test 5):
import java.util.*;

public class DigitalStringMaximization{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] result = new String[n];
		for(int i = 0; i < n; i++){
			result[i] = maximize(sc.next());
		}
		Arrays.stream(result).forEach(System.out::println);
	}
	
	private static String maximize(String str){
		for(int i = 1; i < str.length(); i++){
			for(int j = i; j >= 1; j--){
				String op = perform(str, j);
				if(op.compareTo(str) > 0) str = op;
				else break;
			}
				
		}
		return str;
	}
	
	private static String perform(String str, int i){
		int j = i - 1;
		char[] chars = str.toCharArray();
		chars[i] = (char)(chars[i] - 1);
		char temp = chars[i];
		chars[i] = chars[j];
		chars[j] = temp;
		return new String(chars);
	}
}
Problem: 2050D - Digital string maximization
Language: Java 8

Previous submission (verdict: Time limit exceeded on test 5):
import java.util.*;

public class DigitalStringMaximization{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] result = new String[n];
		for(int i = 0; i < n; i++){
			result[i] = maximize(sc.next());
		}
		Arrays.stream(result).forEach(System.out::println);
	}
	
	private static String maximize(String str){
		for(int i = 1; i < str.length(); i++){
			for(int j = i; j >= 1; j--){
				String op = perform(str, j);
				if(op.compareTo(str) > 0) str = op;
				else break;
			}
				
		}
		return str;
	}
	
	private static String perform(String str, int i){
		int j = i - 1;
		char[] chars = str.toCharArray();
		chars[i] = (char)(chars[i] - 1);
		char temp = chars[i];
		chars[i] = chars[j];
		chars[j] = temp;
		return new String(chars);
	}
}

Submission (verdict: Time limit exceeded on test 6):
import java.util.*;

public class DigitalStringMaximization{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] result = new String[n];
		for(int i = 0; i < n; i++){
			result[i] = maximize(sc.next());
		}
		Arrays.stream(result).forEach(System.out::println);
	}
	
	private static String maximize(String str){
		for(int i = 1; i < str.length(); i++){
			for(int j = i; j >= 1; j--){
				if(str.charAt(j) - str.charAt(j-1) > 1)
					str = perform(str, j);
				else break;
			}
				
		}
		return str;
	}
	
	private static String perform(String str, int i){
		int j = i - 1;
		char[] chars = str.toCharArray();
		chars[i] = (char)(chars[i] - 1);
		char temp = chars[i];
		chars[i] = chars[j];
		chars[j] = temp;
		return new String(chars);
	}
}

/*
i = 1 51476
i = 2 53176
i = 3 53616 55316
I = 4 55316
i = 5 55351 55431
*/
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <iostream>

#include<bits/stdc++.h>

#define ll long long

using namespace std;

void solve() {

string s;

cin>>s;

int n=s.size();

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

int num=s[i]-'0',ind=0;

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

if(s[i]-'0'&&s[j]-'0'-(j-i)>num){num=s[j]-'0'-(j-i);ind=j;}

}

if(ind!=0){

for(int j=ind;j>i;j--)s[j]=s[j-1];

s[i]='0'+num;

}

}

cout<<s<<"\n";

}

int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) {

solve();

}

return 0;

}