ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 61 ms):
#include<iostream>
#include<cstring>
using namespace std;
#define mem1  std::memset(a,0,sizeof(a));
#define mem2  std::memset(b,0,sizeof(b));
#define mem3  std::memset(c,0,sizeof(c));
#define endl '\n'
#define thirteentargetofnosevenday() ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set  tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//#define endl '\n'
const int mx=2e5+123;
int a[mx];
int32_t main()
{
    thirteentargetofnosevenday();
    ll t;
    cin>>t;
    while(t--)
    {
    string s;
    cin>>s;
    ll sum=0,two=0,three=0;
    for(ll i=0; i<s.size(); i++){
        s[i]-=48;
        if(s[i]==2)two++;
        if(s[i]==3)three++;
        sum+=s[i];
    }
   if(sum%9==0)cout<<"YES"<<endl;
   else {
    ll f=0;
    for(ll i=0; i<=two; i++){
        for(ll j=0; j<=three; j++){
            ll final=(sum+i*2+j*6);
            if(final%9==0){
                f++;
                break;
            }
        }
        if(f>0)break;
    }
    if(f>0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
   }
    }
}






Solution 2 (runtime: 62 ms):
/**
 *    author:  tourist
 *    created: 05.12.2024 19:38:37
**/
#include <bits/stdc++.h>

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    string s;
    cin >> s;
    vector<bool> dp(9);
    dp[0] = true;
    for (char c : s) {
      vector<bool> new_dp(9);
      for (int x = 0; x < 9; x++) {
        if (dp[x]) {
          int d = int(c - '0');
          while (d <= 9) {
            new_dp[(x + d) % 9] = true;
            if (d <= 1) {
              break;
            }
            d = d * d;
          }
        }
      }
      swap(dp, new_dp);
    }
    cout << (dp[0] ? "YES" : "NO") << '\n';
  }
  return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>

using namespace std;

int find(string &s, int r)
{
    int l = r-1;
    // cout << l << endl;
    while (l >= 0)
    {
        if (s[r] - s[l] > 1 || s[l] - s[r] > 1)
        {
            return l;
        }
        else
        {
            l--;
            r--;
        }
    }
    return l;
}

void change(string &s, int r)
{
    int l = r;
    while (l < s.length() - 1)
    {
        if (s[l + 1] - s[l] > 1)
        {
            char temp = s[l + 1];
            s[l + 1] = s[l];
            s[l] = temp - 1;
            l++;
            // cout << s << " s from change" << endl;
        }
        else
        {
            return;
        }
    }
    return;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int r = s.size() - 1;
        while (r >= 0)
        {
            if (s[r] == '0')
            {
                r--;
            }
            else
            {
                int k;
                k = find(s, r);
                // cout << k << endl;
                if (k >= 0)
                {
                    change(s, k);
                }
                r = k;
                // cout << r << "next" << " st " << s << endl;
            }
        }
        cout << s << endl;
    }
    return 0;
}

Solution 2 (runtime: 108 ms):
// Online C++ compiler to run C++ program online
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
typedef std::pair<int, int> Pair;
bool customCompare(const Pair &a, const Pair &b) {
    if (a.first != b.first)
        return a.first < b.first;
    return a.second < b.second;
}

void fun(){
    string s;
    cin >> s;
    
    int i=0, n = s.length();
    while(i<n){
        int last_ind = min(i+9, n), max_val = s[i]-'0', max_ind = i,run_ind = i+1;
        
        // Get the max_val for the present index
        while(run_ind < last_ind){
            int run_val = s[run_ind]-'0';
            if((run_val - (run_ind - i)) > max_val){
                max_val = run_val - (run_ind - i);
                max_ind = run_ind;
            }
            run_ind++;
        }
        
        // Shift the value to right
        run_ind = max_ind;
        while(run_ind > i){
            s[run_ind] = s[run_ind-1];
            run_ind--;
        }
        s[run_ind] = max_val + '0';
        i++;
    }
    cout << s << endl;
}
int main() {
    int t;
    cin >> t;
    
    while(t--){
        fun();
    }
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 124 ms):
#include <bits/stdc++.h>
using namespace std;

