ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int long long
#define F first
#define S second
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
 
const int MOD = 1e9 + 7;
int powMOD(int x, int n) {
    int res = 1;
    while(n > 0) {
        if(n % 2) {
            res *= x;
            res %= MOD;
        }
        x *= x;
        x %= MOD;
        n >>= 1;
    }
    return res;
}
 
int n;
void solve() {
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    vector<pair<int, int>> v;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            if(a[i] < a[j]) {
                v.push_back({a[j], a[i]});
                v.push_back({a[i], a[j]});
            } else {
                v.push_back({a[i], a[j]});
            }
        }
    }
    
    cout << v.size() << "\n";
    for(auto x: v) {
        cout << x.first << " " << x.second << "\n";
    }
    
}
 
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int long long
#define F first
#define S second
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
 
const int MOD = 1e9 + 7;
int powMOD(int x, int n) {
    int res = 1;
    while(n > 0) {
        if(n % 2) {
            res *= x;
            res %= MOD;
        }
        x *= x;
        x %= MOD;
        n >>= 1;
    }
    return res;
}
 
int n;
void solve() {
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    vector<pair<int, int>> v;
    for(int i = n - 1; i >= 0; i--) {
        for(int j = i-1; j >= 0; j--) {
            if(a[i] < a[j]) {
                v.push_back({a[j], a[i]});
            } else {
                v.push_back({a[i], a[j]});
                v.push_back({a[j], a[i]});
            }
        }
    }
    
    cout << v.size() << "\n";
    for(auto x: v) {
        cout << x.first << " " << x.second << "\n";
    }
    
}
 
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;

template <typename T>

using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long

#define pb push_back

#define pf push_front

#define eb emplace_back

#define ins insert

#define F first

#define S second

#define MAXN 100005

#define LOG (int)log2(MAXN)+1



const int INF = LLONG_MAX-10;

const int MOD = 1e9;

const double EPS = 1e-8;



//WA?



void solve() {

    int n, m;

    cin >> n >> m;



    multiset<int> ms_a, ms_b;

    vector<int> b_vals(m);

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

        cin >> x;

        ms_a.ins(x);

    }

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

        cin >> b_vals[i];

        ms_b.ins(b_vals[i]);

    }



    for (int x : b_vals) {

        auto it = ms_a.find(x);

        if (it != ms_a.end()) {

            ms_a.erase(it);

            ms_b.erase(ms_b.find(x));

        }

    }



    vector<int> a_rem(ms_a.begin(), ms_a.end());

    vector<int> b_rem(ms_b.begin(), ms_b.end());



    if ((a_rem.empty() && !b_rem.empty()) || (!a_rem.empty() && b_rem.empty())) {

        cout << "No\n";

        return;

    }



    int idx = 0;

    for (int target : b_rem) {

        int sum = a_rem[idx++];

        while (idx < (int)a_rem.size() && sum < target && llabs(sum - a_rem[idx]) <= 1) {

            sum += a_rem[idx++];

        }

        if (sum != target) {

            cout << "No\n";

            return;

        }

    }



    cout << "Yes\n";

}





signed main() {

    ios_base::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);

    int t = 1;

    cin >> t;

    while(t--) solve();

    return 0;

}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 7):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;

template <typename T>

using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long

#define pb push_back

#define pf push_front

#define eb emplace_back

#define ins insert

#define F first

#define S second

#define MAXN 100005

#define LOG (int)log2(MAXN)+1



const int INF = LLONG_MAX-10;

const int MOD = 1e9;

const double EPS = 1e-8;



void solve() {

	int n, m;

	cin >> n >> m;

	multiset<int> a, b;

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

		int x;

		cin >> x;

		a.ins(x);

	}

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

		int x;

		cin >> x;

		b.ins(x);

	}

	int t = n-m, c = 0;

	while(c<t && !a.empty() && !b.empty()){

		auto it1 = prev(b.end()), it2 = prev(a.end());

		b.erase(it1);

		if(*it1==*it2){

			a.erase(it2);

		} else{

			int x = *it1;

			b.ins( x/2 );

			b.ins( (x+1)/2 );

			c++;

		}

	}	

//	for(auto el: a) cout << el << ' '; cout << '\n';

//	for(auto el: b) cout << el << ' '; cout << '\n';

	if(a==b) cout << "Yes\n";

	else cout << "No\n";

}





signed main() {

    ios_base::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);

    int t = 1;

    cin >> t;

    while(t--) solve();

    return 0;

}



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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;

template <typename T>

using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long

#define pb push_back

