ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 7):
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define int long long int
#define nl cout<<endl;
#define PB push_back
#define MP make_pair
#define f(a,b) for(int i = a; i < b; i++)
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
    int t=1;
    cin>>t;
    while(t--){
        string s;
        cin >> s;

        int n = s.length();

        int val1, val2, maxi, ind;
        f(0,n-1){
            if(s[i] < '8'){
                val1 = s[i] - '0';
                maxi = val1;
                ind = i;
                for(int j = i + 1; j <= min(i+10,n-1); j++){
                    val2 = s[j] - '0';
                    val2 -= (j - i);
                    if(val2 > maxi){
                        maxi = val2;
                        ind = j;
                    }
                }
                char c = maxi + '0';
                // cout << s.substr(0,i-1) << " " <<  c << " " << s.substr(i,ind-i) << " " << s.substr(ind+1);
                // nl
                // cout << i  << " ";
                s = s.substr(0,i) + c + s.substr(i,ind-i) + s.substr(ind+1);
                // else s = c + s.substr(i,ind-i) + s.substr(ind+1);
                // cout << s << endl;
            }
        }
        cout << s;
        nl
    }	
    return 0;
}

Submission (verdict: Time limit exceeded on test 7):
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define int long long int
#define nl cout<<endl;
#define PB push_back
#define MP make_pair
#define f(a,b) for(int i = a; i < b; i++)
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
    int t=1;
    cin>>t;
    while(t--){
        string s;
        cin >> s;

        int n = s.length();

        int val1, val2, maxi, ind;
        f(0,n-1){
            if(s[i] < '8'){
                val1 = s[i] - '0';
                maxi = val1;
                ind = i;
                for(int j = i + 1; j <= min(i+8,n-1); j++){
                    val2 = s[j] - '0';
                    val2 -= (j - i);
                    if(val2 > maxi){
                        maxi = val2;
                        ind = j;
                    }
                    if(maxi == 9 - (j - i)) break;
                }
                char c = maxi + '0';
                s = s.substr(0,i) + c + s.substr(i,ind-i) + s.substr(ind+1);
            }
        }
        cout << s;
        nl
    }	
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 7):
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define int long long int
#define nl cout<<endl;
#define PB push_back
#define MP make_pair
#define f(a,b) for(int i = a; i < b; i++)
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
    int t=1;
    cin>>t;
    while(t--){
        string s;
        cin >> s;

        int n = s.length();

        int val1, val2, maxi, ind;
        f(0,n-1){
            if(s[i] < '8'){
                val1 = s[i] - '0';
                maxi = val1;
                ind = i;
                for(int j = i + 1; j <= min(i+10,n-1); j++){
                    val2 = s[j] - '0';
                    val2 -= (j - i);
                    if(val2 > maxi){
                        maxi = val2;
                        ind = j;
                    }
                }
                char c = maxi + '0';
                // cout << s.substr(0,i-1) << " " <<  c << " " << s.substr(i,ind-i) << " " << s.substr(ind+1);
                // nl
                // cout << i  << " ";
                s = s.substr(0,i) + c + s.substr(i,ind-i) + s.substr(ind+1);
                // else s = c + s.substr(i,ind-i) + s.substr(ind+1);
                // cout << s << endl;
            }
        }
        cout << s;
        nl
    }	
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
/*avro28*/

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#define ll long long

#define vl vector<ll>

#define pb push_back

#define ff first 

#define ss second

#define dout(x) cerr<<#x<<": "<<x<<"\n";

#define vout(x) cerr<<#x<<": "; \

for (auto &i:x){cerr<<i<<" ";} cerr<<"\n";

#define mout(x)cerr<<#x<<":\n"; \

for (auto &i:x){cerr<<i.ff<<" "<<i.ss<<"\n";}

using namespace std;

using namespace __gnu_pbds;

template<typename T> using oset = tree<T, null_type, 

less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll mod=1e9+7, inf=(1LL<<62), N=2e5+5;



// vl g[N], comp;

// bool vis[N];

// ll dp[N][505];



// void dfs(ll node){

//     if (vis[node]) return;

//     vis[node]=1;

//     for (auto &i:g[node]) dfs(i);

//     return;

// }



ll fun(ll id, ll n){

    return 0;

}



