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

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=1e6+7;
int n,t,m;
string b;
ll a[MAXN];
int main()
{

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>t;
	while(t--)
	{
		cin>>b;
		n=b.size();
		b=' '+b;
		for(int i=1;i<=n;i++) a[i]=b[i]-'0';
		for(int nowl=1;nowl<=n;nowl++)
		{
			int maxl=0,max_id=-1;
			for(int i=nowl;i<=min(n,nowl+10);i++)
			{
				int sss=a[i]-(i-nowl);
				// if(sss<0) break;
				if(sss>maxl) maxl=sss,max_id=i;
			}
			for(int i=max_id-1;i>=nowl;i--) swap(a[i],a[i+1]);
			a[nowl]=maxl;
		}
		for(int i=1;i<=n;i++) cout<<a[i];cout<<'\n'; 
	}
    return 0;
}
/*

1
5
1 2 3 5 4
1 2 3 4 5
A 1 3 1
A 1 3 1
A 1 3 1
A 1 3 1
*/

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=1e6+7;
int n,t,m;
string b;
ll a[MAXN];
int main()
{

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>t;
	while(t--)
	{
		cin>>b;
		n=b.size();
		b=' '+b;
		for(int i=1;i<=n;i++) a[i]=b[i]-'0';
		for(int nowl=1;nowl<=n;nowl++)
		{
			int maxl=0,max_id=-1;
			for(int i=nowl;i<=n;i++)
			{
				int sss=a[i]-(i-nowl);
				if(sss<0) break;
				if(sss>maxl) maxl=sss,max_id=i;
			}
			for(int i=max_id-1;i>=nowl;i--) swap(a[i],a[i+1]);
			a[nowl]=maxl;
		}
		for(int i=1;i<=n;i++) cout<<a[i];cout<<'\n'; 
	}
    return 0;
}
/*

1
5
1 2 3 5 4
1 2 3 4 5
A 1 3 1
A 1 3 1
A 1 3 1
A 1 3 1
*/

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

Code 1:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f first
#define s second
int32_t main()
{
    fast_io
    int t;
    cin>>t;
    while(t--)
    {
        string a;
        cin>>a;
        int n=a.size();
        for(int i=0;i<n-1;i++)
        {
            int j=min(i+9, n-1);
            int ij=i, mx=0;
            while(j!=i)
            {
                if(a[j]-(j-i)>a[i] && a[j]-(j-i)>mx)
                {
                    mx=a[j]-(j-i);
                    ij=j;
                }
                j--;
            }
            if(ij!=i){a[ij]-=(ij-i);
            swap(a[ij], a[i]);}
        }
        cout<<a<<'\n';
    }
    return 0;
}


Code 2:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f first
#define s second
int32_t main()
{
    fast_io
    int t;
    cin>>t;
    while(t--)
    {
        string a;
        cin>>a;
        int n=a.size();
        for(int i=0;i<n-1;i++)
        {
            int j=min(i+9, n-1);
            int ij=i, mx=0;
            while(j!=i)
            {
                if(i==j)break;
                if(a[j]-(j-i)>a[i] && a[j]-(j-i)>=mx)
                {
                    mx=a[j]-(j-i);
                    ij=j;
                }
                j--;
            }
            if(ij!=i)
            {
                while(1)
                {
                    if(ij==i)break;
                    a[ij]--;
                    swap(a[ij-1], a[ij]);
                    ij--;
                    }
            }
        }
        cout<<a<<'\n';
    }
    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;
	while (t--) {
		string s;
		cin >> s;
		int n = s.size();
		int a[n];
		for (int i = 0; i < n; i++) {
			a[i] = s[i] - '0' - i;
		}
		for (int i = 0; i < n; i++) {
			int m = a[i], im = i;
			for (int j = i; j < n and j < i + 10; j++) {
				if (a[j] > m) {
					im = j, m = a[j];
				}
			}
			int t, t1 = m + 1;
			for (int j = i; j <= im; j++) {
				t = a[j];
				a[j] = t1 - 1;
				t1 = t;
			}
		}
		for (int i = 0; i < n; i++) 
			cout << a[i] + i;
		cout << endl;
	}
	return 0;
}


