ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define int long long

using namespace std;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

void solve() {
    int n;
    cin >> n;
    int c[n + 1];
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    vector <pii> ans;
    int pos[n + 1];
    int p[n + 1];
    for(int i = 1; i <= n; i++) {
        pos[i] = i;
        p[i] = i;
    }
    for(int i = 1; i <= n; i++) {
        int x = pos[c[i]];
        for(int j = x + 1; j <= n - i + 1; j++) {
            ans.pb({p[j], c[i]});
            swap(p[j], p[j - 1]);
            x++;
        }
        for(int j = n - i; j >= 1; j--) {
            ans.pb({c[i], p[j]});
            swap(p[j], p[j + 1]);
        }
        for(int j = 1; j <= n - i; j++) {
            swap(p[j], p[j + 1]);
        }
    }
    cout << ans.size() << "\n";
    for(auto [x, y] : ans)
        cout << x << " " << y << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef STRIKAZA
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // STRIKAZA
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define int long long

using namespace std;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

void solve() {
    int n;
    cin >> n;
    int c[n + 1];
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    vector <pii> ans;
    int pos[n + 1];
    int p[n + 1];
    for(int i = 1; i <= n; i++) {
        pos[i] = i;
        p[i] = i;
    }
    for(int i = 1; i <= n; i++) {
        int x = pos[c[i]];
        for(int j = x + 1; j <= n - i + 1; j++) {
            ans.pb({p[j], c[i]});
            swap(p[j], p[j - 1]);
            swap(pos[p[j]], pos[p[j - 1]]);
            x++;
        }
        for(int j = n - i; j >= 1; j--) {
            ans.pb({c[i], p[j]});
            swap(p[j], p[j + 1]);
            swap(pos[p[j]], pos[p[j + 1]]);
        }
        for(int j = 1; j <= n - i; j++) {
            swap(p[j], p[j + 1]);
            swap(pos[p[j]], pos[p[j + 1]]);
        }
    }
    cout << ans.size() << "\n";
    for(auto [x, y] : ans)
        cout << x << " " << y << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef STRIKAZA
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // STRIKAZA
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


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

using ll=long long;
#define int ll
const int MOD=1e9+7,MAXX=-1e18,MINN=1e18;
#define db(t) cout << #t << "=" << t << "\n";
#define affiche(t) cout << #t << " : "; for (auto x:t) cout << x << " " ; cout << "\n";
#define ff first 
#define ss second
int count(vector <int> &a,int n)
{
    if(n==1)
        return a[0];
    int res=accumulate(a.begin(),a.end(),0);
    vector <int> b(n-1),c(n-1);
    for(int i=0;i<n-1;i++)
    {
        b[i]=a[i+1]-a[i];
        c[i]=a[n-i-2]-a[n-i-1];
    }
    return max(res,max(count(b,n-1),count(c,n-1)));
}
void solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &i:a)
        cin>>i;
    cout<<count(a,n)<<endl;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
        solve();
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

using ll=long long;
#define int ll
const int MOD=1e9+7,MAXX=-1e18,MINN=1e18;
#define db(t) cout << #t << "=" << t << "\n";
#define affiche(t) cout << #t << " : "; for (auto x:t) cout << x << " " ; cout << "\n";
#define ff first 
#define ss second
int count(vector <int> &a,int n,int x)
{
    if(n==1)
        return a[0];
    vector <int> b(n-1),c(n-1);
    for(int i=0;i<n-1;i++)
    {
        b[i]=a[i+1]-a[i];
        c[i]=a[n-i-2]-a[n-i-1];
    }
    return max(x,max(count(b,n-1,b[n-2]-b[0]),count(c,n-1,c[n-2]-c[0])));
}
void solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &i:a)
        cin>>i;
    int res=accumulate(a.begin(),a.end(),0);
    cout<<count(a,n,res)<<endl;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
        solve();
}

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