#define pf push_front

#define eb emplace_back

#define ins insert

#define F first

#define S second

#define MAXN 100005

#define LOG (int)log2(MAXN)+1



const int INF = LLONG_MAX-10;

const int MOD = 1e9;

const double EPS = 1e-8;



void solve() {

	int n, m;

	cin >> n >> m;

	multiset<int> a, b;

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

		int x;

		cin >> x;

		a.ins(x);

	}

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

		int x;

		cin >> x;

		b.ins(x);

	}

    int t = n - m, c = 0;

    while (!a.empty() && !b.empty() && *prev(a.end()) == *prev(b.end())) {

        a.erase(prev(a.end()));

        b.erase(prev(b.end()));

    }

    while (c < t && !a.empty() && !b.empty()) {

        int x = *prev(b.end());

        b.erase(prev(b.end()));

        b.ins(x / 2);

        b.ins((x + 1) / 2);

        c++;

        while (!a.empty() && !b.empty() && *prev(a.end()) == *prev(b.end())) {

            a.erase(prev(a.end()));

            b.erase(prev(b.end()));

        }

    }

    cout << (a == b ? "Yes\n" : "No\n");

}





signed main() {

    ios_base::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);

    int t = 1;

    cin >> t;

    while(t--) solve();

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

typedef long long ll;

const int N=100000;

vector<int> v;

int CALMEX(vector<int> sex){

	int m[10]={};

	for(auto k:sex){

		m[k]++;

	}

	if(m[0]==0){

		return 0;

	}

	if(m[1]==0){

		return 1;

	}

	if(m[2]==0){

		return 2;

	}

	if(m[3]==0){

		return 3;

	}

	return 4;

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	int a[n+2]={};

	vector<vector<int>> g(n+2);

	g[x].push_back(y);

	g[y].push_back(x);

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

		g[i].push_back(i-1);

		g[i].push_back(i+1);

	}

	g[1].push_back(n);

	g[1].push_back(2);

	g[n].push_back(1);

	g[n].push_back(n-1);

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

		for(auto x:g[i]){

		//	cout<<a[x]<<" ";

			v.push_back(a[x]);

		}

		a[i]=CALMEX(v);

		v.clear();

	}

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

		cout<<a[i]<<" ";

	}

	cout<<'\n';

}

int main(){

	#define task ""

	if(fopen(task".inp", "r")){

		freopen(task".inp", "r", stdin);

		freopen(task".out", "w", stdout);

	}

	ios_base::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	int t;

	cin>>t;

	while(t--){

		solve();

	}

}



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

using namespace std;

typedef long long ll;

const int N=100000;

vector<int> v;

int CALMEX(vector<int> sex){

	int m[10]={};

	for(auto k:sex){

		m[k]++;

	}

	if(m[0]==0){

		return 0;

	}

	if(m[1]==0){

		return 1;

	}

	if(m[2]==0){

		return 2;

	}

	if(m[3]==0){

		return 3;

	}

	return 4;

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	int a[n+2]={};

	vector<vector<int>> g(n+2);

	g[x].push_back(y);

	g[y].push_back(x);

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

		g[i].push_back(i-1);

		g[i].push_back(i+1);

	}

	g[1].push_back(n);

	g[1].push_back(2);

	g[n].push_back(1);

	g[n].push_back(n-1);

	for(auto k:g[x]){

		//	cout<<a[x]<<" ";

			v.push_back(a[k]);

	}

	a[x]=CALMEX(v);

			v.clear();

	for(auto k:g[y]){

		//	cout<<a[x]<<" ";

			v.push_back(a[k]);

	}

	a[y]=CALMEX(v);

			v.clear();

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

		for(auto x:g[i]){

		//	cout<<a[x]<<" ";

			v.push_back(a[x]);

		}

		if(i!=x&&i!=y) a[i]=CALMEX(v);

		v.clear();

	}

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

		cout<<a[i]<<" ";

	}

	cout<<'\n';

}

