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

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int sum = 0;
        for (char c : s)
        {
            sum += c - '0';
        }
        int twos = 0;
        int threes = 0;
        for (char c : s)
        {
            if (c == '2')
            {
                twos++;
            }
            else if (c == '3')
            {
                threes++;
            }
        }
        int flag = 0;
        for (int i = 0; i <= min(10ll, twos); i++)
        {
            for (int j = 0; j <= min(10ll, threes); j++)
            {
                if ((sum + 2 * i + 6 * j) % 9 == 0)
                {
                    flag = 1;
                    break;
                }
            }
        }
        if (flag)
        {
            cout << "YES\n";
        }
        else
        {
            cout << "NO\n";
        }
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int sum = 0;
        string s = to_string(n);
        for (char c : s)
        {
            sum += c - '0';
        }
        if (sum % 9 == 0)
        {
            cout << "YES\n";
            continue;
        }
        int twos = 0;
        int threes = 0;
        for (char c : s)
        {
            if (c == '2')
            {
                twos++;
            }
            else if (c == '3')
            {
                threes++;
            }
        }
        int flag = 0;
        for (int i = 0; i <= twos; i++)
        {
            for (int j = 0; j <= threes; j++)
            {
                if ((sum + 2 * i + 6 * j) % 9 == 0)
                {
                    flag = 1;
                    break;
                }
            }
        }
        if (flag)
        {
            cout << "YES\n";
        }
        else
        {
            cout << "NO\n";
        }
    }
    return 0;
}

Answer: 1
Problem: 2050C - Uninteresting Number
Language: c++23 

Code 1:
#include <bits/stdc++.h>



#define int long long



using namespace std;



void solve(){

    string s;

    cin >> s;

    int cnt = 0, cnt2 = 0, sum = 0;

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

        int c = s[i] - '0';

        if (c == 2){

            cnt++;

        }

        else if (c == 3){

            cnt2++;

        }

        sum += c;

    }



    int x = sum % 9;

    if (x == 0){

        cout << "YES\n";

        return;

    }

    while (cnt > 0){

        x += 2;

        if (x % 9 == 0){

            cout << "YES\n";

            return;

        }

        cnt--;

    }

    int x = sum % 9;

    if (x == 0){

        cout << "YES\n";

        return;

    }

    while (cnt2 > 0){

        x += 6;

        if (x % 9 == 0){

            cout << "YES\n";

            return;

        }

        cnt2--;

    }

    int x = sum % 9;

    if (x == 0){

        cout << "YES\n";

        return;

    }



    cout << "NO\n";

}



int32_t main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t;

    cin >> t;

    while (t--){

        solve();

    }

    return 0;

}

Code 2:
#include <bits/stdc++.h>



#define int long long



using namespace std;



void solve(){

    string s;

    cin >> s;

    int cnt = 0, cnt2 = 0, sum = 0;

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

        int c = s[i] - '0';

        if (c == 2){

            cnt++;

        }

        else if (c == 3){

            cnt2++;

        }

        sum += c;

    }



    int x = sum % 9;

    

    for (int i = 0; i <= min(8ll, cnt); i++){

        for (int j = 0; j <= min(8ll, cnt2); j++){

            if ((2 * i + 6 * j + x) % 9 == 0){

                cout << "YES\n";

                return;

            }

        }

    }

    cout << "NO\n";

}



int32_t main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t;

    cin >> t;

    while (t--){

        solve();

    }

    return 0;

}

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

