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

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

long long m=1000000007;

long long  power(int x, unsigned int y)
{
    long long  temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return ((temp%m) * (temp%m))%m;
    else
        return  (x%m * temp%m * temp%m)%m;
}
void solv() {
    int n ,m,k;
    cin >> n >> m >> k;
    int a[m];
    int b[k];
    for(int i = 0 ; i < m ; i++) cin>>a[i];
    for(int i = 0 ; i < k ; i++) cin>>b[i];
    string ans="";
    if(n-k >1){
      for(int i = 0 ; i < m ; i++) ans+='0';
      cout << ans << endl;
      return;
    }
    if(k==n){
      for(int i = 0 ; i < m ; i++) ans+='1';
      cout << ans << endl;
      return;
    }
    int miss=1;
    for(int i = 0 ; i < k ; i++) {
       if(b[i] != miss) break;
       else{
        miss++;
       }
    }
    for(int i =0 ;i < m ;i++){
      if(a[i] == miss) ans+='1';
      else ans+='0';
    }
    cout << ans <<endl;
 
}

vector<int> storePrime(){
        int n = 1000;
        vector<bool> prime(n+1,1);
        for(int i = 2;i<=n;i++){
            if(prime[i]){
                for(int j = 2*i;j<=n;j+=i){
                    prime[i] = 0;
                }
            }
        }
        vector<int> ans;
        for(int i = 2;i<=n;i++){
            if(prime[i])    ans.push_back(i);
        }
        return ans;
    }

	int binary(long long arr[],long long n,long long k,int y)
	{
		int s=0,e=n-1;
		int mid=s+(e-s)/2;
		while(s<e)
		{
			
			if(arr[mid]==y && mid!=k)
			return arr[mid];
			else
			e--;
			if(arr[mid]<y)
			{
				s=mid+1;
			}
			if(arr[mid]>y)
			e=mid-1;

			mid=s+(e-s)/2;
		}
		return 0;
	}

int main () {
	 #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

	int t;
	cin>>t;
	while(t--)
    {
		int x;
        long long sum=0;
        string s;
        cin>>s;
        long long th=0,tw=0;
        x=s.length()-1;

        for(int i=s.length()-1;i>=1;i--)
        {
            if(s[i]-'0'>s[i-1]+1-'0')
            {
                s[i]--;
                swap(s[i],s[i-1]);
                i+=2;
            }

           
        }
        
       
        cout<<s<<endl;
        

    }
	
}


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

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#define endl '\n'

#define int long long

using namespace std;

const int N=4e2+10;

typedef long long ll;

int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

int n,m;

int a[N][N];

int d[N];

queue<char> q;

string s;

void solved()

{

	string s;

	cin>>s;

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

	{

		int r=i,l=i-1;

		//cout<<r<<' '<<l<<endl;

		char x=s[r],y=s[l];

		//cout<<x--<<' '<<y<<endl;

		while((x)>y+1&&l>=0)

		{

			//cout<<s[r]--<<' '<<s[l]<<endl;

			s[r]--;

			x=s[r];

			swap(s[r],s[l]);

			r--;

			l--;

			y=s[l];

			//x--;

			//cout<<s<<endl;

			//cout<<x--<<' '<<y<<' '<<l<<endl;

		}

	}

	cout<<s<<endl;

}

signed main()

{

    IOS;

    int t=1;

    cin>>t;

    

    //cout<<t<<endl;

    while(t--)

    {

        solved();

        //cout<<endl;

    }

    //cout<<endl;

}