Code 2:
#include<bits/stdc++.h>
using namespace std;
int main () {
	int t; cin >> t;
	while (t--) {
		string s;
		cin >> s;
		int n = s.size();
		int a[n];
		for (int i = 0; i < n; i++) {
			a[i] = s[i] - '0' - i;
		}
		for (int i = 0; i < n; i++) {
			int m = a[i], im = i;
			for (int j = i + 1; j < n; j++) {
				if (a[j] > m) {
					im = j, m = a[j];
				}
			}
			int t, t1 = m + 1;
			for (int j = i; j <= im; j++) {
				t = a[j];
				a[j] = t1 - 1;
				t1 = t;
			}
		}
		for (int i = 0; i < n; i++) 
			cout << a[i] + i;
		cout << endl;
	}
	return 0;
}


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

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

#define out(x) #x << " = " << x << " "
#ifndef LOCAL
#define endl "\n"
#define cerr \
	if (false) cerr
#define stdio(true) stdio(false)
#endif

const int MAX_N = 1e5 + 10;
const int INF = 1e9 + 10;

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

	for (int i = 1; i < x.size(); i++) {
		int prv = 0;
		while (i - prv - 1 >= 0 && x[i - prv] != '0' && x[i - prv] - 1 > x[i - prv - 1]) {
			x[i - prv] -= 1;
			swap(x[i - prv], x[i - prv - 1]);
			prv++;
		}
	}

	cout << x << endl;
}

int main() {
	ios_base::sync_with_stdio(true);
	cin.tie(NULL);
	cout.tie(NULL);

	int t;
	cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}

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

#define out(x) #x << " = " << x << " "
#ifndef LOCAL
#define endl "\n"
#define cerr \
	if (false) cerr
#define stdio(true) stdio(false)
#endif

const int MAX_N = 1e5 + 10;
const int INF = 1e9 + 10;

bool isBigger(const string& a, const string& b) {
	if (a.size() > b.size()) return true;
	if (a.size() < b.size()) return false;

	return a > b;
}

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

	int currentDigit = 1;

	while (currentDigit < x.size()) {
		if (currentDigit < 1) currentDigit = 1;
		if (x[currentDigit] == '0') {
			currentDigit++;
			continue;
		}

		string b = x;
		swap(b[currentDigit], b[currentDigit - 1]);
		b[currentDigit - 1]--;

		if (b > x) {
			swap(x[currentDigit], x[currentDigit - 1]);
			x[currentDigit - 1]--;
			currentDigit -= 2;
		}

		currentDigit++;
	}

	cout << x << endl;
}

int main() {
	ios_base::sync_with_stdio(true);
	cin.tie(NULL);
	cout.tie(NULL);

	int t;
	cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}

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

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

using namespace std;

#define cin(v) for (auto& i : v) cin >> i;
#define cout(v) for (auto& i : v) cout << i << " "; cout << endl;
#define endl "\n"
#define aint(a) a.begin(), a.end()
#define int long long
const int MOD = 1000000007;

void myprog();

int32_t main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int t = 1;
        cin >> t;
        while (t-- > 0)
                myprog();
        return 0;
}


void myprog(){
        string s;
        cin >> s;

        int n = s.size();
        for(int i = 1; i < n; i++){
                for(int j = i; j >= 1; j--){
                        if(s[j] > s[j - 1] + 1){
                                swap(s[j], s[j - 1]);
                                s[j - 1]--;
                                //cout << s << " ";
                        }
                }
        }

        cout << s << endl;
}

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

using namespace std;

#define cin(v) for (auto& i : v) cin >> i;
#define cout(v) for (auto& i : v) cout << i << " "; cout << endl;
#define endl "\n"
#define aint(a) a.begin(), a.end()
#define int long long
const int MOD = 1000000007;

void myprog();

int32_t main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int t = 1;
        cin >> t;
        while (t-- > 0)
                myprog();
        return 0;
}


void myprog(){
        string s;
        cin >> s;

        int n = s.size();
        for(int i = 1; i < n; i++){
                for(int j = i; j >= 1; j--){
                        if(s[j] > s[j - 1] + 1){
                                swap(s[j], s[j - 1]);
                                s[j - 1]--;
                                //cout << s << " ";
                        }
                        else{
                                break;
                        }
                }
        }

        cout << s << endl;
}

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

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

using namespace std;



int32_t main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int tc;

cin>>tc;

string s;

while(tc--){

cin>>s;

int a;

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

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

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

a = s[j]-1;

s[j] = s[j-1];

s[j-1] = a;

}else break;

}

}

cout<<s<<'\n';

}

return 0;

}



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