int a[200005];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        for(int i = 1; i <= n; i++){
            cin >> a[i];
        }
        if(a[1] > a[2]){
            cout << "NO" << '\n';
            continue; 
        }
        bool con = 0;
        for(int i = 1; i < n; i ++){
            if(a[i] <= a[i + 1]){
                a[i + 1] -= a[i];
                a[i] = 0;
            }
        }
        for(int i = 1; i < n; i ++){
            if(a[i] > a[i + 1]){
                con = 1;
                break;
            }
        }
        if(con == 1){
            cout << "NO" << '\n';
        }else{
            cout << "YES" << '\n';
        }
    }
}

Solution 2 (runtime: 108 ms):
// D. Subtract Min Sort 减去最小值排序 使序列变为非递减序列

/*
给定一个由n个正整数组成的序列a
可以执行以下操作任意次数：
选择一个索引i, m = min(a[i], a[i+1]) a[i] -= m; a[i+1] -= m;
确定是否可以通过执行任意次数的操作使序列变为非递减序列。
操作定义：选择任意相邻的两个元素，并同时减去它们的最小值。
这个操作会减少这两个元素的值，但不会改变它们的相对顺序。
如果序列已经是非递减的，那么不需要任何操作。
如果序列中存在一个元素比它后面的元素大，那么需要通过操作来减少这个元素的值，使其不大于后面的元素。
由于只能减少相邻元素的值，需要确保在减少一个元素时，不会影响到前面的元素。
*/

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;

const string Y = "YES";
const string N = "NO";

bool check(vector<int>& a) {
    for (int i = 0; i < a.size() - 1; i++) {
        if (a[i] > a[i + 1]) {
            return false;
        }
    }
    return true;
}

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

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

    // 检查序列本身是否是非递减序列
    if(check(a)){
        cout << Y << endl;
        return;
    }

     for (int i = 0; i < n - 1; i++) {
        int m = min(a[i], a[i + 1]);
        a[i] -= m;
        a[i + 1] -= m;
    }

    if (check(a)) {
        cout << Y << endl;
    } else {
        cout << N << endl;    
    }

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 359 ms):
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        for (int i = 1; i < n; i++ ){
            int k = min(a[i], a[i - 1]);
            a[i] -= k;
            a[i - 1] -= k;
        }
        bool yes = true;
        for (int i = 1; i < n; i++){
            if(a[i] < a[i - 1]){
                yes = false;
                break;
            }
        }
        if(yes)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}

Solution 2 (runtime: 93 ms):
#include <iostream>

#include <vector>

using namespace std;

 

typedef long long ll;

 

void solve(){

    int n;

    cin >> n;

    vector<ll> a(n);

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

        cin >> a[i];

    }

    

    // For a non-decreasing sequence, we need to be able to zero-out all but the last element.

    // The very first operation is only possible if a[0] <= a[1].

    if(a[0] > a[1]){

        cout << "NO\n";

        return;

    }

    

    // Let d be the residual after zeroing-out a[0] using (a[0], a[1]).

    ll d = a[1] - a[0];

    

    // Process the rest of the array.

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

        if(a[i] < d){

            cout << "NO\n";

            return;

        }

        d = a[i] - d;

    }

    

    cout << "YES\n";

}

 

