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


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define endl '\n'
#define yn(ans) cout << (ans ? "YES\n" : "NO\n")
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
const int MOD = 1000000007;
const int N = 200000;
const int inf = INT_MAX;
template <typename S>ostream& operator<<(ostream& os,const vector<S>& vector) {for (auto element : vector) {os << element << " ";} return os;}
template <typename S>istream& operator>>(istream& is, vector<S>& vec) {for (auto& element : vec) {is >> element;}return is;}
template <typename T1, typename T2>ostream& operator<<(ostream& os, const pair<T1, T2>& p) {os << "{" << p.first << ", " << p.second << "}";return os;}

void solve(){
    int n;
    cin >> n;
    vi arr(n);
    cin >> arr;

    vector<pii> final_pos(n);
    fo(i,n) final_pos[arr[i] -1] = {arr[i],i};

    vector<pii> ans;
    fo(i,n) {
        bool swapped = false;
        fo(j,n - i - 1) {
            if (final_pos[j].second > final_pos[j + 1].second) {
                swap(final_pos[j], final_pos[j + 1]);
                swapped = true;
                ans.push_back(make_pair(final_pos[j].first, final_pos[j + 1].first));
            }else{
                ans.push_back(make_pair(final_pos[j + 1].first,final_pos[j].first));
                ans.push_back(make_pair(final_pos[j].first, final_pos[j + 1].first));
            }
        }
        if (!swapped) break;
    }

    cout << ans.size() << endl;
    if (ans.size() > 0){
        fo(i,ans.size()){
            cout << ans[i].first << ' ' << ans[i].second << endl;
        }
    }
}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Memory limit exceeded on test 4):
#include <iostream>
#include <vector>
using namespace std;
#define int long long int

