ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: c++20 

Code 1:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

const int INF = 2e9;
void solve() {
    string s;
    cin >> s;
    vector<int> a;
    for(auto c : s) {
        a.push_back(c - '0');
    }

    vector<int> b;
    for(int i = 0;i < a.size(); ++i) {
        int index = -1,maxx = -INF;
        for(int j = i;j < min(i + 10, (int)a.size());++j) {
            int tmp = a[j] - (j - i);
            if(tmp > maxx) {
                maxx = tmp;
                index = j;
            }
        }
            b.push_back(maxx);

            while(index > i) {
                swap(a[index], a[index - 1]);
                index --;
            }
        }
    for(auto x : b) cout << x;
    cout << endl;
}

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



Code 2:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

const int INF = 2e9;
void solve() {
    string s;
    cin >> s;
    vector<int> a;
    for(auto c : s) {
        a.push_back(c - '0');
    }

    vector<int> b;
    for(int i = 0;i < a.size(); ++i) {
        int index = -1,maxx = -INF;
        for(int j = i;j < a.size();++j) {
            int tmp = a[j] - (j - i);
            if(tmp > maxx) {
                maxx = tmp;
                index = j;
            }
        }
            b.push_back(maxx);

            while(index > i) {
                swap(a[index], a[index - 1]);
                index --;
            }
        }
    for(auto x : b) cout << x;
    cout << endl;
}

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



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

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(x) cerr << #x << " = " << (x) << endl
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
//最大公约数
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> 
using max_heap = priority_queue<T>;
template <typename T> 
using min_heap = priority_queue<T , vector<T> , greater<>>;

constexpr int mod = 998244353;
//快速幂
ll power(ll a, ll b) {
    a %= mod;
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}




void solve(){
	string s;
	cin>>s;
	int n = s.size();
	vector<int> st;
	vector<int> cur;
	for (int i=0;i<n;i++){
		int num = s[i]-'0';
		while (!st.empty() && num>st.back()+1){
			num--;
			cur.push_back(st.back());
			st.pop_back();
		}
		st.push_back(num);
		while (!cur.empty()){
			st.push_back(cur.back());
			cur.pop_back();
		}
	}
	for (auto v:st) cout<<v;
	cout<<"\n";
}




int main(){
    fastio;
    cout << fixed << setprecision(10);
    int T;
    cin>>T;

    while (T--){
        solve();
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(x) cerr << #x << " = " << (x) << endl
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
//最大公约数
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> 
using max_heap = priority_queue<T>;
template <typename T> 
using min_heap = priority_queue<T , vector<T> , greater<>>;

constexpr int mod = 998244353;
//快速幂
ll power(ll a, ll b) {
    a %= mod;
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}




void solve(){
	string s;
	cin>>s;
	int n = s.size();
	vector<array<int,2>> st;
	vector<array<int,2>> cur;
	for (int i=0;i<n;i++){
		int num = s[i]-'0';
		while (!st.empty() && num>st.back()[0]+st.back()[1]){
			cur.push_back(st.back());
			num -= st.back()[1];
			st.pop_back();
		}
		if (!st.empty() && st.back()[0]==num){
			st[st.size()-1][1]++;
		}
		else{
			st.push_back({num,1});
		}
		while (!cur.empty()){
			auto v = cur.back();
			cur.pop_back();
			st.push_back(v);
		}
	}
	for (auto v:st){
		for (int i=0;i<v[1];i++) cout<<v[0];
	}
	cout<<"\n";
}




int main(){
    fastio;
    cout << fixed << setprecision(10);
    int T;
    cin>>T;

    while (T--){
        solve();
    }
    return 0;
}

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

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

using namespace std;



string canMakeDivisibleBy9(string s) {

    int n=s.length();

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

        if(s[i]==0) continue;

        for(int j=i;j>0;j--){

            if(s[j]-s[j-1]>1){

                swap(s[j-1],--s[j]);

            }

        }

        

    }

    return s;

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;  

        cout << (canMakeDivisibleBy9(s)) << endl;

    }

    return 0;

}



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

using namespace std;



string canMakeDivisibleBy9(string s) {

    int n=s.length();

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

        if(s[i]==0) continue;

        for(int j=i;j>0 && s[j]-s[j-1]>1;j--){

           swap(s[j-1],--s[j]);

        }

        

    }

    return s;

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;  

        cout << (canMakeDivisibleBy9(s)) << endl;

    }

    return 0;

}



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

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

int main() 
{
    int t;
    cin>>t;
    for(int m=0;m<t;m++)
    {
      
      string s;
      cin>>s;
      for(int i=0;i<s.size();i++)
      { 
        int max_index=i;
        int d=s[i]-'0';
        for(int j=i+1;j<s.size()&&j<=i+9;j++)
        {
          int x=(s[j]-'0')-(j-i);
           if(x>d)
           {
             max_index=j;
             d=x;
           }
        }
        if(max_index!=i)
        { string p=s;
          
          for(int j=i+1;j<=max_index;j++)
          {
            p[j]=s[j-1];
          }
          p[i]=d+'0';
          s=p;
          
        }
        
        
        
      }
      
      cout<<s<<endl;
      
      
      
      
    }
    return 0;
}

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

