Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 2):
// /**
// *    author:  _isomorphism
// *    created: 19.12.2024 16:30:22
// **/
// 
// Problem: D. Digital string maximization
// Contest: Codeforces - Codeforces Round 991 (Div. 3)


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)2e18
#define endl '\n'

const int mod = 1e9 + 7;
const int MOD = 998244353;

vector<int> binrep(int n) {
  if (n == 0)
    return {0};
  vector<int> b;
  while (n > 0) {
    b.insert(b.begin(), n % 2);
    n /= 2;
  }
  return b;
}

int binpow(int base, int exp, int m) {
  int result = 1;
  base = base % m;
  while (exp > 0) {
    if (exp % 2 == 1) {
      result = (result * base) % m;
    }
    base = (base * base) % m;
    exp = exp / 2;
  }
  return result;
}


//bool check(int x){
//
//}
//
//int search(int k) {
//  int pos = 0, max = INF;
//  for (int i = max; i >= 1; i /= 2) {
//    while (check(pos + i)) pos += i;
//  }
//  return pos;
//}
//
//int search(int k) {
//    int low = 0, high = INF, ans = -1;
//    while (low <= high) {
//        int mid = low + (high - low) / 2;
//        if (check(mid)) {
//            ans = mid;
//            high = mid - 1;
//        } else {
//            low = mid + 1;
//        }
//    }
//    return ans;
//}

void solve() {
	string s; cin >> s;
	int n = s.length();
	int idx = 0;
	char m = '0', temp;
	string ans = "";
	for(int i = 0; i < n; i++){
		m = '0';
		for(int j = 0; j < 9 && j < n; j++){
			temp = (char)((int)s[j] - j);
			if(m < temp){
				m = temp;
				idx = j;
			}
		}
		ans += m;
		s.erase(s.begin() + idx);
		n--;
		i--;
	}
	cout << ans;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int test = 1;
  cin >> test;

  while (test--) {
    solve();
    cout << '\n';
  }
  return 0;
}

Submission (verdict: Runtime error on test 2):
// /**
// *    author:  _isomorphism
// *    created: 19.12.2024 16:30:22
// **/
// 
// Problem: D. Digital string maximization
// Contest: Codeforces - Codeforces Round 991 (Div. 3)


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)2e18
#define endl '\n'

const int mod = 1e9 + 7;
const int MOD = 998244353;

vector<int> binrep(int n) {
  if (n == 0)
    return {0};
  vector<int> b;
  while (n > 0) {
    b.insert(b.begin(), n % 2);
    n /= 2;
  }
  return b;
}

int binpow(int base, int exp, int m) {
  int result = 1;
  base = base % m;
  while (exp > 0) {
    if (exp % 2 == 1) {
      result = (result * base) % m;
    }
    base = (base * base) % m;
    exp = exp / 2;
  }
  return result;
}


//bool check(int x){
//
//}
//
//int search(int k) {
//  int pos = 0, max = INF;
//  for (int i = max; i >= 1; i /= 2) {
//    while (check(pos + i)) pos += i;
//  }
//  return pos;
//}
//
//int search(int k) {
//    int low = 0, high = INF, ans = -1;
//    while (low <= high) {
//        int mid = low + (high - low) / 2;
//        if (check(mid)) {
//            ans = mid;
//            high = mid - 1;
//        } else {
//            low = mid + 1;
//        }
//    }
//    return ans;
//}

void solve() {
    string s;
    cin >> s;
    int n = s.length();
    int idx = 0;
    char m = '0', temp;
    string ans = "";
    for (int i = 0; i < n; i++) {
        m = '0';
        for (int j = 0; j < 9 && i + j < n; j++) {
            temp = (char)((int)s[i + j] - j);
            if (m < temp) {
                m = temp;
                idx = i + j;
            }
        }
        ans += m;
        s.erase(s.begin() + idx);
        n--; i--;
    }
    cout << ans;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int test = 1;
  cin >> test;

  while (test--) {
    solve();
    cout << '\n';
  }
  return 0;
}