int solve(vector<vector<int> > &dp, string &s, int i, int sum) {
    if (sum % 9 == 0) {
        return 1;
    }
    if (i == s.size()) {
        return 0;
    }
    if (dp[i][sum] != -1) { 
        return dp[i][sum];
    }

    int x = s[i] - '0';
    int ans = 0;
    if ((x * x) <= 9) {
        ans = solve(dp, s, i + 1, sum - x + (x * x));
        if (ans == 1) {
            return dp[i][sum] = 1;
        }
    }
    ans = solve(dp, s, i + 1, sum);
    return dp[i][sum] = ans;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        string s1;
        cin >> s1;
        int n;
        n = s1.size();
        string s = s1;
        int sum = 0;
        for (char c : s) {
            sum += c - '0';
        }
        if (sum % 9 == 0) {
            cout << "YES" << endl;
            continue;
        }
        int maxSum = 9 * s.size(); 
        vector<vector<int> > dp(s.size() + 1, vector<int>(maxSum + 1, -1));
        int ans = solve(dp, s, 0, sum);
        if (ans) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


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

bool solve(string &s, int sum) {
    int n = s.size();
    vector<vector<bool> > dp(n + 1, vector<bool>(9, false));
    dp[0][sum % 9] = true;
    for (int i = 0; i < n; ++i) {
        int x = s[i] - '0';
        for (int mod = 0; mod < 9; ++mod) {
            if (!dp[i][mod]) continue;
            dp[i + 1][mod] = true;
            if (x * x <= 9) {
                int newMod = (mod - x + x * x + 9) % 9;
                dp[i + 1][newMod] = true;
            }
        }
    }
    return dp[n][0];
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        int sum = 0;
        for (char c : s) {
            sum += c - '0';
        }
        if (sum % 9 == 0 || solve(s, sum)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <vector>
#include <algorithm>
#define mod(x) (x > 0 ? x : (-1) * x)
using namespace std;
#define int long long int

int solve(vector<vector<int> > &dp, string s, int i, int sum) {
    if (dp[i][sum] != -1) {
        return dp[i][sum];
    }
    if (i == s.size()) {
        return 0;
    }
    int x = s[i] - '0';
    int ans = 0;
    if ((x * x) <= 9) {
        if ((sum - x + (x * x)) % 9 == 0) {
            return dp[i][sum] = 1;
        }
        ans = max(ans, solve(dp, s, i + 1, sum - x + (x * x)));
    }
    ans = max(ans, solve(dp, s, i + 1, sum));
    return dp[i][sum] = ans;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        string s = to_string(n);
        int sum = 0;
        for (int i = 0; i < s.size(); i++) {
            sum += s[i] - '0';
        }
        if (sum % 9 == 0) {
            cout << "YES" << endl;
            continue;
        }
        int maxSum = 9 * s.size(); 
        vector<vector<int> > dp(s.size() + 1, vector<int>(maxSum + 1, -1));
        int ans = solve(dp, s, 0, sum);
        if (ans) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <vector>
using namespace std;
#define int long long int

int solve(vector<vector<int> > &dp, string &s, int i, int sum) {
    if (sum % 9 == 0) {
        return 1;
    }
    if (i == s.size()) {
        return 0;
    }
    if (dp[i][sum] != -1) { 
        return dp[i][sum];
    }

    int x = s[i] - '0';
    int ans = 0;
    if ((x * x) <= 9) {
        ans = solve(dp, s, i + 1, sum - x + (x * x));
        if (ans == 1) {
            return dp[i][sum] = 1;
        }
    }
    ans = solve(dp, s, i + 1, sum);
    return dp[i][sum] = ans;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        string s = to_string(n);
        int sum = 0;
        for (char c : s) {
            sum += c - '0';
        }
        if (sum % 9 == 0) {
            cout << "YES" << endl;
            continue;
        }
        int maxSum = 9 * s.size(); 
        vector<vector<int> > dp(s.size() + 1, vector<int>(maxSum + 1, -1));
        int ans = solve(dp, s, 0, sum);
        if (ans) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


Submission (verdict: Memory limit exceeded on test 4):
#include <iostream>
#include <vector>
using namespace std;
#define int long long int

int solve(vector<vector<int> > &dp, string &s, int i, int sum) {
    if (sum % 9 == 0) {
        return 1;
    }
    if (i == s.size()) {
        return 0;
    }
    if (dp[i][sum] != -1) { 
        return dp[i][sum];
    }

    int x = s[i] - '0';
    int ans = 0;
    if ((x * x) <= 9) {
        ans = solve(dp, s, i + 1, sum - x + (x * x));
        if (ans == 1) {
            return dp[i][sum] = 1;
        }
    }
    ans = solve(dp, s, i + 1, sum);
    return dp[i][sum] = ans;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        string s1;
        cin >> s1;
        int n;
        n = s1.size();
        string s = s1;
        int sum = 0;
        for (char c : s) {
            sum += c - '0';
        }
        if (sum % 9 == 0) {
            cout << "YES" << endl;
            continue;
        }
        int maxSum = 9 * s.size(); 
        vector<vector<int> > dp(s.size() + 1, vector<int>(maxSum + 1, -1));
        int ans = solve(dp, s, 0, sum);
        if (ans) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <vector>
#include <algorithm>
#define mod(x) (x > 0 ? x : (-1) * x)
using namespace std;
#define int long long int

int solve(vector<vector<int> > &dp, string s, int i, int sum) {
    if (dp[i][sum] != -1) {
        return dp[i][sum];
    }
    if (i == s.size()) {
        return 0;
    }
    int x = s[i] - '0';
    int ans = 0;
    if ((x * x) <= 9) {
        if ((sum - x + (x * x)) % 9 == 0) {
            return dp[i][sum] = 1;
        }
        ans = max(ans, solve(dp, s, i + 1, sum - x + (x * x)));
    }
    ans = max(ans, solve(dp, s, i + 1, sum));
    return dp[i][sum] = ans;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        string s = to_string(n);
        int sum = 0;
        for (int i = 0; i < s.size(); i++) {
            sum += s[i] - '0';
        }
        if (sum % 9 == 0) {
            cout << "YES" << endl;
            continue;
        }
        int maxSum = 9 * s.size(); 
        vector<vector<int> > dp(s.size() + 1, vector<int>(maxSum + 1, -1));
        int ans = solve(dp, s, 0, sum);
        if (ans) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


Submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <vector>
using namespace std;
#define int long long int

int solve(vector<vector<int> > &dp, string &s, int i, int sum) {
    if (sum % 9 == 0) {
        return 1;
    }
    if (i == s.size()) {
        return 0;
    }
    if (dp[i][sum] != -1) { 
        return dp[i][sum];
    }

    int x = s[i] - '0';
    int ans = 0;
    if ((x * x) <= 9) {
        ans = solve(dp, s, i + 1, sum - x + (x * x));
        if (ans == 1) {
            return dp[i][sum] = 1;
        }
    }
    ans = solve(dp, s, i + 1, sum);
    return dp[i][sum] = ans;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        string s = to_string(n);
        int sum = 0;
        for (char c : s) {
            sum += c - '0';
        }
        if (sum % 9 == 0) {
            cout << "YES" << endl;
            continue;
        }
        int maxSum = 9 * s.size(); 
        vector<vector<int> > dp(s.size() + 1, vector<int>(maxSum + 1, -1));
        int ans = solve(dp, s, 0, sum);
        if (ans) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fl(i,n) for(ll i=0; i<n; i++)

ll cute(vector<ll> a){
    ll s=0,n=a.size();
    if (n==1) return a[0];
    else{
        fl(i,n) s+=a[i];
        vector<ll> v(n-1);
        fl(i,n-1) v[i]=a[i+1]-a[i];
        return (max(s,abs(cute(v))));
    }
}

void solve(){
    ll n; cin >> n;
    vector<ll> a(n);
    fl(i,n) cin >> a[i];
    cout << cute(a) << '\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll tt; cin >> tt;
    while(tt--) solve();
}
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
#define fl(i,n) for(ll i=0; i<n; i++)

ll cute(vector<ll> a){
    ll s=0,n=a.size();
    if (n==1) return a[0];
    else{
        fl(i,n) s+=a[i];
        vector<ll> v(n-1);
        fl(i,n-1) v[i]=a[i+1]-a[i];
        return (max(s,abs(cute(v))));
    }
}

void solve(){
    ll n; cin >> n;
    vector<ll> a(n);
    fl(i,n) cin >> a[i];
    cout << cute(a) << '\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll tt; cin >> tt;
    while(tt--) solve();
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fl(i,n) for(ll i=0; i<n; i++)

ll cute(vector<ll> a){
    ll s=0,n=a.size();
    if (n==1) return a[0];
    else{
        fl(i,n) s+=a[i];
        vector<ll> v(n-1);
        fl(i,n-1) v[i]=a[i+1]-a[i];
        ll sum=cute(v);
        return (max(s,max(sum,-sum)));
    }
}

void solve(){
    ll n; cin >> n;
    vector<ll> a(n);
    fl(i,n) cin >> a[i];
    cout << cute(a) << '\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll tt; cin >> tt;
    while(tt--) solve();
}
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
#define fl(i,n) for(ll i=0; i<n; i++)

ll cute(vector<ll> a){
    ll s=0,n=a.size();
    if (n==1) return a[0];
    else{
        fl(i,n) s+=a[i];
        vector<ll> v(n-1);
        fl(i,n-1) v[i]=a[i+1]-a[i];
        ll sum=cute(v);
        return (max(s,max(sum,-sum)));
    }
}

void solve(){
    ll n; cin >> n;
    vector<ll> a(n);
    fl(i,n) cin >> a[i];
    cout << cute(a) << '\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll tt; cin >> tt;
    while(tt--) solve();
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fl(i,n) for(ll i=0; i<n; i++)

ll cute(vector<ll> a,ll k){
    ll s=0,n=a.size();
    if (n==1) return a[0];
    else{
        fl(i,n) s+=a[i];
        vector<ll> v(n-1);
        fl(i,n-1) v[i]=a[i+1]-a[i];
        if(k==0) return max(s,abs(cute(v,k+1)));
        else return max(abs(s),abs(cute(v,k+1)));
    }
}

void solve(){
    ll n; cin >> n;
    vector<ll> a(n);
    fl(i,n) cin >> a[i];
    cout << cute(a,0) << '\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll tt; cin >> tt;
    while(tt--) solve();
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll n,a[N];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int flag=0;
    for(int i=1;i<n;i++){
        ll t=min(a[i],a[i+1]);
        a[i]-=t,a[i+1]-=t;
        if(a[i+1]==0){
            cout<<"NO"<<endl;
            return ;
        }
    }
    cout<<"YES"<<endl;
    return ;
}

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

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll n,a[N];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        if(a[i]>=a[i+1]){
            cout<<"NO"<<endl;
            return ;
        }
        ll t=min(a[i],a[i+1]);
        a[i]-=t,a[i+1]-=t;
        
    }
    cout<<"YES"<<endl;
    return ;
}

int main(){
    int _;
    cin>>_;
    while(_--){
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll n,a[N];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int flag=0;
    for(int i=1;i<n;i++){
        ll t=min(a[i],a[i+1]);
        a[i]-=t,a[i+1]-=t;
        if(a[i+1]==0){
            flag=1;
        }
    }
    if(flag==1)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return ;
}

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

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll n,a[N];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int flag=0;
    for(int i=1;i<n;i++){
        ll t=min(a[i],a[i+1]);
        a[i]-=t,a[i+1]-=t;
        if(a[i+1]==0){
            cout<<"NO"<<endl;
            return ;
        }
    }
    cout<<"YES"<<endl;
    return ;
}

int main(){
    int _;
    cin>>_;
    while(_--){
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll n,a[N];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int flag=0;
    for(int i=1;i<n;i++){
        ll t=min(a[i],a[i+1]);
        a[i]-=t,a[i+1]-=t;
        if(a[i+1]==0){
            flag=1;
        }
    }
    if(flag==1)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return ;
}

int main(){
    int _;
    cin>>_;
    while(_--){
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll n,a[N];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        if(a[i]>=a[i+1]){
            cout<<"NO"<<endl;
            return ;
        }
        ll t=min(a[i],a[i+1]);
        a[i]-=t,a[i+1]-=t;
        
    }
    cout<<"YES"<<endl;
    return ;
}

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

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll n,a[N];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return ;
        }
        ll t=min(a[i],a[i+1]);
        a[i]-=t,a[i+1]-=t;
        
    }
    cout<<"YES"<<endl;
    return ;
}

int main(){
    int _;
    cin>>_;
    while(_--){
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

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

using namespace std;

void solve(){   

    long long n,l,r;

    long long ans=0,s=0;

    cin>>n>>l>>r;

    int a[n],c[n];

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

	cin>>a[i];

	c[i]=a[i];

}

    sort(a,a+r);

    sort(c+l-1,c+n);

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

    	s+=a[i];

    	ans+=c[i];

	}

    cout<<min(ans,s)<<endl;

}

int main(){

	int T;

	cin>>T;

	while(T--)solve();

    return 0;

} 

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

using namespace std;

void solve(){   

    long long n,l,r;

    long long ans=0,s=0;

    cin>>n>>l>>r;

    int a[n],c[n];

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

	cin>>a[i];

	c[i]=a[i];

}

    sort(a,a+r);

    sort(c+l-1,c+n);

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

    	s+=a[i];

	}

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

        ans+=c[i];

    }

    cout<<min(ans,s)<<endl;

}

int main(){

	int T;

	cin>>T;

	while(T--)solve();

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,l,r;
    cin>>n>>l>>r;
    long long ans=0;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<r-l+1;i++){
        ans+=a[i];
    }
    cout<<ans<<endl;
}
int main(){
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}

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

using namespace std;

void solve(){   

    long long n,l,r;

    long long ans=0,s=0;

    cin>>n>>l>>r;

    int a[n],c[n];

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

	cin>>a[i];

	c[i]=a[i];

}

    sort(a,a+r);

    sort(c+l-1,c+n);

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

    	s+=a[i];

    	ans+=c[i];

	}

    cout<<min(ans,s)<<endl;

}