void solve(){

    ll n, l, r, sum=0; cin>>n>>l>>r;

    vl a(n);

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

        cin>>a[i];

    }

    sort(a.begin(), a.end());

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

        sum+=a[i];

    }

    cout<<sum<<"\n";

}

int main(){

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

    // freopen(".in", "r", stdin);

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

    ll T=1; 

    cin>>T;

    while (T--) solve();

}

Submission (verdict: Wrong answer on test 2):
/*avro28*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define vl vector<ll>
#define pb push_back
#define ff first 
#define ss second
#define dout(x) cerr<<#x<<": "<<x<<"\n";
#define vout(x) cerr<<#x<<": "; \
for (auto &i:x){cerr<<i<<" ";} cerr<<"\n";
#define mout(x)cerr<<#x<<":\n"; \
for (auto &i:x){cerr<<i.ff<<" "<<i.ss<<"\n";}
using namespace std;
using namespace __gnu_pbds;
template<typename T> using oset = tree<T, null_type, 
less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1e9+7, inf=(1LL<<62), N=2e5+5;

// vl g[N], comp;
// bool vis[N];
// ll dp[N][505];

// void dfs(ll node){
//     if (vis[node]) return;
//     vis[node]=1;
//     for (auto &i:g[node]) dfs(i);
//     return;
// }

ll fun(ll id, ll n){
    return 0;
}

void solve(){
    ll n, l, r, sum1=0, sum2=0, mx=-1; 
    cin>>n>>l>>r;
    l--, r--;
    vl a(n), b, c;
    for (ll i=0; i<n; i++){
        cin>>a[i];
    }
    for (ll i=l; i<=r; i++){
        mx=max(mx, a[i]);
    }
    for (ll i=0; i<l; i++){
        if (a[i]<mx) b.pb(a[i]);
    }
    for (ll i=n-1; i>r; i--){
        if (a[i]<mx) c.pb(a[i]);
    }
    sort(a.begin()+l, a.begin()+r+1);
    reverse(a.begin()+l, a.begin()+r+1);
    for (ll i=l; i<=r; i++){
        if (i-l<b.size() && b[i-l]<a[i]) sum1+=b[i-l];
        else sum1+=a[i];
    }
    for (ll i=l; i<=r; i++){
        if (i-l<c.size() && c[i-l]<a[i]) sum2+=c[i-l];
        else sum2+=a[i];
    }
    cout<<min(sum1, sum2)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    ll T=1; 
    cin>>T;
    while (T--) solve();
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
/*avro28*/

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#define ll long long

#define vl vector<ll>

#define pb push_back

#define ff first 

#define ss second

#define dout(x) cerr<<#x<<": "<<x<<"\n";

#define vout(x) cerr<<#x<<": "; \

for (auto &i:x){cerr<<i<<" ";} cerr<<"\n";

#define mout(x)cerr<<#x<<":\n"; \

for (auto &i:x){cerr<<i.ff<<" "<<i.ss<<"\n";}

using namespace std;

using namespace __gnu_pbds;

template<typename T> using oset = tree<T, null_type, 

less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll mod=1e9+7, inf=(1LL<<62), N=2e5+5;



// vl g[N], comp;

// bool vis[N];

// ll dp[N][505];



// void dfs(ll node){

//     if (vis[node]) return;

//     vis[node]=1;

//     for (auto &i:g[node]) dfs(i);

//     return;

// }



ll fun(ll id, ll n){

    return 0;

}



void solve(){

    ll n, l, r, sum=0; cin>>n>>l>>r;

    vl a(n);

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

        cin>>a[i];

    }

    sort(a.begin(), a.end());

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

        sum+=a[i];

    }

    cout<<sum<<"\n";

}