int main() 
{
    int t;
    cin>>t;
    for(int m=0;m<t;m++)
    {
      
      string s;
      cin>>s;
      for(int i=0;i<s.size();i++)
      { 
        int max_index=i;
        int d=s[i]-'0';
        int e=s.size();
        int q=min(e,i+10);
        for(int j=i+1;j<q;j++)
        {
          int x=(s[j]-'0')-(j-i);
           if(x>d)
           {
             max_index=j;
             d=x;
           }
        }
        
        while(max_index>i)
        {
          swap(s[max_index],s[max_index-1]);
          max_index--;
        }
        s[i]=d+'0';
        
        
        
      }
      
      cout<<s<<endl;
      
      
      
      
    }
    return 0;
}

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

Code 1:
#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 < min(i + 10, 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;
}

Code 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;
            // 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;
}

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

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

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

Code 2:
#include<bits/stdc++.h>
using namespace std;
char judge(string& s,int x)
{
	int ans=0,y;
	if(s.size()-x>10)
	{
		for(int i=x;i<x+10;i++)
		{
			int a=(s[i]-'0')-i+x;
			if(a>ans)
			{
				ans=a;
				y=i;
			}
		}
	}
	else
	{
		for(int i=x,len=s.size();i<len;i++)
		{
			int a=(s[i]-'0')-i+x;
			if(a>ans)
			{
				ans=a;
				y=i;
			}
		}
	}
	if(y==x) return ans+'0';
	else
	{
		for(int i=y;i>=x;i--)
		{
			char c=s[i];
			s[i]=s[i-1];
			s[i-1]=(s[i]-'0'-1)+'0';
		}
		return ans+'0';
	}
}
void sol()
{
	string s;
	string b;
	cin>>s;
	for(int i=0,len=s.size();i<len;i++)
	{
		b+=judge(s,i); 
	}
	cout<<b<<endl;
	return;
}
int main()
{
	int t;
	t=0;
	cin>>t;
	while(t--)
	{
		sol();
	}
	return 0;
}

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

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

using namespace std;

int main(){

	int t;

	cin>>t;

	while(t--){

	string a;

	cin>>a;

	for(int i=1;i<a.size();i++){

		int j=i;

		while(a[j]-1>a[j-1]&&j>0){

			swap(a[j-1],a[j]);

			a[j-1]--;

			j--;

		}

	}

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

		cout<<a[i];

	}

	cout<<endl;}

	return 0;

} 

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

using namespace std;

int main(){

	int t;

	cin>>t;

	while(t--){

	char a[200005];

	cin>>a;

	for(int i=1;i<strlen(a);i++){

		int j=i;

		while(a[j]-1>a[j-1]&&j>0){

			swap(a[j-1],a[j]);

			a[j-1]--;

			j--;

		}

	}

	for(int i=0;i<strlen(a);i++){

		cout<<a[i];

	}

	cout<<endl;}

	return 0;

} 

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

Code 1:
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){

    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n=s.length();
        set<pair<char,int>>st;
        for(int i=0;i<n;i++)st.insert({s[i],n-i});
        while(st.size()){
            auto it=*st.begin();
            char val=it.first;
            int index=n-it.second;
            int i=index;
            st.erase(it);
            if (index==n-1 || s[index+1]=='0')continue;
            int original=(s[index]-'0')*10+s[index+1]-'0';
            int rev=((s[index+1]-'0')-1)*10+(s[index]-'0');
            if (rev>original){
                st.erase({s[index+1],index+1});
                swap(s[index],s[index+1]);
                s[i]=((s[i]-'0')-1)+'0';
                st.insert({s[i],n-i});
                st.insert({s[i+1],n-(i+1)});
            }
        }
        cout<<s<<endl;
    }
    

  return 0;
}