int main(){

	int T;

	cin>>T;

	while(T--)solve();

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,l,r;
    cin>>n>>l>>r;
    long long ans=0;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<r-l+1;i++){
        ans+=a[i];
    }
    cout<<ans<<endl;
}
int main(){
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2050D - Digital string maximization
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 main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int n = s.size();
        string res = s;

        // cout << n << endl;
        for (int i = 0; i < n; i++)
        {
            int k = -1;
            for (int j = i + 1; j < n; j++)
            {
                if (res[j] - j > res[i] - i and res[j] - j >= '0' and res[j] - j <= '9')
                {
                    if (k == -1)
                    {
                        k = j;
                        // cout << "Here " << s[k] << endl;
                    }
                    else if (k != -1 and res[j] - j > res[k] - k)
                    {
                        k = j;
                        // cout << "There " << s[k] << endl;
                    }
                }
            }
            if (k != -1)
            {
                res[k] = res[k] - k + i;
                while (k > i)
                {
                    swap(res[k], res[k - 1]);
                    k--;
                }
            }

            // cout << i << " " << k << " " << res << endl;
        }
        cout << res << endl;
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int n = s.size();
        string res = s;

        // cout << n << endl;
        for (int i = 0; i < n; i++)
        {
            int k = -1;
            // cout << res[i] << endl;
            for (int j = i + 1; j < n; j++)
            {
                // cout << "ta " << res[i] << " " << res[j] << endl;
                if (res[j] + i - j > res[i] and res[j] - j + i >= '0' and res[j] - j + i <= '9')
                {
                    if (k == -1)
                    {
                        k = j;
                        // cout << "Here " << res[k] << endl;
                    }
                    else if (k != -1 and res[j] - j > res[k] - k)
                    {
                        k = j;
                        // cout << "There " << res[k] << endl;
                    }
                }
            }
            // cout << i << " " << k << " ";
            if (k != -1)
            {
                res[k] = res[k] - k + i;
                while (k > i)
                {
                    swap(res[k], res[k - 1]);
                    k--;
                }
            }
            // cout << res << endl;
        }
        cout << res << endl;
    }
    return 0;
}