int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t;

    cin >> t;

    while(t--){

        solve();

    }

    

    return 0;

}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long 
#define input_vector(v,n) vector<int>v(n); for(int &x:v) cin>>x;
void solve(){
    int n;
    cin>>n;
    input_vector(v,n);
    int tot_sum=accumulate(v.begin(),v.end(),0LL);
    for(int i=n-1;i>0;i--){
        int sum=0;
        for(int r=0;r<i;r++) v[r]-=v[r+1];
        for(int s=0;s<i;s++) sum+=v[s];
        sum=max(sum,-sum);
        tot_sum=max(tot_sum,sum);
    }
    cout<<tot_sum<<endl;
}
int32_t main(){
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>

using namespace std;




int main()
{

    int ts;
    cin >> ts;
    while(ts--)
      {
             long long a[51];
              int n;
              cin >> n;
               long long sum = 0;
              for(int i = 1;i<=n;++i){
                 cin >> a[i];

                 sum+=a[i];

              }

            while(n>1)
               {
                   n--;
                   long long s2 = 0;
                   for(int i = 1;i<=n;++i){
                     a[i] = a[i+1] - a[i];

                      s2+=a[i];

                   }

                   long long s1 = -s2;






                 sum = max(sum,max(s2,s1));

               }






           cout << sum << endl;






      }







}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 109 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
void solve()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    map<int, int> mp;
    for (int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        mp[a[i]] ++;
    }
    vector<int> v;
    for (auto [i, j] : mp)
        v.push_back(j);
    sort(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < v.size() - 1; i ++)
    {
        if (v[i] <= k)
            k -= v[i], ans ++;
    }
    cout << v.size() - ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T --)
    solve ();
    return 0;
}

Solution 2 (runtime: 281 ms):
// https://codeforces.com/problemset/problem/2057/B
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
ll t, n, k;
map<ll, ll> a;
vector<p> b;

bool cmp(p a, p b)
{
    return a.second < b.second;
}

void solve()
{
    ll ans = 0;
    cin >> n >> k;
    for (ll i = 1; i <= n; i++)
    {
        ll aa;
        cin >> aa;
        a[aa] += 1;
    }
    for (auto i : a)
    {
        b.push_back({i.first, i.second});
    }
    sort(b.begin(), b.end(), cmp);
    for (auto i : b)
    {
        if (k >= i.second)
            k -= i.second;
        else
            ans++;
    }
    if (ans == 0)
        ans = 1;
    cout << ans << '\n';
    a.clear();
    b.clear();
}

int main()
{
    cin >> t;
    while (t--)
        solve();
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define fi first
#define se second
#define PII pair<int,int>
#define ALL(x) x.begin(),x.end()
const int N=2e5+10;

void solve()
{
    int n,fa=0;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++)
    {
        if(a[i]>a[i+1])
        {
            cout<<"NO\n";
            return;
        }
        a[i+1]-=a[i];
    }
    cout<<"YES\n";
}

signed main()
{
    IOS
    int T=1;
    cin>>T;
    while(T--)solve();
    return 0;
}

Solution 2 (runtime: 374 ms):


#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;



int main()

{

int n,t;

cin>>t;

while(t--){

cin>>n;

int arr[n];



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

cin>>arr[i];

}



bool f=1;

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

if(arr[i]<=arr[i+1]){

int min=arr[i];

arr[i]=0;

arr[i+1]= arr[i+1]-min;

}

//  cout<<i<<" "<<arr[i]<<" "<<arr[i+1];

}

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

//cout<<arr[i];

if(arr[i]>arr[i+1]){

f=0;

break;

}

}

//  cout<<arr[n-1];

if(!f)cout<<"NO"<<endl;

else{

cout<<"Yes"<<endl;

}



}



return 0;

}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 108 ms):
#include<bits/stdc++.h>
using namespace std;