int main(){

	#define task ""

	if(fopen(task".inp", "r")){

		freopen(task".inp", "r", stdin);

		freopen(task".out", "w", stdout);

	}

	ios_base::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	int t;

	cin>>t;

	while(t--){

		solve();

	}

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

typedef long long ll;

const int N=100000;

vector<int> v;

int CALMEX(vector<int> sex){

	int m[10]={};

	for(auto k:sex){

		m[k]++;

	}

	if(m[0]==0){

		return 0;

	}

	if(m[1]==0){

		return 1;

	}

	if(m[2]==0){

		return 2;

	}

	if(m[3]==0){

		return 3;

	}

	return 4;

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	int a[n+2]={};

	vector<vector<int>> g(n+2);

	g[x].push_back(y);

	g[y].push_back(x);

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

		g[i].push_back(i-1);

		g[i].push_back(i+1);

	}

	g[1].push_back(n);

	g[1].push_back(2);

	g[n].push_back(1);

	g[n].push_back(n-1);

	for(auto k:g[x]){

		//	cout<<a[x]<<" ";

			v.push_back(a[k]);

	}

	a[x]=CALMEX(v);

			v.clear();

	for(auto k:g[y]){

		//	cout<<a[x]<<" ";

			v.push_back(a[k]);

	}

	a[y]=CALMEX(v);

			v.clear();

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

		for(auto x:g[i]){

		//	cout<<a[x]<<" ";

			v.push_back(a[x]);

		}

		if(i!=x&&i!=y) a[i]=CALMEX(v);

		v.clear();

	}

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

		cout<<a[i]<<" ";

	}

	cout<<'\n';

}

int main(){

	#define task ""

	if(fopen(task".inp", "r")){

		freopen(task".inp", "r", stdin);

		freopen(task".out", "w", stdout);

	}

	ios_base::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	int t;

	cin>>t;

	while(t--){

		solve();

	}

}



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

using namespace std;

typedef long long ll;

const int N=100000;

vector<int> v;

int CALMEX(vector<int> sex){

	int m[10]={};

	for(auto k:sex){

		m[k]++;

	}

	if(m[0]==0){

		return 0;

	}

	if(m[1]==0){

		return 1;

	}

	if(m[2]==0){

		return 2;

	}

	if(m[3]==0){

		return 3;

	}

	return 4;

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	int a[n+2]={};

	vector<vector<int>> g(n+2);

	g[x].push_back(y);

	g[y].push_back(x);

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

		g[i].push_back(i-1);

		g[i].push_back(i+1);

	}

	g[1].push_back(n);

	g[1].push_back(2);

	g[n].push_back(1);

	g[n].push_back(n-1);

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

		for(auto x:g[i]){

		//	cout<<a[x]<<" ";

			v.push_back(a[x]);

		}

		a[i]=CALMEX(v);

		v.clear();

	}

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

		for(auto x:g[i]){

		//	cout<<a[x]<<" ";

			v.push_back(a[x]);

		}

		a[i]=CALMEX(v);

		v.clear();

	}

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

		cout<<a[i]<<" ";

	}

	cout<<'\n';

}

int main(){

	#define task ""

	if(fopen(task".inp", "r")){

		freopen(task".inp", "r", stdin);

		freopen(task".out", "w", stdout);

	}

	ios_base::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	int t;

	cin>>t;

	while(t--){

		solve();

	}

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;

typedef long long ll;

const int N=100000;

vector<int> v;

int CALMEX(vector<int> sex){

	int m[10]={};

	for(auto k:sex){

		m[k]++;

	}

	if(m[0]==0){

		return 0;

	}

	if(m[1]==0){

		return 1;

	}

	if(m[2]==0){

		return 2;

	}

	if(m[3]==0){

		return 3;

	}

	return 4;

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	int a[n+2]={};

	vector<vector<int>> g(n+2);

	g[x].push_back(y);

	g[y].push_back(x);

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

		g[i].push_back(i-1);

		g[i].push_back(i+1);

	}

	g[1].push_back(n);

	g[1].push_back(2);

	g[n].push_back(1);

	g[n].push_back(n-1);

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

		for(auto x:g[i]){

		//	cout<<a[x]<<" ";

			v.push_back(a[x]);

		}

		a[i]=CALMEX(v);

		v.clear();

	}

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

		cout<<a[i]<<" ";

	}

	cout<<'\n';

}