using namespace std;



int32_t main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int tc;

cin>>tc;

string s;

while(tc--){

cin>>s;

string a = "";

int mx, itr;

while(s.size()) {

mx = -1;

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

if ((s[i]-'0')-i>mx) {

mx = (s[i]-'0') - i;

itr = i;

if (mx>9-i-1) break;

}

}

a = a + to_string(mx);

s.erase(s.begin()+ itr);

}

cout<<a<<'\n';

}

return 0;

}



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

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

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; 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<<endl;
}
int main()
{
	int t; 
	cin >> t;
	while (t--)
	{
		solve();
	}

}

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

void solve()
{
	string s;
	cin >> s;
	int n = s.size(),j;
	for (int i = 0; i < n; i++)
	{
		int best = s[i] - '0', pos = i;
		for ( j = i; j < min(i + 10, n);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<<endl;
}
int main()
{
	int t; 
	cin >> t;
	while (t--)
	{
		solve();
	}

}

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

Code 1:
#include <iostream>

#include <string>



int main() {

std::ios_base::sync_with_stdio(false);

std::cin.tie(nullptr);



int t;

std::cin >> t;



while (t--) {

std::string s;

std::cin >> s;



bool improved = true;

while (improved) {

improved = false;



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

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



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

std::string temp = s;

temp[i]--;

std::swap(temp[i], temp[j]);



if (temp > s) {

s = temp;

improved = true;

goto found_improvement;

}

}

}

found_improvement:;

}



std::cout << s << "\n";

}



return 0;

}

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

using namespace std;



#define fastio ios::sync_with_stdio(0);cin.tie(0)



int main()

{

fastio;

long long t,n,i,j;

string s;

char cur;

cin>>t;

while(t--)

{

cin>>s;

n=s.size();

for(i=1;i<n;i++)

{

cur=s[i];

for(j=i-1;j>=0;j--)

{

if(cur<=s[j]+1)

break;

s[j+1]=s[j];

s[j]=(char)(cur-1);

cur--;

if(cur=='0')

break;

}

}

cout<<s<<"\n";

}

}

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

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

#define INF 100000000
#define ll long long int



int main(){
    int t;					cin>>t;
    while(t--){
    	string s;
    	cin>>s;
    	int n=s.size();
    	vector<int>a;
    	for(int i=0;i<n;i++){
    		a.push_back(s[i]-'0');
    	}

    	for(int i=0;i<n;i++){
            int indx=i;
            int mx= a[i];
            for(int j=i;j<=n-1;j++){
                if(a[j]-(j-i)>=0 and a[j]-(j-i)>mx){
                    mx= a[j]-(j-i);
                    indx=j;
                }
            }
            while(indx>i){
                a[indx]--;
                swap(a[indx],a[indx-1]);
                indx--;
            }
    	}
    	for(int i=0;i<n;i++){
            cout<< a[i];
    	}
    	cout<<endl;
    }
    return 0;
}



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

#define INF 100000000
#define ll long long int



int main(){
    int t;					cin>>t;
    while(t--){
    	string s;
    	cin>>s;
    	int n=s.size();
    	vector<int>a;
    	for(int i=0;i<n;i++){
    		a.push_back(s[i]-'0');
    	}

    	for(int i=0;i<n;i++){
            int indx=i;
            int mx= a[i];
            for(int j=i;j<=min(n-1, i+12);j++){
                if(a[j]-(j-i)>=0 and a[j]-(j-i)>mx){
                    mx= a[j]-(j-i);
                    indx=j;
                }
            }
            while(indx>i){
                a[indx]--;
                swap(a[indx],a[indx-1]);
                indx--;
            }
    	}
    	for(int i=0;i<n;i++){
            cout<< a[i];
    	}
    	cout<<endl;
    }
    return 0;
}



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

Code 1:
#include<bits/stdc++.h>
using namespace std;
void solve (int n){
	string s=to_string(n);
	int m=s.size();
	for(int j=0; j<m; j++){
	for(int i=1; i<m; i++){
		if(s[i]-1>0 && s[i-1]<s[i]-1){
		    int k=s[i];
		    s[i]=s[i-1];
		    s[i-1]=k-1;
		}
			
		
	}
	}
	
	
	cout<<s;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		solve(n);
		cout<<endl;
	}
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
void solve (string s){
	
	int m=s.size();
	bool flag =  true;
	while(flag){
		flag =false;
		for(int i=1; i<m; i++){
			
		if(s[i]-1>0 && s[i-1]<s[i]-1){
		    int k=s[i];
		    s[i]=s[i-1];
		    s[i-1]=k-1;
		    flag=true;
		}
			
		
	}
	}
	
	
	
	
	cout<<s;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		string s;
		cin>>s;
		solve(s);
		cout<<endl;
	}
}

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