int solve(string& s1, string& s2, string& s3, int i, int j, int k, vector<vector<int>>& dp){
    if(k<0 && j<0 && i<0){
        return 0;
    }
    if(k<0){
        return 1e8;
    }
    if(i>=0 && j>=0 && dp[i+1][j+1] != -1){
        return dp[i+1][j+1];
    }
    // cout<<i<<j<<k<<endl;
    int ans = 1e8;
    if(s3[k]!=s1[i] && s3[k]!=s2[j]){
        if(i>=0 &&j>=0)
        return dp[i+1][j+1] = 1+min(solve(s1, s2, s3, i-1, j, k-1, dp), solve(s1, s2, s3, i, j-1, k-1, dp));
        if(i>=0)
        return dp[i+1][j+1] = 1+solve(s1, s2, s3, i-1, j, k-1, dp);
        if(j>=0)
        return dp[i+1][j+1] = 1+solve(s1, s2, s3, i, j-1, k-1, dp);

    }
    if(i>=0 && s3[k]==s1[i]){
        ans=min(ans, solve(s1, s2, s3, i-1, j, k-1, dp));
    }
    else if(i>=0){
        ans = min(ans, 1+solve(s1, s2, s3, i-1, j, k-1,dp));
    }
    if(j>=0 && s3[k]==s2[j]){
        ans=min(ans, solve(s1, s2, s3, i, j-1, k-1, dp));
    }
    else if(j>=0){
        ans = min(ans, 1+solve(s1, s2, s3, i, j-1, k-1, dp));
    }
    return dp[i+1][j+1] = ans;
}


int main(){
    int testcases=1;

    cin>>testcases;
    while(testcases--){
        string s1, s2, s3;
        cin>>s1>>s2>>s3;
        vector<vector<int>> dp(s3.size()+10, vector<int>(s3.size()+10, -1));
        cout << solve(s1, s2, s3, s1.size()-1, s2.size()-1, s3.size()-1, dp)<<endl;

    }
}



Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e3 + 10;
int t;
char a[N], b[N], c[N*2];
int dp[N][N];
void solve()
{
    cin >> a + 1;
    cin >> b + 1;
    cin >> c + 1;
    int la = strlen(a + 1);
    int lb = strlen(b + 1);
    for (int i = 0; i <= la; i++)
    {
        for (int j = 0; j <= lb; j++)
        {
            dp[i][j] = 1e8;
        }
    }
    dp[0][0]=0;
    for (int i = 0; i <= la; i++)
    {
        for (int j = 0; j <= lb; j++)
        {
            if(i) dp[i][j] = min(dp[i][j],dp[i - 1][j] + (c[i + j] != a[i]));
            if(j) dp[i][j] = min(dp[i][j], dp[i][j - 1] + (c[i + j] != b[j]));
            // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl; 
        }
    }
    cout<<dp[la][lb]<<endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 62 ms):
#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 ull unsigned long long
#define ll long long 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(), v.end()
#define vec vector<ll>
#define pb push_back
#define Raftaar ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MEX LONG_LONG_MAX
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
/*


*/                 
            