int main(){

	#define task ""

	if(fopen(task".inp", "r")){

		freopen(task".inp", "r", stdin);

		freopen(task".out", "w", stdout);

	}

	ios_base::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	int t;

	cin>>t;

	while(t--){

		solve();

	}

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

typedef long long ll;

const int N=100000;

vector<int> v;

int CALMEX(vector<int> sex){

	int m[10]={};

	for(auto k:sex){

		m[k]++;

	}

	if(m[0]==0){

		return 0;

	}

	if(m[1]==0){

		return 1;

	}

	if(m[2]==0){

		return 2;

	}

	if(m[3]==0){

		return 3;

	}

	return 4;

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	int a[n+2]={};

	vector<vector<int>> g(n+2);

	g[x].push_back(y);

	g[y].push_back(x);

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

		g[i].push_back(i-1);

		g[i].push_back(i+1);

	}

	g[1].push_back(n);

	g[1].push_back(2);

	g[n].push_back(1);

	g[n].push_back(n-1);

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

		for(auto x:g[i]){

		//	cout<<a[x]<<" ";

			v.push_back(a[x]);

		}

		a[i]=CALMEX(v);

		v.clear();

	}

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

		for(auto x:g[i]){

		//	cout<<a[x]<<" ";

			v.push_back(a[x]);

		}

		a[i]=CALMEX(v);

		v.clear();

	}

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

		cout<<a[i]<<" ";

	}

	cout<<'\n';

}

int main(){

	#define task ""

	if(fopen(task".inp", "r")){

		freopen(task".inp", "r", stdin);

		freopen(task".out", "w", stdout);

	}

	ios_base::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	int t;

	cin>>t;

	while(t--){

		solve();

	}

}



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

using namespace std;

typedef long long ll;

const int N=100000;

vector<int> v;

int CALMEX(vector<int> sex){

	int m[10]={};

	for(auto k:sex){

		m[k]++;

	}

	if(m[0]==0){

		return 0;

	}

	if(m[1]==0){

		return 1;

	}

	if(m[2]==0){

		return 2;

	}

	if(m[3]==0){

		return 3;

	}

	return 4;

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	int a[n+2]={},b[n+2]={};

	vector<vector<int>> g(n+2);

	g[x].push_back(y);

	g[y].push_back(x);

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

		g[i].push_back(i-1);

		g[i].push_back(i+1);

	}

	g[1].push_back(n);

	g[1].push_back(2);

	g[n].push_back(1);

	g[n].push_back(n-1);

	int thu=10;

	while(thu--){

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

		for(auto x:g[i]){

		//	cout<<a[x]<<" ";

			v.push_back(a[x]);

		}

		a[i]=CALMEX(v);

		v.clear();

	}

}

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

		cout<<a[i]<<" ";

	}

	cout<<'\n';

}

int main(){

	#define task ""

	if(fopen(task".inp", "r")){

		freopen(task".inp", "r", stdin);

		freopen(task".out", "w", stdout);

	}

	ios_base::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	int t;

	cin>>t;

	while(t--){

		solve();

	}

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n-1; i++)
	{
		int cur = s[i] - '0';
		vector<int> steps(n, 0);
		int step = 1;
		int maxv = 0, maxind = -1;
		for (int j = i + 1; j < n; j++)
		{
			steps[j] = s[j] == '0' ? 0 : (s[j] - '0') - step;
			if (steps[j] > maxv && steps[j] > cur && steps[j] != 0)
			{
				maxv = steps[j];
				maxind = j;
			}
			step++;
		}

		int j;
		for (j = (maxind == -1 ? -1 : maxind); j > i; j--)
		{
			swap(s[j], s[j - 1]);
		}

		if (j != -1)
		{
			int t = s[j] - '0';
			t = steps[maxind];
			s[j] = t + '0';
		}
	}

	cout << s << "\n";
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}

Submission (verdict: Time limit exceeded on test 7):
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n-1; i++)
	{
		int cur = s[i] - '0';
		vector<int> steps(n, 0);
		int step = 1;
		int maxv = 0, maxind = -1;
		for (int j = i + 1; j < n && j < i+10; j++)
		{
			steps[j] = s[j] == '0' ? 0 : (s[j] - '0') - step;
			if (steps[j] > maxv && steps[j] > cur && steps[j] != 0)
			{
				maxv = steps[j];
				maxind = j;
			}
			step++;
		}

		int j;
		for (j = (maxind == -1 ? -1 : maxind); j > i; j--)
		{
			swap(s[j], s[j - 1]);
		}

		if (j != -1)
		{
			int t = s[j] - '0';
			t = steps[maxind];
			s[j] = t + '0';
		}
	}

	cout << s << "\n";
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 7):
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n-1; i++)
	{
		int cur = s[i] - '0';
		vector<int> steps(n, 0);
		int step = 1;
		int maxv = 0, maxind = -1;
		for (int j = i + 1; j < n && j < i+10; j++)
		{
			steps[j] = s[j] == '0' ? 0 : (s[j] - '0') - step;
			if (steps[j] > maxv && steps[j] > cur && steps[j] != 0)
			{
				maxv = steps[j];
				maxind = j;
			}
			step++;
		}

		int j;
		for (j = (maxind == -1 ? -1 : maxind); j > i; j--)
		{
			swap(s[j], s[j - 1]);
		}

		if (j != -1)
		{
			int t = s[j] - '0';
			t = steps[maxind];
			s[j] = t + '0';
		}
	}

	cout << s << "\n";
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}