int main(){

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

    // freopen(".in", "r", stdin);

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

    ll T=1; 

    cin>>T;

    while (T--) solve();

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


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

int t;

void solve()
{
	string str;
	cin >> str;
	for(int i = str.size() - 1;i > 0;i--)
	{
	    if(str[i] > str[i - 1] + 1 && str[i - 1] != 0 )
	    {
	    	str[i]--;
	    	swap(str[i],str[i - 1]);
	    	for(int j = i;j < str.size() - 1;j++)
	    	{
	    		if(str[j + 1] > str[j] + 1 && str[j] != 0)
	    		{
	    			str[j + 1] --;
	    			swap(str[j + 1],str[j]);
				}
			}
		}
	}
	cout << str << endl; 
}

int main()
{
	cin >> t;
	while(t--) solve();
	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

int t;

void solve()
{
	string str;
	cin >> str;
	for(int i = str.size() - 1;i > 0;i--)
	{
	    if(str[i] > str[i - 1] + 1 && str[i - 1] != 0 )
	    {
	    	str[i]--;
	    	swap(str[i],str[i - 1]);
	    	for(int j = i;j < str.size() - 1;j++)
	    	{
	    		if(str[j + 1] > str[j] + 1 && str[j] != 0)
	    		{
	    			str[j + 1] --;
	    			swap(str[j + 1],str[j]);
				}
			}
		}
	}
	cout << str << endl; 
}

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

Submission (verdict: Time limit exceeded on test 4):
#include<iostream>
#include<algorithm>
using namespace std;

int t;
bool st[1005];

void solve()
{
	string str;
	cin >> str;
	for(int i = 0;i < str.size(); i++) st[i] = false;
	for(int i = str.size() - 1;i > 0;i--)
	{
	    if(str[i] > str[i - 1] + 1 && str[i - 1] != 0 )
	    {
	    	str[i]--;
	    	swap(str[i],str[i - 1]);
	    	st[i] = true;
	    	for(int j = i;j < str.size() - 1;j++)
	    	{
	    		if(str[j + 1] > str[j] + 1 && str[j] != 0)
	    		{
	    			str[j + 1] --;
					st[j + 1] = true; 
	    			swap(str[j + 1],str[j]);
				}
				else if(st[j]) break;
			}
		}
	}
	cout << str << endl; 
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> t;
	while(t--) solve();
	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

int t;
bool st[1005];

void solve()
{
	string str;
	cin >> str;
	for(int i = 0;i < str.size(); i++) st[i] = false;
	for(int i = str.size() - 1;i > 0;i--)
	{
	    if(str[i] > str[i - 1] + 1 && str[i - 1] != 0 )
	    {
	    	str[i]--;
	    	swap(str[i],str[i - 1]);
	    	st[i] = true;
	    	for(int j = i;j < str.size() - 1;j++)
	    	{
	    		if(str[j + 1] > str[j] + 1 && str[j] != 0)
	    		{
	    			str[j + 1] --;
					st[j + 1] = true; 
	    			swap(str[j + 1],str[j]);
				}
				else if(st[j]) break;
			}
		}
	}
	cout << str << endl; 
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> t;
	while(t--) solve();
	return 0;
}

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

int t;

void solve()
{
	string str;
	cin >> str;
	for(int i = str.size() - 1;i > 0;i--)
	{
	    if(str[i] > str[i - 1] + 1 && str[i - 1] != 0 )
	    {
	    	str[i]--;
	    	swap(str[i],str[i - 1]);
	    	for(int j = i;j < str.size() - 1;j++)
	    	{
	    		if(str[j + 1] > str[j] + 1 && str[j] != 0)
	    		{
	    			str[j + 1] --;
	    			swap(str[j + 1],str[j]);
				}
				else break;
			}
		}
	}
	cout << str << endl; 
}

int main()
{
	cin >> t;
	while(t--) solve();
	return 0;
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>

#include<cmath>

#include<algorithm>

#include<string>

#include<vector>

#include<map>

#include<set>

#include<functional>

#include<cstring>

using namespace std;

using ll = long long;

ll dp[1009][1009];

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	ll t;

	cin >> t;

	while (t--) {

		memset(dp, 0, sizeof(dp));//行a列b

		string a;

		string b;

		string target;

		ll p1 = a.size();

		ll p2 = b.size();

		dp[0][0] = 0;

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

			dp[i + 1][0] = dp[i][0] + (a[i] != target[i]);

		}

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

			dp[0][j + 1] = dp[0][j] + (b[j] != target[j]);

		}

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

				for (int j = 1; j <= p2; j++) {

					dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != target[i + j - 1]), dp[i][j - 1] + (b[j - 1] != target[i + j - 1]));

				}

			}

			cout << dp[p1][p2] << endl;

	}

	return 0;

}









Submission (verdict: Accepted):
#include<iostream>

#include<cmath>

#include<algorithm>

#include<string>

#include<vector>

#include<map>

#include<set>

#include<functional>

#include<cstring>

using namespace std;

using ll = long long;