Code 1:


    #include <bits/stdc++.h> // include all standard headers
    using namespace std;
     
    #define ll long long
    #define ld long double
    #define pii pair<int, int>
    #define mp make_pair
    #define pb push_back
    #define eb emplace_back
    #define fi first
    #define se second
     
    const int INF = 1e9;
    const ll INFLL = 1e18;
    const int MOD = 1e9 + 7;

    char rect(vector<char> &s){
        int n=s.size();
     
    
     char max=s[0];
     int ind=0;
        for(int i=1; i<min(n,10); i++){
          if(s[i]-i>max){
          max=s[i]-i;
          ind=i;
        }}
        s.erase(s.begin()+ind);
        return max;
    
    }
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        // Declare any additional variables here
        
        int t; // number of test cases
        cin >> t;
        
        while (t--) {
          string s;
          cin >> s;
          ll n;
          n=s.size();
          vector<char> v;
          if(n>9){
          for(int i=0; i<10;i++)
           v.pb(s[i]);
           cout<<rect(v);
           for(int i=10;i<n;i++){
            v.pb(s[i]);
           cout<<rect(v);}
           for(int i=0;i<9;i++){
               cout<<rect(v);
           }
          
          }
          else{
        for(int i=0;i<n;i++){
        v.pb(s[i]);
        }
        int size=v.size();
        for(int i=0;i<size;i++)
        cout<<rect(v);
          }
        cout<<"\n";
         
        }
       
        
        return 0;
    }




Code 2:
#include <bits/stdc++.h> // include all standard headers
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
    bool customSort(const pair<int, int>& a, const pair<int, int>& b) {
    if (a.first == b.first) { 
        return a.second > b.second; 
    }
    return a.first < b.first; }
char rect(vector<char> &s){
    int n=s.size();
    vector<pair<char,ll>> v(n);
    vector<char> vis;

    for(int i=0; i<min(n,10); i++){
      if(s[i]!='\0'){
        v[i].fi=s[i]-i;
        v[i].se=i;}
    
    }
sort(v.begin(),v.end(),customSort);
    s.erase(s.begin()+v[v.size()-1].se);
    return v[v.size()-1].fi;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    // Declare any additional variables here
    
    int t; // number of test cases
    cin >> t;
    
    while (t--) {
      string s;
      cin >> s;
      ll n;
      n=s.size();
     vector<char> v;
     for(int i=0;i<n;i++){
        v.pb(s[i]);
     }
     for(int i=0;i<n;i++)
      cout<<rect(v);
      

    }
    
    return 0;
}

Answer: 1
Problem: 2050D - Digital string maximization
Language: c++23 

Code 1:
#include <iostream>
#include <string>
using namespace std;

void solve(string s) {
    long long n = s.size();
    bool updated = true;

    while (updated) {
        updated = false;
        for (long long i = n - 1; i > 0; --i) {
            if (s[i] > s[i - 1] + 1) {
                s[i]--;
                swap(s[i], s[i - 1]);
                updated = true;  // Mark as updated to repeat the process
            }
        }
    }

    cout << s;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        solve(s);
        cout << endl;
    }
    return 0;
}

Code 2:
#include<iostream>
#include<string>
using namespace std;

int main(){
int t;
cin>>t;
while(t--){
    string n;
    cin>>n;
    int change(1);
    while(change!=0){
        change=0;
        for(int i=1;i<n.length();i++){
            if((n[i-1] - '0')<((n[i] - '0')-1)){
                int temp=n[i-1] - '0';
                n[i-1]=char((n[i] - '0') - 1) + '0';
                n[i]=char(temp) + '0';
                change++;
            }
        }
    }
    cout<<n<<endl;
}
return 0;
}

Answer: 2
Problem: 2050D - Digital string maximization
Language: c++20 

Code 1:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

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

    solve();

    return 0;
}


Code 2:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    int t;
    cin >> t;
    
    while (t--) {
        string s;
        cin >> s;
        int n = s.size();
        
        bool changed;
        do {
            changed = false;
            for (int i = 1; i < n; i++) {
                if (s[i] > s[i-1] && s[i] != '0' && s[i] != s[i-1] + 1) {
                    s[i] -= 1;
                    swap(s[i], s[i-1]);
                    changed = true;
                }
            }
        } while (changed);
        
        cout<<s<<endl;
        
        
}}

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

    solve();

    return 0;
}


Answer: 2
Problem: 2050D - Digital string maximization
Language: python

Code 1:
for _ in range(int(input())):
  s=list(map(int,input()[::-1]))
  a=[]
  while s:
    m=s[-1]
    x=-1
    for i in range(-1,max(-11,-len(s)-1),-1):
      if x-m==9:
        break
      if s[i]+i+1>m:
        m=s[i]+i+1
        x=i
    a.append(m)
    del s[x]
  print("".join(map(str,a)))

