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

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ld = long double;

#define int long long
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define vi vector<int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fr(i, n) for (int i = 0; i < n; i++)

void ssort(string &s)
{
    int n = s.size();

    if (n == 1)
    {
        return;
    }

    string a, b;
    fr(i, n / 2)
    {
        a.push_back(s[i]);
    }
    for (int i = n / 2; i < n; i++)
    {
        b.push_back(s[i]);
    }

    ssort(a);
    ssort(b);

    int ai = 0, bi = 0, i = 0;
    while (ai < a.size() && bi < b.size())
    {
        if (b[bi] - (a.size() + bi - i) > a[ai])
        {
            s[i++] = b[bi] - (a.size() + bi - i);
            bi++;
        }
        else
        {
            s[i++] = a[ai++];
        }
    }

    while (ai < a.size())
    {
        s[i++] = a[ai++];
    }
    while (bi < b.size())
    {
        s[i++] = b[bi++];
    }

    // for (auto x : a)
    // {
    //     cout << x;
    // }
    // cout << endl;

    // for (auto x : b)
    // {
    //     cout << x;
    // }
    // cout << endl;
}

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

    ssort(s);
    cout << s << '\n';
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;
using ld = long double;

#define int long long
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define vi vector<int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fr(i, n) for (int i = 0; i < n; i++)

void ssort(string &s)
{
    int n = s.size();

    if (n == 1 || n == 0)
    {
        return;
    }

    string a = s.substr(0, n / 2);
    string b = s.substr(n / 2, n - n / 2);

    ssort(a);
    ssort(b);

    int ai = 0, bi = 0, i = 0;
    while (ai < a.size() && bi < b.size())
    {
        if (b[bi] - (a.size() + bi - i) > a[ai])
        {
            s[i++] = b[bi] - (a.size() + bi - i);
            bi++;
        }
        else
        {
            s[i++] = a[ai++];
        }
    }

    while (ai < a.size())
    {
        s[i++] = a[ai++];
    }
    while (bi < b.size())
    {
        s[i++] = b[bi++];
    }

    // for (auto x : a)
    // {
    //     cout << x;
    // }
    // cout << endl;

    // for (auto x : b)
    // {
    //     cout << x;
    // }
    // cout << endl;
}

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

    ssort(s);
    cout << s << '\n';
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}