Code 2:
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){

    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n=s.length();
        set<pair<char,int>>st;
        for(int i=0;i<n;i++)st.insert({s[i],n-i});
        string org=s;
        while(st.size()){
            auto it=*st.begin();
            char val=it.first;
            int index=n-it.second;
            int i=index;
            st.erase(it);
            if (index==n-1 || s[index+1]=='0')continue;
            int original=(s[index]-'0')*10+s[index+1]-'0';
            int rev=((s[index+1]-'0')-1)*10+(s[index]-'0');
            if (rev>original){
                st.erase({s[index+1],index+1});
                swap(s[index],s[index+1]);
                s[i]=((s[i]-'0')-1)+'0';
                st.insert({s[i],n-i});
                st.insert({s[i+1],n-(i+1)});
            }
            // cout<<s<<endl;
        }
        while(org!=s){
            org=s;
            for(int i=0;i<n;i++)st.insert({s[i],n-i});
            while(st.size()){
                auto it=*st.begin();
                char val=it.first;
                int index=n-it.second;
                int i=index;
                st.erase(it);
                if (index==n-1 || s[index+1]=='0')continue;
                int original=(s[index]-'0')*10+s[index+1]-'0';
                int rev=((s[index+1]-'0')-1)*10+(s[index]-'0');
                if (rev>original){
                    st.erase({s[index+1],index+1});
                    swap(s[index],s[index+1]);
                    s[i]=((s[i]-'0')-1)+'0';
                    st.insert({s[i],n-i});
                    st.insert({s[i+1],n-(i+1)});
                }
                // cout<<s<<endl;
            }
        }
        cout<<s<<endl;
    }
    

  return 0;
}

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

Code 1:
#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;
}

Code 2:
#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 = s[i] - '0';
        long long ind = i;
        for(long long j = i; j<min(n, j+9); j++){
            long long mx = s[i] - '0' - (j - i);
            if(mx > max){
                max = mx;
                ind = j;
            }
        }
        for(long long k = ind; k>i; k--){
            s[k] = s[k-1];
        }
        s[i] = max + '0';
    }
    cout<<s<<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;
}

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

Code 1:
#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;
}

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

void solve(){
   string s;
   cin>>s;
   vector<int>digits(s.length());
   //convert string to integer array
   for(int i=0;i<s.length;i++){
    digits[i]=s[i]-'0';
   }
   for(int i=0;i<digits.size();i++){
    int copy_i = i;
    while(copy_i>=0 && digits[copy_i]>0 && (digits[copy_i]>digits[copy_i-1])){
        int temp=digits[copy_i];
        digits[copy_i]=digits[copy_i-1];
        digits[copy_i-1]=temp-1;//***why we use this temp-1 while swqpping instead of using temp */
        if(copy_i>1){
            copy_i--;
        }else{
            break;
        }
    }
   }
   for(int d:digits){
    cout<<digits[d];
   }
}

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

Answer: 1
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(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();
    }
}

Code 2:
v#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();
    }
}

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

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

int32_t main()
{
    cin.tie(0);
    cout.sync_with_stdio(0);
    int test = 1;
    cin >> test;
    while (test--)
    {
        string a;
        cin >> a;
        int n = a.size();
        for (int i = 0; i < n; i++)
        {
            vector<int> p(9 , -1);
            for (int j = i , k = 0; j < min((int) i + 9 , n); j++ , k++)
            {
                p[k] = a[j] - '0' - k;
            }
            int mx = -1 , pos = i;
            for (int m = 0; m < 9; m++)
            {
                if (p[m] > mx)
                {
                    mx = p[m];
                    pos = i + m;
                }
            }
            if (pos != i)
            {
                char ch = a[pos];
                int d = pos - i;
                ch = (ch - '0' - d) + '0';
                a.erase(pos , 1);
                a.insert(i , 1 , ch);
            }
        }
        cout << a << endl;
    }
    return 0;
}


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

int32_t main()
{
    cin.tie(0);
    cout.sync_with_stdio(0);
    int test = 1;
    cin >> test;
    while (test--)
    {
        string a;
        cin >> a;
        int n = a.size();
        for (int i = 0; i < n; i++)
        {
            vector<int> p(8 , -1);
            for (int j = i , k = 0; j < min((int) i + 8 , n); j++ , k++)
            {
                p[k] = a[j] - '0' - k;
            }
            int mx = -1 , pos = i;
            for (int m = 0; m < 8; m++)
            {
                if (p[m] > mx)
                {
                    mx = p[m];
                    pos = i + m;
                }
            }
            if (pos != i)
            {
                char ch = a[pos];
                int d = pos - i;
                ch = (ch - '0' - d) + '0';
                a.erase(pos , 1);
                a.insert(i , 1 , ch);
            }
        }
        cout << a << endl;
    }
    return 0;
}

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

Code 1:
t= int(input())
for k in range(t):    
    a=input()
    b= len(a)
    for i in range(b):
        if i<(b-8):
            t= i+9
        else:
            t= b
        m= int(a[i])
        n=i
        for j in range(i,t):
            if (int(a[j])-j+i)> m:
                m= int(a[j])-j+i
                n= j
        a= a[0:i]+str(m)+a[i:n]+a[n+1:b]
    print(a)

Code 2:
t= int(input())
for k in range(t):    
    a=list(input())
    b= len(a)
    for i in range(b):
        t= min(i+9,b)
        m= int(a[i])
        n=i
        for j in range(i,t):
            if (int(a[j])-j+i)> m:
                m= int(a[j])-j+i
                n= j
        while n>i:
            a[n],a[n-1]= a[n-1],str(int(a[n])-1)
            n-=1
    print("".join(a))

Answer: 2