Code 1:
def solve():
    s = input()
    s = list(s)  
    for i in range(len(s)):
        best = int(s[i])  
        pos = i  
        
        for j in range(i, min(i + 10, len(s))):
            if int(s[j]) - (j - i) > best:
                best = int(s[j]) - (j - i)
                pos = j

        while pos > i:
            s[pos], s[pos - 1] = s[pos - 1], s[pos]
            pos -= 1

        s[i] = str(best)

    print(''.join(s))


if __name__ == "__main__":
    TESTS = int(input())
    for _ in range(TESTS):
        solve()
        print()


Code 2:
n = int(input())
for _ in range(n):
    n1 = list(input())  # Convert input to a list for mutability
    length = len(n1)

    for i in range(length):
        best = int(n1[i])
        pos = i

        # Optimize the inner loop to minimize recalculations
        for j in range(i, min(i + 9, length)):
            value = int(n1[j]) - (j - i)
            if value > best:
                best = value
                pos = j

        # Perform swaps to bring the best element to the correct position
        while pos > i:
            n1[pos], n1[pos - 1] = n1[pos - 1], n1[pos]
            pos -= 1

        n1[i] = str(best)

    print("".join(n1))


Answer: 2
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 s;

cin>>s;

int n = s.size();

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

{

if(s[i]=='8' || s[i]=='9') continue;

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

int x=i;

for (int j = i+1; j < i+8; j++)

{

if(j<n && s[j]-'0'-(j-i)>best){

best=s[j]-'0'-(j-i);

x=j;

}

}

s[x]=best+'0';

while(x!=i){

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

x--;

}

}

cout<<s<<endl;

}

return 0;

}

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

using namespace std;



int main(){

int t;

cin>>t;

while(t--){

string s;

cin>>s;

int n = s.size();

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

{

if(s[i]=='8' || s[i]=='9') continue;

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

int x=i;

for (int j = i+1; j < i+9; j++)

{

if(j<n && s[j]-'0'-(j-i)>best){

best=s[j]-'0'-(j-i);

x=j;

}

}

s[x]=best+'0';

while(x!=i){

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

x--;

}

}

cout<<s<<endl;

}

return 0;

}

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

Code 1:
#include<bits/stdc++.h>
#define ll long long int 
#define INF (ll)1e18
#define mod 998244353
using namespace std;
ll pow_mod(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2)
        res=(res*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return res;
}
int main(){
    ll t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n = s.size();
        for(int i = 0 ; i < n ; i++){
            // if((s[i]-'0') == 0) {
            //     continue;
            // }
            int maxi = s[i]-'0';
            int maxi_idx = i;
            int cnt = 0;
            bool chk = false;
            for(int j = i+1 ; j < min(i+9,n) ; j++){
                cnt++;
                if(maxi < ((s[j]-'0')-cnt)){
                    chk = true;
                    maxi = (s[j]-'0')-cnt;
                    maxi_idx = j;
                    //cout<<maxi<<"  "<<maxi_idx<<endl;
                }
            }
            if(chk){
                //cout<<maxi<<"  "<<maxi_idx<<"  "<<cnt<<endl;
                char val = '0'+maxi;
                //cout<<val<<endl;
                for(int j = maxi_idx ; j >= i ; j--){
                    if(j-1 >= 0) s[j] = s[j-1];
                }
                s[i] = val;
            }
            //cout<<s<<endl;
        }
        cout<<s<<endl;
    }
    return 0;
}