using ll=long long;
#define int ll
const int MOD=1e9+7,MAXX=-1e18,MINN=1e18;
#define db(t) cout << #t << "=" << t << "\n";
#define affiche(t) cout << #t << " : "; for (auto x:t) cout << x << " " ; cout << "\n";
#define ff first 
#define ss second
int count(vector <int> &a,int n,int x)
{
    if(n==1)
        return a[0];
    vector <int> b(n-1);
    for(int i=0;i<n-1;i++)
        b[i]=a[i+1]-a[i];
    return max(x,count(b,n-1,abs(b[n-2]-b[0])));
}
void solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &i:a)
        cin>>i;
    vector <int > b=a;
	reverse(b.begin(),b.end());
    int res=accumulate(a.begin(),a.end(),0);
    cout<<max(count(a,n,res),count(b,n,res))<<endl;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
        solve();
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

using ll=long long;
#define int ll
const int MOD=1e9+7,MAXX=-1e18,MINN=1e18;
#define db(t) cout << #t << "=" << t << "\n";
#define affiche(t) cout << #t << " : "; for (auto x:t) cout << x << " " ; cout << "\n";
#define ff first 
#define ss second
int count(vector <int> &a,int n,int x)
{
    if(n==1)
        return a[0];
    vector <int> b(n-1);
    for(int i=0;i<n-1;i++)
        b[i]=a[i+1]-a[i];
    return max(x,count(b,n-1,abs(b[n-2]-b[0])));
}
void solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &i:a)
        cin>>i;
    vector <int > b=a;
	reverse(b.begin(),b.end());
    int res=accumulate(a.begin(),a.end(),0);
    cout<<max(count(a,n,res),count(b,n,res))<<endl;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
        solve();
}

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

using ll=long long;
#define int ll
const int MOD=1e9+7,MAXX=-1e18,MINN=1e18;
#define db(t) cout << #t << "=" << t << "\n";
#define affiche(t) cout << #t << " : "; for (auto x:t) cout << x << " " ; cout << "\n";
#define ff first 
#define ss second
int count(vector <int> &a,int n,int x)
{
    if(n==1)
        return max(x,a[0]);
    vector <int> b(n-1);
    for(int i=0;i<n-1;i++)
        b[i]=a[i+1]-a[i];
    return max(x,count(b,n-1,abs(a[n-1]-a[0])));
}
void solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &i:a)
        cin>>i;
    vector <int > b=a;
	reverse(b.begin(),b.end());
    int res=accumulate(a.begin(),a.end(),0);
    cout<<max(count(a,n,res),count(b,n,res))<<endl;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
        solve();
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

using ll=long long;
#define int ll
const int MOD=1e9+7,MAXX=-1e18,MINN=1e18;
#define db(t) cout << #t << "=" << t << "\n";
#define affiche(t) cout << #t << " : "; for (auto x:t) cout << x << " " ; cout << "\n";
#define ff first 
#define ss second
int count(vector <int> &a,int n)
{
    if(n==1)
        return a[0];
    int res=accumulate(a.begin(),a.end(),0);
    vector <int> b(n-1),c(n-1);
    for(int i=0;i<n-1;i++)
    {
        b[i]=a[i+1]-a[i];
        c[i]=a[n-i-2]-a[n-i-1];
    }
    return max(res,max(count(b,n-1),count(c,n-1)));
}
void solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &i:a)
        cin>>i;
    cout<<count(a,n)<<endl;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
        solve();
}

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