Code 2:
for _ in range(int(input())):
  s=list(map(int,input()))
  a=[]
  while s:
    m=s[0]
    x=0
    for i in range(1,min(10,len(s))):
      if x+m==9:
        break
      if s[i]-i>m:
        m=s[i]-i
        x=i
    a.append(m)
    del s[x]
  print("".join(map(str,a)))
      

Answer: 1
Problem: 2050D - Digital string maximization
Language: python

Code 1:
t =  int(input())

def solve():

s = [int(i) for i in list(input())]

n = len(s)

for i in range(1,n,1):

for j in range(max(i-10, 0), i):

if s[i] - (i-j) > s[j]:

s.insert(j, s[i] - (i-j))

s.pop(i+1)

break

print("".join([str(i) for i in s]))

return

for i in range(t):

solve()

Code 2:
t =  int(input())

def solve():

s = [int(i) for i in list(input())]

n = len(s)

for i in range(1,n,1):

for j in range(max(i-10, 0), i):

if s[i] - (i-j) > s[j]:

tmp = s[j:i]

s[j] = s[i] - (i-j)

s[j+1:i+1] = tmp

break

print("".join([str(i) for i in s]))

return

for i in range(t):

solve()

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

Code 1:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 
// typedef vector<int> vi; 
// typedef vector<vector<int>> vvi; 
// typedef vector<long long> vl; 
// typedef vector<vector<long long>> vvl;
// typedef vector<bool> vb; 
// typedef vector<vector<bool>> vvb; 
// typedef map<int, int> mii; 
// typedef map<long long, long long> mll;
// typedef pair<int, int> pii; 
// typedef pair<long long, long long> pll;
// typedef unsigned long long ull; 
// typedef long double ld; 
// typedef long long ll;
typedef long long ll;
#define f(i,a,b) for(int i = a; i < b ; i++)
#define geti(n) int n; cin >> n;
#define getll(n) long long int n; cin >> n;
#define gets(s) string s; cin >>s;
#define getv(v,n) vector<int> v(n) ; f(i, 0 ,n) cin >> v[i];
#define srt(v) sort(v.begin(), v.end());
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
void Solve() 
{
    string s;
    cin>>s;
    vector<long long> v(s.size());
    long long n = s.size();
    for(long long i = 0; i<s.size(); i++){
        v[i] = (s[i] - '0');
    }
    for(long long i = 0; i<n; i++){
        long long max = v[i];
        long long ind = i;
        for(long long j = i; j<min(n, j+9); j++){
            long long mx = v[j] - (j - i);
            if(mx > max){
                max = mx;
                ind = j;
            }
        }
        for(long long k = ind; k>i; k--){
            v[k] = v[k-1];
        }
        v[i] = max;
        cout<<max;
    }
    cout<<endl;
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++) 
    {
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured:"  << elapsed.count() * 1e-9 << ",seconds."; 
    return 0;
}

Code 2:
#include <bits/stdc++.h>

using namespace std;

void solve() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0', pos = i;
        for (int j = i; j < min(i + 10, (int) s.size()); j++) {
            if (s[j] - '0' - (j - i) > best) {
                best = s[j] - '0' - (j - i);
                pos = j;
            }
        }
        while (pos > i) {
            swap(s[pos], s[pos - 1]);
            pos--;
        }
        s[i] = char(best + '0');
    }
    cout << s;
}

int main() {
    int TESTS = 1; cin >> TESTS;
    while (TESTS --> 0) {
        solve();
        cout << '\n';
    }
    return 0;
}

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

Code 1:
#include <bits/stdc++.h>
using namespace std;
void solve();

int main()
{
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
        cout << "\n";
    }
}