void solve(){
	ll l,r;
	cin>>l>>r;
	ll prev=0;
	ll a,b,c;
	rf(i,30,0){
		ll p=0,q=0;
		if(l & (1ll<<i)){
			p=1;
		}
		if(r & (1ll<<i)){
			q=1;
		}
		if(p==q){
			prev+=(p*(1ll<<i));
		}
		else{
			a=prev+(1ll<<i);
			b=a-1;
			break;
		}
	}
	f(i,l,r+1){
		if(i!=a && i!=b){
			c=i;
			break;
		}
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
}

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


Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
#define endl "\n"
#define int long long
#define mod_ 1000000007
#define fastIO                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
using namespace std;


void pixel() {
    int l, r;
    cin >> l >> r;
    int k = 31 - __builtin_clz(l ^ r);
    int a = l | ((1 << k) - 1);
    int b = a + 1;
    int c = (a == l ? r : l);
    cout << a << " " << b << " " << c << endl;
}

int32_t main() {
    fastIO;
    int t = 1;
    cin >> t;
    while (t--) {
        pixel();        
    }
    return 0;
}





/*
 _____ _____ _____ _____ _____ 
|     |  _  |   __|   __|     |
|   --|     |__   |__   |-   -|
|_____|__|__|_____|_____|_____|

*/
Problem: 2049C - MEX Cycle
Language: c++17 

Solution 1 (runtime: 78 ms):
#include<bits/stdc++.h>

using namespace std;

#define print_b(ans) cout<<(ans?"YES":"NO")<<endl;

#define print_n(x)        cout<<x<<endl;

#define times(x)          int x;cin>>x;while(x--)

#define debug(x) cout<<#x<<": "<<x<<endl;

typedef long long ll;

void judge(){

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    #ifndef ONLINE_JUDGE

        freopen("input.txt","r",stdin);

        //freopen("output.txt","w",stdout);

    #endif

}

int main(){

    judge();

    times(x){

        int n,x,y;cin>>n>>x>>y;

        if(x<y)swap(x,y);

        vector<int> ans(n);

        ans[x-1]=1;

        ans[y-1]=0;

        int left=(x-y-1);

        int right=n-(x-y+1);

        if(left%2==0){

            bool test=1;

            for(int i=y;i<x-1;i++){

                ans[i]=test;

                test^=1;

            }

        }

        else{

            bool test=1;

            for(int i=y;i<(y+left/2);i++){

                ans[i]=test;

                test^=1;

            }

            ans[y+left/2]=2;

            for(int i=(y+left/2+1);i<x-1;i++){

                ans[i]=test;

                test^=1;

            }

        }

        if(right%2==0){

            bool test=false;

            int i=x;

            i%=n;

            while(i!=y-1){

                ans[i]=test;

                test^=true;

                i++;

                i%=n;

            }

        }

        else{

            bool test=0;

            int i=x;

            i%=n;

            int test1=(x+right/2)%n;

            while(i!=test1){

                ans[i]=test;

                test^=1;

                i++;

                i%=n;

            }

            ans[i]=2;

            i++;

            i%=n;

            while(i!=y-1){

                ans[i]=test;

                test^=1;

                i++;

                i%=n;

            }

        }

        for(int i=0;i<n;i++)cout<<ans[i]<<" ";

        cout<<endl;

    }

}

Solution 2 (runtime: 77 ms):
#include <ios>

#include <iostream> 

#include <vector>



using namespace std;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    int t;

    cin >> t;



    while(t--) {

        int n, x, y;

        cin >> n >> x >> y;

        --x;

        --y;

        std::vector<int> a(2 * n, 0);



        int value = 0;

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

            a[i] = value;

            value = (value + 1) % 2;

        }

        

        if (n % 2 == 1 || (y -  x) % 2 == 0) {

            a[x] = 2;

        }



        std::vector<int> result(n);

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

            result[i % n] = a[i];

        }



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

            cout << result[i] << " ";

        }

        cout << "\n";

    }

}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 1983 ms):
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	
	int t ; 
	cin>>t;
	while(t--){
	    string s  ;
	     cin>>s ;
	     if(s.size()==1){
	         cout<<s<<endl ;
	         continue ;
	     }
	     for(int i = 0; i <s.size() ;i++){
	         char ans = s[i] ; int index = i ; 
	         for(int j =i ; j <=i+9&&j<=s.size() ; j++ ){
	             if(s[j]-j+i > ans && s[j]>'0'){
	                 ans = s[j]-j+i;
	                 index = j ; 
	             }
	         }
	           s.erase(s.begin()+index);
	         s.insert(s.begin()+i,ans);
	     }
	     cout<<s<<endl;
	}
 
} 

Solution 2 (runtime: 62 ms):
#include <ostream>

#include <cstdio>

#include <algorithm>

#include<list>

#include<queue>

#include <iostream>

#include <cstring>

#include <math.h>

#include <cmath>

#include <string>

using namespace std;

using i64 = long long;

int T, n;

void solve() {

    string s; cin >> s;

    for (int i = 0; i < (int)s.size(); i ++) {

        int res = s[i], pos = i;

        for (int j = i + 1; j < min((int)s.size(), i + 11); j ++) 

            if ((int)s[j] - (j - i) > res) res = (int)s[j] - (j - i), pos = j;

        for (int j = pos; j > i; j --) swap(s[j], s[j - 1]), s[j - 1] --;

    }

    cout << s << '\n';

}

int main() {

    cin.tie(NULL) -> sync_with_stdio(false);

    cin >> T;

    while (T --) solve();

    return 0;

}