using ll=long long;
#define int ll
const int MOD=1e9+7,MAXX=-1e18,MINN=1e18;
#define db(t) cout << #t << "=" << t << "\n";
#define affiche(t) cout << #t << " : "; for (auto x:t) cout << x << " " ; cout << "\n";
#define ff first 
#define ss second
int count(vector <int> &a,int n,int x)
{
    if(n==1)
        return a[0];
    vector <int> b(n-1),c(n-1);
    for(int i=0;i<n-1;i++)
    {
        b[i]=a[i+1]-a[i];
        c[i]=a[n-i-2]-a[n-i-1];
    }
    return max(x,max(count(b,n-1,b[n-2]-b[0]),count(c,n-1,c[n-2]-c[0])));
}
void solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &i:a)
        cin>>i;
    int res=accumulate(a.begin(),a.end(),0);
    cout<<count(a,n,res)<<endl;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
        solve();
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

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

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n,k,res;
        cin >> n >> k;
        vector<int> v(n);
        res =1;

        for (int i=0;i<n;cin >> v[i],i++)

        sort(v.begin(),v.end());
        vector<int> cnt = {1};
        for (int i=1;i<n;i++)
        {
            if (v[i]!=v[i-1])
            cnt.push_back(1);
            else
            cnt.back()++;
        }
        sort(cnt.begin(),cnt.end());
        int s=cnt.size();
        for (int i=0;i<s-1;i++)
        {
            if (cnt[i]>k)
            res = s-i;
            else
            k-=cnt[i];
        }
        cout << res << "\n";
    }
}

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

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n,k,res;
        cin >> n >> k;
        vector<int> v(n);
        res =1;

        for (int i=0;i<n;i++)
        {
            cin >> v[i];
        }

        sort(v.begin(),v.end());
        vector<int> cnt = {1};
        for (int i=1;i<n;i++)
        {
            if (v[i]!=v[i-1])
            cnt.push_back(1);
            else
            cnt.back()++;
        }
        sort(cnt.begin(),cnt.end());
        int s=cnt.size();
        for (int i=0;i<s;i++)
        {
            if (cnt[i]>k)
            {   
                res = s-i;
                break;
            }
            else
            k-=cnt[i];
        }
        cout << res << "\n";
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


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

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n,k;
        cin >> n >> k;
        map<int,int> m;
        vector<int> v;

        for (int i=0;i<n;i++)
        {
            int x;
            cin >> x;
            m[x]++;
        }
        for (int i=0;i<m.size();i++)
        {
            v.push_back(m[i]);
        }

        sort(v.rbegin(),v.rend());

        for (int i=v.size()-1;i>=0;i--)
        {
            if (v[i]<=k)
            {
                k-=v[i];
                v.pop_back();
            }
            else
            break;
        }
        int x = v.size();
        cout << max(x,1) << "\n";

    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Memory limit exceeded on test 4):
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n,k;
        cin >> n >> k;
        map<int,int> m;
        vector<int> v;

        for (int i=0;i<n;i++)
        {
            int x;
            cin >> x;
            m[x]++;
        }
        for (int i=0;i<m.size();i++)
        {
            v.push_back(m[i]);
        }

        sort(v.rbegin(),v.rend());

        for (int i=v.size()-1;i>=0;i--)
        {
            if (v[i]<=k)
            {
                k-=v[i];
                v.pop_back();
            }
            else
            break;
        }
        int x = v.size();
        cout << max(x,1) << "\n";

    }
}

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

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n,k,res;
        cin >> n >> k;
        vector<int> v(n);
        res =1;

        for (int i=0;i<n;cin >> v[i],i++)

        sort(v.begin(),v.end());
        vector<int> cnt = {1};
        for (int i=1;i<n;i++)
        {
            if (v[i]!=v[i-1])
            cnt.push_back(1);
            else
            cnt.back()++;
        }
        sort(cnt.begin(),cnt.end());
        int s=cnt.size();
        for (int i=0;i<s-1;i++)
        {
            if (cnt[i]>k)
            res = s-i;
            else
            k-=cnt[i];
        }
        cout << res << "\n";
    }
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        long n,l,r,s1,s2;
        s1=s2=0;
        cin >> n >> l >> r;
        vector<long> a(n),a1,a2;
        for (int i=0;i<n;i++)
        cin >> a[i];
        for (int i=0;i<r;i++)
        a1.push_back(a[i]);
        for (int i=l-1;i<n;i++)
        a2.push_back(a[i]);

        sort(a1.begin(),a1.end());
        sort(a2.begin(),a2.end());

        for (int i=0;i<r-l+1;i++)
        s1+=a1[i];
        for (int i=0;i<r-l+1;i++)
        s2+=a2[i];

        s1 = min(s1,s2);
        cout << s1 << "\n";
    }
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        long n,l,r,s1,s2;
        s1=s2=0;
        cin >> n >> l >> r;
        vector<long> a(n),a1,a2;
        for (int i=0;i<n;i++)
        cin >> a[i];
        for (int i=0;i<r;i++)
        a1.push_back(a[i]);
        for (int i=l-1;i<n;i++)
        a2.push_back(a[i]);

        sort(a1.begin(),a1.end());
        sort(a2.begin(),a2.end());

        for (int i=0;i<r-l+1;i++)
        s1+=a1[i];
        for (int i=0;i<r-l+1;i++)
        s2+=a2[i];

        s1 = min(s1,s2);
        cout << s1 << "\n";
    }
}

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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        long long n,l,r,s1,s2;
        s1=s2=0;
        cin >> n >> l >> r;
        vector<long long> a(n),a1,a2;
        for (int i=0;i<n;i++)
        cin >> a[i];
        for (int i=0;i<r;i++)
        a1.push_back(a[i]);
        for (int i=l-1;i<n;i++)
        a2.push_back(a[i]);

        sort(a1.begin(),a1.end());
        sort(a2.begin(),a2.end());

        for (int i=0;i<r-l+1;i++)
        s1+=a1[i];
        for (int i=0;i<r-l+1;i++)
        s2+=a2[i];

        s1 = min(s1,s2);
        cout << s1 << "\n";
    }
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        long n,l,r,s1,s2;
        s1=s2=0;
        cin >> n >> l >> r;
        vector<long> a(n),a1,a2;
        for (int i=0;i<n;i++)
        cin >> a[i];
        for (int i=0;i<r;i++)
        a1.push_back(a[i]);
        for (int i=l-1;i<n;i++)
        a2.push_back(a[i]);

        sort(a1.begin(),a1.end());
        sort(a2.begin(),a2.end());

        for (int i=0;i<r-l+1;i++)
        s1+=a1[i];
        for (int i=0;i<r-l+1;i++)
        s2+=a2[i];

        s1 = min(s1,s2);
        cout << s1 << "\n";
    }
}

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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        long n,l,r,s1,s2;
        s1=s2=0;
        cin >> n >> l >> r;
        vector<long> a(n),a1,a2;
        for (int i=0;i<n;i++)
        cin >> a[i];
        for (int i=0;i<r;i++)
        a1.push_back(a[i]);
        for (int i=l-1;i<n;i++)
        a2.push_back(a[i]);

        sort(a1.begin(),a1.end());
        sort(a2.begin(),a2.end());

        for (int i=0;i<r-l+1;i++)
        s1+=a1[i];
        for (int i=0;i<r-l+1;i++)
        s2+=a2[i];

        s1 = min(s1,s2);
        cout << s1 << "\n";
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>



