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

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

#define lli            long long int
#define ll             long long
// #define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define pb             push_back
#define all(x)         x.begin(), x.end()
#define lb             lower_bound
#define ub             upper_bound
#define ins            insert
#define sz(x)          (int)(x).size()
#define mk             make_pair
#define deci(x, y)     fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define hemant         ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define PI             3.141592653589793238
#define mem0(x)        memset(x,0,sizeof x)
#define mem1(x)        memset(x,-1,sizeof x)
#define nl              "\n"
#define yy             cout<<"YES"<<"\n"
#define nn             cout<<"NO"<<"\n"
#define vi             vector<int> 
#define vll            vector<long long>
#define vvi            vector<vector<int> >
#define ff             first
#define ss             second
#define debug(x)       cerr << #x <<" "; _print(x); cerr << endl;

typedef unsigned long long ull;
typedef long double lld;

ll modular_expo(long long x, unsigned ll y, int p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
vector<ll> sieve(ll n) {ll *arr = new ll[n + 1](); vector<ll> vect; for (ll i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (ll j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll primefactorscount(ll n){vector<ll> v1=sieve(n);ll cnt=0;for(ll i=0;i<sz(v1);i++){if(n%v1[i]==0){cnt++;}}return cnt;}
int mod_add(int a, int b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
 
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(deque <T> v);
template <class T> void _print(set <T> v);
template <class T> void _print(list <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T, class V> void _print(multimap <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(deque <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(list <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

bool isPower(ll x, ll y)
{
    long double res1 = log(y) / log(x);
    return res1==floor(res1);
}

void solve(){
    w(t){
        string s;
        cin>>s;
        int n=s.length();
        map<int, pair<int, int> > mp;
        for(int i=0;i<n-1;i++){
            // cout<<s[i]<< " ";
            int a1 = (int)s[i] - '0';
            int a2 = (int)s[i+1] - '0';
            mp[i] = make_pair(a1, a2);
        }
        // debug(mp)
        int i=0;
        int exists = 0;
        while(true){
            if (i == n-1){
                if (exists == 1){
                    i=0;
                    exists = 0;
                    continue;
                }else{
                    break;
                }
            }
            if ( i == 0){
                pair<int, int> p1 = mp[i];
                if (p1.first + 1 < p1.second){
                    int x = p1.first;
                    int y = p1.second;
                    p1.first = y - 1;
                    p1.second = x;
                    if (i + 1 < n){
                        pair<int, int> p2 = mp[i + 1];
                        p2.first = x;
                        mp[i + 1] = p2;
                        mp[i] = p1;
                        exists =1;
                    }
                }
            }
            else if( i == n-2 ){
                pair<int, int> p1 = mp[i];
                if (p1.first + 1 < p1.second){
                    int x = p1.first;
                    int y = p1.second;
                    p1.first = y - 1;
                    p1.second = x;
                    if (i - 1 >= 0){
                        pair<int, int> p2 = mp[i - 1];
                        p2.second = y-1;
                        mp[i-1] = p2;
                        mp[i] = p1;
                        exists = 1;
                    }
                }
            }
            else{
                pair<int, int> p1 = mp[i];
                if (p1.first + 1 < p1.second){
                    int x = p1.first;
                    int y = p1.second;
                    p1.first = y - 1;
                    p1.second = x;
                    if (i + 1 < n and i - 1 >=0){
                        pair<int, int> p2 = mp[i + 1];
                        pair<int, int> p3 = mp[i - 1];
                        p2.first = x;
                        p3.second = y-1;
                        mp[i-1] = p3;
                        mp[i + 1] = p2;
                        mp[i] = p1;
                        exists = 1;
                    }
                }
            }
            // debug(mp)
            i++;
        }
        // debug(mp)
        for(int i = 0; i < n; i++) {
            if(i == n - 1) {
                pair<int, int> p = mp[i - 1]; // Use i - 1 to get the last pair
                char ch1 = p.second + '0';
                cout << ch1;
            } else {
                char ch1 = mp[i].first + '0';
                cout << ch1;
            }
        }
        cout<<nl;
    }
}
int32_t main(){
    hemant;
    solve();
}

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

#define lli            long long int
#define ll             long long
// #define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define pb             push_back
#define all(x)         x.begin(), x.end()
#define lb             lower_bound
#define ub             upper_bound
#define ins            insert
#define sz(x)          (int)(x).size()
#define mk             make_pair
#define deci(x, y)     fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define hemant         ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define PI             3.141592653589793238
#define mem0(x)        memset(x,0,sizeof x)
#define mem1(x)        memset(x,-1,sizeof x)
#define nl              "\n"
#define yy             cout<<"YES"<<"\n"
#define nn             cout<<"NO"<<"\n"
#define vi             vector<int> 
#define vll            vector<long long>
#define vvi            vector<vector<int> >
#define ff             first
#define ss             second
#define debug(x)       cerr << #x <<" "; _print(x); cerr << endl;

typedef unsigned long long ull;
typedef long double lld;

ll modular_expo(long long x, unsigned ll y, int p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
vector<ll> sieve(ll n) {ll *arr = new ll[n + 1](); vector<ll> vect; for (ll i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (ll j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll primefactorscount(ll n){vector<ll> v1=sieve(n);ll cnt=0;for(ll i=0;i<sz(v1);i++){if(n%v1[i]==0){cnt++;}}return cnt;}
int mod_add(int a, int b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
 
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(deque <T> v);
template <class T> void _print(set <T> v);
template <class T> void _print(list <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T, class V> void _print(multimap <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(deque <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(list <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

bool isPower(ll x, ll y)
{
    long double res1 = log(y) / log(x);
    return res1==floor(res1);
}

void solve(){
    w(t){
        string s;
        cin>>s;
        int n=s.length();
        if (n==1){
            cout<<s<<nl;
            continue;
        }
        map<int, pair<int, int> > mp;
        for(int i=0;i<n-1;i++){
            // cout<<s[i]<< " ";
            int a1 = (int)s[i] - '0';
            int a2 = (int)s[i+1] - '0';
            mp[i] = make_pair(a1, a2);
        }
        // debug(mp)
        int i=0;
        int exists = 0;
        while(true){
            if (i == n-1){
                if (exists == 1){
                    i=0;
                    exists = 0;
                    continue;
                }else{
                    break;
                }
            }
            if ( i == 0){
                pair<int, int> p1 = mp[i];
                if (p1.first + 1 < p1.second){
                    int x = p1.first;
                    int y = p1.second;
                    p1.first = y - 1;
                    p1.second = x;
                    if (i + 1 < n){
                        pair<int, int> p2 = mp[i + 1];
                        p2.first = x;
                        mp[i + 1] = p2;
                        mp[i] = p1;
                        exists =1;
                    }
                }
            }
            else if( i == n-2 ){
                pair<int, int> p1 = mp[i];
                if (p1.first + 1 < p1.second){
                    int x = p1.first;
                    int y = p1.second;
                    p1.first = y - 1;
                    p1.second = x;
                    if (i - 1 >= 0){
                        pair<int, int> p2 = mp[i - 1];
                        p2.second = y-1;
                        mp[i-1] = p2;
                        mp[i] = p1;
                        exists = 1;
                    }
                }
            }
            else{
                pair<int, int> p1 = mp[i];
                if (p1.first + 1 < p1.second){
                    int x = p1.first;
                    int y = p1.second;
                    p1.first = y - 1;
                    p1.second = x;
                    if (i + 1 < n and i - 1 >=0){
                        pair<int, int> p2 = mp[i + 1];
                        pair<int, int> p3 = mp[i - 1];
                        p2.first = x;
                        p3.second = y-1;
                        mp[i-1] = p3;
                        mp[i + 1] = p2;
                        mp[i] = p1;
                        exists = 1;
                    }
                }
            }
            // debug(mp)
            i++;
        }
        // debug(mp)
        for(int i = 0; i < n; i++) {
            if(i == n - 1) {
                pair<int, int> p = mp[i - 1]; // Use i - 1 to get the last pair
                char ch1 = p.second + '0';
                cout << ch1;
            } else {
                char ch1 = mp[i].first + '0';
                cout << ch1;
            }
        }
        cout<<nl;
    }
}
int32_t main(){
    hemant;
    solve();
}

Answer: 2