bool swapOrNot(int a, int b)
{
    int num1 = (b - 1) * 10 + a;
    int num2 = (a * 10) + b;
    return num1 > num2;
}

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

    int n = num.length();

    if (n == 1)
    {
        cout << num;
        return;
    }

    string ans = "";
    ans += num[n - 1];

    for (int i = n - 2; i >= 0; i--)
    {
        ans = num[i] + ans;
        if (ans[0] < ans[1])
        {
            for (int j = 0; j < ans.length() - 1; j++)
            {
                if (ans[j] < ans[j + 1])
                {
                    if (swapOrNot(ans[j] - '0', ans[j + 1] - '0'))
                    {
                        char modifiedChar = ans[j + 1] - 1;
                        swap(ans[j], modifiedChar);
                        ans[j + 1] = modifiedChar;
                    }
                }
                else
                {
                    break;
                }
            }
        }
    }

    cout << ans;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
void solve();

int main()
{
    int t=1;
    cin>>t;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

bool swapOrNot(int a, int b)
{
    int num1 = (b-1)*10+a;
    int num2 = (a*10)+b;
    return num1>num2;
}

void solve()
{
    string num;
    cin>>num;
    
    int n=num.length();

    if(n==1)
    {
        cout<<num;
        return;
    }

    string ans="";
    ans+=num[n-1];

    for(int i=n-2;i>=0;i--)
    { 
        ans=num[i]+ans;
        for(int j=0;j<ans.length()-1;j++)
        {
           if(swapOrNot(ans[j]-'0',ans[j+1]-'0'))
           {
              char modifiedChar = ans[j+1] - 1;
              swap(ans[j], modifiedChar);
              ans[j+1] = modifiedChar;
           }
        }
    }

    cout<<ans;
}

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

Code 1:
#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <iostream>
using namespace std;

using ll = long long;
void setIO() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}




void solve() {
	string s; cin >> s;
	string ans = "";
	int n = s.length();
	vector<int> arr;
	vector<int> diffs(n, 0);
	for(int i = 0; i < n; i++) {
		arr.push_back(s[i] - '0');
	}

	int amtskipped = 0;
	for(int i = 0; i < n; i++) {
		int bestIndex = 0;
		int bestAmt = 0;
		for(int j = 0; j < min((int) arr.size(), 9); j++) {
			if(arr[j] - j > bestAmt) {
				bestIndex = j;
				bestAmt = arr[j] - j;
			}
		}

		arr.erase(arr.begin() + bestIndex);
		ans += to_string(bestAmt);
	}

	cout << ans << "\n";
}





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



Code 2:
#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <iostream>
using namespace std;

using ll = long long;
void setIO() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}




void solve() {
	string s; cin >> s;
	string ans = "";
	int n = s.length();


	set<int> getRid;
	for(int i = 0; i < n; i++) {
		int bestIndex = i;
		int bestAmt = 0;
		for(int j = i; j < min((int) s.size(), i+10); j++) {
			if(s[j] - '0' - (j-i) > bestAmt) {
				bestIndex = j;
				bestAmt = s[j] - '0' - (j-i);
			}
		}

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

		s[i] = char(bestAmt + '0');

	}

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





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



Answer: 2
Problem: 2050D - Digital string maximization
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(m) m.begin(),m.end()
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vvl vector<vector<ll>>
bool is_prime(int n) {
    if (n <= 1) return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}
void solve(){
    string s;
    cin >> s;
    ll n = s.size();
    f(i,0,n-1){
        ll maxi_ind = i;
        ll maxi_val = s[i]-'0';
        f(j,i,min(10LL,n-1)){
            if(s[j]-'0'+i-j>maxi_val){
                maxi_val = s[j]-'0'+i-j;
                maxi_ind = j;
            }
        }
        while(maxi_ind > i){
            swap(s[maxi_ind],s[maxi_ind-1]);
            maxi_ind--;
        }
        s[i] = '0'+maxi_val;
    }
    cout << s << endl;
}
int main(){
    ll t;
    cin >> t;
    while(t--){
        solve();
    }
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(m) m.begin(),m.end()
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vvl vector<vector<ll>>
bool is_prime(int n) {
    if (n <= 1) return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}
void solve(){
    string s;
    cin >> s;
    ll n = s.size();
    f(i,0,n-1){
        ll maxi_ind = i;
        ll maxi_val = s[i]-'0';
        f(j,i,min(i+10LL,n-1)){
            if(s[j]-'0'+i-j>maxi_val){
                maxi_val = s[j]-'0'+i-j;
                maxi_ind = j;
            }
        }
        while(maxi_ind > i){
            swap(s[maxi_ind],s[maxi_ind-1]);
            maxi_ind--;
        }
        s[i] = '0'+maxi_val;
    }
    cout << s << endl;
}
int main(){
    ll t;
    cin >> t;
    while(t--){
        solve();
    }
}

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

Code 1:
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define f first
#define s second

using namespace std;

void solve()
{
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        int q = 0;
        int mx = s[i] - 48;
        for (int j = 1; i + j < s.size() && j < 10; j++)
        {
            int x = s[i + j] - 48;
            x -= j;
            if (x > mx)
            {
                q = j;
                mx = x;
            }
        }

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

        s[i] -= q;
    }

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

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

    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}


Code 2:
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define f first
#define s second

using namespace std;

void solve()
{
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        int q = 0;
        int mx = s[i] - 48;
        for (int j = 1; i + j < s.size() && j < i + 10; j++)
        {
            int x = s[i + j] - 48;
            x -= j;
            if (x > mx)
            {
                q = j;
                mx = x;
            }
        }

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

        s[i] -= q;
    }

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

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

    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}