#define ll long long

#define scn(v) for(auto &i:v)cin>>i
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vl vector<ll>
#define vi vector<int>
#define vvi vector<vi>
#define vvl vector<vl>
#define vb vector<bool>
#define vvb vector<vb>
#define en cout<<'\n'
#define vb vector<bool>
#define vpl vector<pair<ll,ll>>
#define vi vector<int>
#define X first
#define Y second

const int MOD = 998244353;
ll mul(ll a, ll b) {
    return (((a % MOD + MOD) * (b % MOD + MOD)) % MOD);
}
ll fastPow(ll x, ll n, ll m) {
    if (n == 0) {
        return 1;
    }
    ll po = fastPow(x, n / 2, m);
    po =mul(po,po) % m;
    if (n & 1) {
        po =mul(po,x) %m;
    }
    return po % m;
}

ll modInv(ll x, ll m) {
    return fastPow(x, m - 2, m) % m;
}

ll setBit(ll num, ll idx, ll val = 1) {
    return (val) ? (num | (1 << idx)) : (num & ~(1 << idx));
}
int getBit(ll num, int idx) { return ((num >> idx) & 1) == 1; }

void burnx(){
     ll n;
     cin>>n;
     vvl adj(n+1);
     vl deg(n+1);
     for(int i=1;i<n;i++){
         ll u,v;
         cin>>u>>v;
         adj[u].push_back(v);
         adj[v].push_back(u);
         deg[u]++;
         deg[v]++;
     }
     if(n<=2){
         cout<<"0";
         return;
     }
     ll ans=0;
     ll cnt=1;

     for(int z=0;z<2;z++){
         ll mx=0;
         ll mxi=-1;
         for(int i=1;i<=n;i++){
             if(deg[i]>mx){
                 mxi=i;
                 mx=deg[i];
             }
         }
         if(mx==0){
             cnt--;
             continue;
         }
         if(mx==1){
             continue;
         }
         cnt+=deg[mxi]-1;
         deg[mxi]=0;
         for(auto v:adj[mxi]){
             deg[v]--;
         }
     }

     cout<<cnt;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cin.tie(NULL);
//  freopen ("input.txt","r",stdin);
//   freopen ("output.txt","w",stdout);
    //preFact();
    int t = 1;
    cin >> t;

    for(int txt=1;txt<=t;txt++){
        burnx();
        en;
    }

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


Submission (verdict: Runtime error on test 2):
#include<bits/stdc++.h>
using namespace std;
int main(){

    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int count0=0;
        for(int i=0;i<s.length();i++){
            if(s[i]=='0'){
                count0++;
            }
        }
        string res="";
        while(s.size()>count0){
            int m=0;
            int idx=-1;
            for(int i=0;i<s.size();i++){
                if(s[i]!='0'){
                    if(m<(s[i]-'0')-i){
                        m=(s[i]-'0')-i;
                        idx=i;
                    }
                }
            }
            res+=to_string(m);
            s.erase(idx,1);
        }
        while(count0--){
            res+='0';
        }
        cout<<res<<endl;
    }

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

Previous submission (verdict: Runtime error on test 2):
#include<bits/stdc++.h>
using namespace std;
int main(){

    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int count0=0;
        for(int i=0;i<s.length();i++){
            if(s[i]=='0'){
                count0++;
            }
        }
        string res="";
        while(s.size()>count0){
            int m=0;
            int idx=-1;
            for(int i=0;i<s.size();i++){
                if(s[i]!='0'){
                    if(m<(s[i]-'0')-i){
                        m=(s[i]-'0')-i;
                        idx=i;
                    }
                }
            }
            res+=to_string(m);
            s.erase(idx,1);
        }
        while(count0--){
            res+='0';
        }
        cout<<res<<endl;
    }

    return 0;
}

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

    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        string res="";
        while(s.size()>0){
            int m=-1;
            int idx=-1;
            for(int i=0;i<s.size();i++){
                if(m<(s[i]-'0')-i){
                    m=(s[i]-'0')-i;
                    idx=i;
                }
            }
            res+=to_string(m);
            s.erase(idx,1);
        }
        cout<<res<<endl;
    }

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

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
int main(){

    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        string res="";
        while(s.size()>0){
            int m=-1;
            int idx=-1;
            for(int i=0;i<s.size();i++){
                if(m<(s[i]-'0')-i){
                    m=(s[i]-'0')-i;
                    idx=i;
                }
            }
            res+=to_string(m);
            s.erase(idx,1);
        }
        cout<<res<<endl;
    }

    return 0;
}

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

    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        string res="";
        while(s.size()>0){
            int m=-1;
            int idx=-1;
            for(int i=0;i<9&&i<s.size();i++){
                if(m<(s[i]-'0')-i){
                    m=(s[i]-'0')-i;
                    idx=i;
                }
            }
            res+=to_string(m);
            s.erase(idx,1);
        }
        cout<<res<<endl;
    }

    return 0;
}