ll dp[1009][1009];

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	ll t;

	cin >> t;

	while (t--) {

		memset(dp, 0, sizeof(dp));//行a列b

		string a;

		string b;

		string target;

		cin>>a>>b>>target;

		ll p1 = a.size();

		ll p2 = b.size();

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

			dp[i + 1][0] = dp[i][0] + (a[i] != target[i]);

		}

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

			dp[0][j + 1] = dp[0][j] + (b[j] != target[j]);

		}

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

				for (int j = 1; j <= p2; j++) {

					dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != target[i + j - 1]), dp[i][j - 1] + (b[j - 1] != target[i + j - 1]));

				}

			}

			cout << dp[p1][p2] << endl;

	}

	return 0;

}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Compilation error):
#include<iostream>

#include<cmath>

#include<algorithm>

#include<string>

#include<vector>

#include<map>

#include<set>

#include<functional>

using namespace std;

using ll = long long;

ll dp[1009][1009];

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	ll t;

	cin >> t;

	while (t--) {

		memset(dp, 0, sizeof(dp));//行a列b

		string a;

		string b;

		string target;

		ll p1 = a.size();

		ll p2 = b.size();

		dp[0][0] = 0;

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

			dp[i + 1][0] = dp[i][0] + (a[i] != target[i]);

		}

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

			dp[0][j + 1] = dp[0][j] + (b[j] != target[j]);

		}

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

				for (int j = 1; j <= p2; j++) {

					dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != target[i + j - 1]), dp[i][j - 1] + (b[j - 1] != target[i + j - 1]));

				}

			}

			cout << dp[p1][p2] << endl;

	}

	return 0;

}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Compilation error):
#include<iostream>

#include<cmath>

#include<algorithm>

#include<string>

#include<vector>

#include<map>

#include<set>

#include<functional>

using namespace std;

using ll = long long;

ll dp[1009][1009];

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	ll t;

	cin >> t;

	while (t--) {

		memset(dp, 0, sizeof(dp));//行a列b

		string a;

		string b;

		string target;

		ll p1 = a.size();

		ll p2 = b.size();

		dp[0][0] = 0;

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

			dp[i + 1][0] = dp[i][0] + (a[i] != target[i]);

		}

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

			dp[0][j + 1] = dp[0][j] + (b[j] != target[j]);

		}

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

				for (int j = 1; j <= p2; j++) {

					dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != target[i + j - 1]), dp[i][j - 1] + (b[j - 1] != target[i + j - 1]));

				}

			}

			cout << dp[p1][p2] << endl;

	}

	return 0;

}





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

#include<cmath>

#include<algorithm>

#include<string>

#include<vector>

#include<map>

#include<set>

#include<functional>

#include<cstring>

using namespace std;

using ll = long long;

ll dp[1009][1009];

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	ll t;

	cin >> t;

	while (t--) {

		memset(dp, 0, sizeof(dp));//行a列b

		string a;

		string b;

		string target;

		ll p1 = a.size();

		ll p2 = b.size();

		dp[0][0] = 0;

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

			dp[i + 1][0] = dp[i][0] + (a[i] != target[i]);

		}

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

			dp[0][j + 1] = dp[0][j] + (b[j] != target[j]);

		}

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

				for (int j = 1; j <= p2; j++) {

					dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != target[i + j - 1]), dp[i][j - 1] + (b[j - 1] != target[i + j - 1]));

				}

			}

			cout << dp[p1][p2] << endl;

	}

	return 0;

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


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


void solve(){
    string s; cin >> s;
    int n = s.length();
    s = '$' + s;
    for(int i = 1; i <= n; i++){
        pair<int, int>mx = {0, 0};
        for(int j = i; j <= min(n, 9LL); j++){
            if(mx.first < s[j] - (j - i) )mx = { s[j] - (j - i), j};
        }
        if(mx.second != i){
            for(int j = mx.second; j > i; j--) s[j]--, swap(s[j], s[j-1]);
        }
    }
    for(int i = 1; i <= n; i++) cout << s[i];
    cout << '\n';
}
 