Answer: 1
Problem: 2050D - Digital string maximization
Language: python

Code 1:
def highest_var(x):
    com = 'play'
    while com == 'play':
        max_n = max(x)
        check = []
        while max_n > 2:
            pos = [[idx, i] for idx, i in enumerate(x) if i == max_n and idx != 0]

            check_q = 0
            for jup in pos:
                if x[jup[0]-1] < max_n - 1:
                    x[jup[0]-1], x[jup[0]] = x[jup[0]]-1, x[jup[0]-1]
                    check_q = 1
                
            max_n -= 1
            if check_q == 1:
                check.append(1)
        if not check:
            com = 'stop'
    return x


t = int(input())
ab_res = []
for _ in range(t):
    s = input()
    x = []
    res = ''
    for letter in s:
        x.append(int(letter))

    x = highest_var(x)
    for i in x:
        res+=str(i)
    ab_res.append(res)

for i in ab_res:
    print(i)

Code 2:
def highest_var(x):
    while True:
        max_n = max(x)  
        check = False   
        while max_n > 1:
            for i in range(1, len(x)):  
                if x[i] == max_n and x[i - 1] < max_n - 1:
                    x[i - 1], x[i] = x[i] - 1, x[i - 1]  
                    check = True  
            max_n -= 1
        if not check:  
            break
    return x


t = int(input())
ab_res = []
for _ in range(t):
    s = input().strip()
    x = list(map(int, s))  
    x = highest_var(x)
    ab_res.append(''.join(map(str, x)))

print('\n'.join(ab_res))

Answer: 2
Problem: 2050D - Digital string maximization
Language: python

Code 1:
from sys import stdin
from typing import Any
import math
input = stdin.readline
def ri(): return int(input())
def rl(v_type=int,output=list): return output(map(v_type, input().split()))
def rs(): return input().rstrip()
def out(x, sep='\n'): print(sep.join(x))


def solve():
    s = rs()
    n = len(s)
    a = list(map(int,s))
    for i in range(n-2,-1,-1):
        for j in range(i+1, min(i + 10,n)):
            if a[j-1] + (1) < a[j]:
                a[j-1],a[j] = a[j] - (1),a[j-1]
            else:
                break
        
    return "".join(map(str,a))


output = []
for _ in range(ri()):
    output.append(str(solve()))
out(output)

Code 2:
from sys import stdin
from typing import Any
import math
input = stdin.readline
def ri(): return int(input())
def rl(v_type=int,output=list): return output(map(v_type, input().split()))
def rs(): return input().rstrip()
def out(x, sep='\n'): print(sep.join(x))


def solve():
    s = rs()
    n = len(s)
    a = list(map(int,s))
    for i in range(1,n):
        for j in range(i -1,max(-1,i - 11),-1):
            if a[j] + 1 < a[j + 1]:
                a[j],a[j+1] = a[j+1] - 1, a[j]
            else:
                break 

        
    return "".join(map(str,a))



output = []
for _ in range(ri()):
    output.append(str(solve()))
out(output)

Answer: 2