Code 2:
#include<bits/stdc++.h>
#define ll long long int 
#define INF (ll)1e18
#define mod 998244353
using namespace std;
ll pow_mod(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2)
        res=(res*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return res;
}
int main(){
    ll t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n = s.size();
        for(int i = 0 ; i < n ; i++){
            if((s[i]-'0') == 0) {
                continue;
            }
            int maxi = s[i]-'0';
            int maxi_idx = i;
            int cnt = 0;
            bool chk = false;
            for(int j = i+1 ; j < min(i+9,n) ; j++){
                cnt++;
                if(maxi < ((s[j]-'0')-cnt)){
                    chk = true;
                    maxi = (s[j]-'0')-cnt;
                    maxi_idx = j;
                }
            }
            if(chk){
                //cout<<maxi<<"  "<<maxi_idx<<"  "<<cnt<<endl;
                char val = '0'+maxi;
                //cout<<val<<endl;
                for(int j = maxi_idx ; j >= i ; j--){
                    if(j-1 >= 0) s[j] = s[j-1];
                }
                s[i] = val;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}

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

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



using namespace std;



#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace __gnu_pbds;

#define ll long long

#define order_set tree < pair<ll,ll> ,  null_type ,  less<pair<ll,ll>> ,  rb_tree_tag ,  tree_order_statistics_node_update >

const ll MAX = 1e18;

const int N = 2e5 + 100;

const ll mod = 1e9 + 7;

ll n, m, k;

string s;

//----------------------------------------------------------------------------------------------------



void solve() {

cin >> s;

n = s.size();

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

ll ok = -1;

char z = s[i];

for (int j = i + 1; j < min(n, n + 10); ++j) {

if (z < (s[j] - (j - i))) {

ok = j;

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

}

}

if (ok > -1) {

s[ok] = z;

}

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

}

cout << s << '\n';





}



//---------------------------------------------------------------------------------------------------

int main() {

ios::sync_with_stdio(NULL);

cin.tie(0);

cout.tie(0);

#ifndef ONLINE_JUDGE

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

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

#endif

int t = 1;

cin >> t;

for (int i = 1; i <= t; i++) {

solve();

}

return 0;

}

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



using namespace std;



#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace __gnu_pbds;

#define ll long long

#define order_set tree < pair<ll,ll> ,  null_type ,  less<pair<ll,ll>> ,  rb_tree_tag ,  tree_order_statistics_node_update >

const ll MAX = 1e18;

const int N = 2e5 + 100;

const ll mod = 1e9 + 7;

ll n, m, k;

string s;

//----------------------------------------------------------------------------------------------------



void solve() {

cin >> s;

n = s.size();

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

ll ok = -1;

char z = s[i];

for (int j = i + 1; j < min(n, i + 10ll); ++j) {

if (z < (s[j] - (j - i))) {

ok = j;

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

}

}

if (ok > -1) {

s[ok] = z;

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

}

}

cout << s << '\n';





}



//---------------------------------------------------------------------------------------------------

int main() {

ios::sync_with_stdio(NULL);

cin.tie(0);

cout.tie(0);

#ifndef ONLINE_JUDGE

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

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

#endif

int t = 1;

cin >> t;

for (int i = 1; i <= t; i++) {

solve();

}

return 0;

}

Answer: 2
Problem: 2050E - Three Strings
Language: c++23 

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

#define ll long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int n = s.size();
        for (int i = 0; i < n; i++)
        {
            char ch = s[i];
            int j = i - 1;
            while (j >= 0 and s[j] - '0' < (s[j + 1] - '0') - 1)
            {
                s[j + 1] = s[j + 1] - 1;
                swap(s[j + 1], s[j]);
                j--;
            }
        }
            cout << s << '\n';
    }
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
string a, b, c;
const int N = 3e3 + 5;
int dp[N][N];
int na, nb, nc;
int fun(int i, int j)
{
    if (i == na and j == nb)
        return 0;
    if (i == na)
    {
        int count = 0;
        for (int k = j; k < nb; k++)
        {
            if (b[k] != c[i + k])
                count++;
        }
        return count;
    }
    if (j == nb)
    {
        int count = 0;
        for (int k = i; k < na; k++)
        {
            if (a[k] != c[j + k])
                count++;
        }
        return count;
    }
    if (dp[i][j] != -1)
        return dp[i][j];
    int ans;
    if (a[i] == c[j + i])
        ans = fun(i + 1, j);
    else
        ans = 1 + fun(i + 1, j);
    if (b[j] == c[i + j])
        ans = min(ans, fun(i, j + 1));
    else
        ans = min(ans, 1 + fun(i, j + 1));
    return dp[i][j] = ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        cin >> a >> b >> c;
        na = a.size();
        nb = b.size();
        nc = c.size();
        f(i, nc + 10)
        {
            f(j, nc + 10)
            {
                dp[i][j] = -1;
            }
        }
        cout << fun(0, 0) << '\n';
    }
}

Answer: 2