Submission (verdict: Time limit exceeded on test 7):
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n-1; i++)
	{
		int cur = s[i] - '0';
		vector<int> steps(n, 0);
		int step = 1;
		int maxv = 0, maxind = -1;
		for (int j = i + 1; j < n && j < i+10; j++)
		{
			steps[j] = s[j] == '0' ? 0 : (s[j] - '0') - step;
			if (steps[j] > maxv && steps[j] > cur)
			{
				maxv = steps[j];
				maxind = j;
			}
			step++;
		}

		int j;
		for (j = (maxind == -1 ? -1 : maxind); j > i; j--)
		{
			swap(s[j], s[j - 1]);
		}

		if (j != -1)
		{
			int t = s[j] - '0';
			t = steps[maxind];
			s[j] = t + '0';
		}
	}

	cout << s << "\n";
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 6):
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n-1; i++)
	{
		int cur = s[i] - '0';
		vector<int> steps(n, 0);
		int step = 1;
		int maxv = 0, maxind = -1;
		for (int j = i + 1; j < n; j++)
		{
			steps[j] = s[j] == '0' ? 0 : (s[j] - '0') - step;
			if (steps[j] > maxv && steps[j] > cur && steps[j] != 0)
			{
				maxv = steps[j];
				maxind = j;
			}
			step++;
		}

		int j;
		for (j = (maxind == -1 ? -1 : maxind); j > i; j--)
		{
			swap(s[j], s[j - 1]);
		}

		if (j != -1)
		{
			int t = s[j] - '0';
			t = steps[maxind];
			s[j] = t + '0';
		}
	}

	cout << s << "\n";
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 7):
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n-1; i++)
	{
		int cur = s[i] - '0';
		vector<int> steps(n, 0);
		int step = 1;
		int maxv = 0, maxind = -1;
		for (int j = i + 1; j < n && j < i+10; j++)
		{
			steps[j] = s[j] == '0' ? 0 : (s[j] - '0') - step;
			if (steps[j] > maxv && steps[j] > cur)
			{
				maxv = steps[j];
				maxind = j;
			}
			step++;
		}

		int j;
		for (j = (maxind == -1 ? -1 : maxind); j > i; j--)
		{
			swap(s[j], s[j - 1]);
		}

		if (j != -1)
		{
			int t = s[j] - '0';
			t = steps[maxind];
			s[j] = t + '0';
		}
	}

	cout << s << "\n";
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++)
	{
		int k = i;
		for (int j = i; j < n && j < i + 10; j++)
		{
			if (s[j] - j > s[k] - k)
			{
				k = j;
			}
		}

		while (k > i)
		{
			s[k]--;
			swap(s[k - 1], s[k]);
			k--;
		}
	}

	cout << s << "\n";
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using ll = long long;
using ull = unsigned long long;
 
const int MAXN = 2000001;
 
int n, m, i, j, l, r, x, a[MAXN];
 
void solve() {
    cin >> n;
    for (i=1; i<=n; i++) cin >> a[i];
    if (n == 2) {
        if (a[1] > a[2]) {
            cout << "NO" << endl;
        }
    }
    for (i=n; i>2; i--) {
        if (a[i] < a[i-1]) {
          x = min(a[i-1], a[i-2]);
          a[i-1] = a[i-2] -= x;
        }
    } 
    for (i=1; i<n; i++) {
        if (a[i] > a[i+1]) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}
 
int main() {
    int t = 1; 
    cin >> t; 
    while (t--) solve(); return 0;
}

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

using ll = long long;
using ull = unsigned long long;
 
const int MAXN = 2000001;
 
int n, m, i, j, l, r, x, a[MAXN];
 
void solve() {
    cin >> n;
    for (i=1; i<=n; i++) cin >> a[i];
    if (n == 2) {
        if (a[1] > a[2]) {
            cout << "NO" << endl;
            return;
        }
    }
    for (i=n; i>2; i--) {
        if (a[i] < a[i-1]) {
          x = min(a[i-1], a[i-2]);
          a[i-1] = a[i-2] -= x;
        }
    } 
    for (i=1; i<n; i++) {
        if (a[i] > a[i+1]) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}
 
int main() {
    int t = 1; 
    cin >> t; 
    while (t--) solve(); return 0;
}