signed main(){
    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++17 (GCC 7-32)

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


void solve(){
    string s; cin >> s;
    int n = s.length();
    s = '$' + s;
    for(int i = 1; i <= n; i++){
        pair<char, int>mx = {0, 0};
        for(int j = i; j <= min(n, 9LL); j++){
            if(mx.first < s[j] - (j - i)) mx = { s[j] - (j - i), j};
        }
        if(mx.second != i){
            for(int j = mx.second; j > i; j--) s[j]--, swap(s[j], s[j-1]);
        }
    }
    for(int i = 1; i <= n; i++) cout << s[i];
    cout << '\n';
}
 
signed main(){
    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;
 
#define ll long long
#define int ll


void solve(){
    string s; cin >> s;
    int n = s.length();
    s = '$' + s;
    for(int i = 1; i <= n; i++){
        pair<char, int>mx = {0, 0};
        for(int j = i; j <= min(n, i + 9LL); j++){
            if(mx.first < s[j] - (j - i)) mx = { s[j] - (j - i), j};
        }
        if(mx.second != i){
            for(int j = mx.second; j > i; j--) s[j]--, swap(s[j], s[j-1]);
        }
    }
    for(int i = 1; i <= n; i++) cout << s[i];
    cout << '\n';
}
 
signed main(){
    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++17 (GCC 7-32)

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


void solve(){
    string s; cin >> s;
    int n = s.length();
    s = '$' + s;
    for(int i = 1; i <= n; i++){
        pair<int, int>mx = {0, 0};
        for(int j = i; j <= min(n, 9LL); j++){
            if(mx.first < s[j] - (j - i) )mx = { s[j] - (j - i), j};
        }
        if(mx.second != i){
            for(int j = mx.second; j > i; j--) s[j]--, swap(s[j], s[j-1]);
        }
    }
    for(int i = 1; i <= n; i++) cout << s[i];
    cout << '\n';
}
 
signed main(){
    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;
 
#define ll long long
#define int ll


void solve(){
    string s; cin >> s;
    int n = s.length();
    s = '$' + s;
    for(int i = 1; i <= n; i++){
        pair<char, int>mx = {0, 0};
        for(int j = i; j <= min(n, 9LL); j++){
            if(mx.first < s[j] - (j - i)) mx = { s[j] - (j - i), j};
        }
        if(mx.second != i){
            for(int j = mx.second; j > i; j--) s[j]--, swap(s[j], s[j-1]);
        }
    }
    for(int i = 1; i <= n; i++) cout << s[i];
    cout << '\n';
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t; cin >> t;
    while(t--)
    solve();
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

void solve() {
    ll num;
    cin>>num;
    string n = to_string(num);
    int twos = 0, threes = 0;
    for(auto i: n){
        if(i=='2') twos++;
        else if (i=='3') threes++;
    }
    ll sum = 0;
    while(num>=10){
        ll digit = num%10;
        num = num/10;
        sum += digit;
    }
    sum += num;

    for (int i = 0; i <= min(twos, 8); ++i){
        for (int j = 0; j <= min(threes, 8); ++j){
            if((sum*1LL + 2*i + 6*j)%9==0){
                cout<<"yes"<<nl;
                return;
            }
        }
    }
    cout<<"no"<<nl;
}

int main() {
#ifdef LOCAL
    freopen("error.txt", "w", stderr);
#endif
    fastio();
    auto start1 = high_resolution_clock::now();
    int TC = 1;
    cin >> TC;
    while(TC--)
        solve();
    auto stop1 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop1 - start1);
#ifdef LOCAL
    cerr << "Time: " << duration . count() / 1000 << endl;
#endif
}

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

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

void solve() {
    string n;
    cin >> n;

    ll sum = 0;
    int twos = 0, threes = 0;
    for (char c : n) {
        int digit = c - '0';
        sum += digit;
        if (digit == 2) twos++;
        else if (digit == 3) threes++;
    }

    for (int i = 0; i < min(10, twos + 1); ++i) {
        for (int j = 0; j < min(10, threes + 1); ++j) {
            if ((sum + 2 * i + 6 * j) % 9 == 0) {
                cout << "YES" << nl;
                return;
            }
        }
    }

    cout << "NO" << nl;
}

int main() {
#ifdef LOCAL
    freopen("error.txt", "w", stderr);
#endif
    fastio();
    auto start1 = high_resolution_clock::now();
    int TC = 1;
    cin >> TC;
    while(TC--)
        solve();
    auto stop1 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop1 - start1);
#ifdef LOCAL
    cerr << "Time: " << duration . count() / 1000 << endl;
#endif
}