Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h> 

using namespace std;

#define ll long long int

#define l <<endl

#define pb push_back

#define f(i,a,n) for(ll i=a;i<n;i++)

#define fastio()                  \

    ios_base::sync_with_stdio(0); \

    cin.tie(0);

#define nl << "\n"

const int MOD = 1e9 + 7;

template<const int mod>

struct mint {

    int val;

    constexpr mint(long long x = 0) : val((x % mod + mod) % mod) {}

    explicit operator int() const { return val; }

    mint& operator+=(const mint &b) { val += b.val; val -= mod * (val >= mod); return *this; }

    mint& operator-=(const mint &b) { val -= b.val; val += mod * (val < 0); return *this; }

    mint& operator*=(const mint &b) { val = 1ll * val * b.val % mod; return *this; }

    mint& operator/=(const mint &b) { return *this *= b.inv(); }

    mint inv() const { int x = 1, y = 0, t; for(int a=val, b=mod; b; swap(a, b), swap(x, y)) t = a/b, a -= t * b, x -= t * y; return mint(x); }

    mint power(int b) const { mint a = *this, res(1); for(; b; a *= a, b /= 2)  if(b & 1) res *= a; return res; }

    mint operator-() const { return val == 0 ? 0 : mod - val; }

    mint& operator++() { val = val == mod - 1 ? 0 : val + 1; return *this; }

    mint& operator--() { val = val == 0 ? mod - 1 : val - 1; return *this; }

    mint operator++(int32_t) { mint before = *this; ++*this; return before; }

    mint operator--(int32_t) { mint before = *this; --*this; return before; }

    friend mint operator+(const mint &a, const mint &b) {return mint(a) += b;}

    friend mint operator-(const mint &a, const mint &b) {return mint(a) -= b;}

    friend mint operator*(const mint &a, const mint &b) {return mint(a) *= b;}

    friend mint operator/(const mint &a, const mint &b) {return mint(a) /= b;}

    friend bool operator==(const mint &a, const mint &b) {return a.val == b.val;}

    friend bool operator!=(const mint &a, const mint &b) {return a.val != b.val;}

    friend bool operator<(const mint &a, const mint &b) {return a.val < b.val;}

    friend istream& operator>>(istream &in, mint &a) {return in >> a.val;}

    friend ostream& operator<<(ostream &os, const mint &a) {return os << a.val;}

};

using Mint = mint<MOD>;



int main()

{

    #ifndef ONLINE_JUDGE

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

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

    #endif

    fastio();

    ll t;

    cin >> t;

    while (t--)

    {

        string s;cin>>s;

        ll n=s.size();

        //sort(s.begin(),s.end());

        f(i,0,n)

        {

            ll maxi=0,mini=n;

            f(j,i,min(i+8,n))

            {

                maxi=max(maxi,(s[j]-'0')-(j-i));

            }

            f(j,i,min(i+8,n))

            {

                if((s[j]-'0')-(j-i)==maxi) mini=min(j,mini);

            } 

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

            char ch=maxi+'0';

            string s1;s1+=ch;

            s=s1+s;

        }

        reverse(s.begin(),s.end());

        //s.erase(s.begin()+0);

        //ll maxi=2;char ch=maxi+'0';

        //string s1;s1+=ch;s=s1+s;

        cout<<s l;

    }

}