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

Previous submission (verdict: Time limit exceeded on test 1):
// /**
// *    author:  _isomorphism
// *    created: 19.12.2024 14:08:48
// **/
// 
// Problem: F. Maximum modulo equality
// 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;
//}

class SegmentTree {
private:
    vector<int> tree;
    int n;

    void build(const vector<int>& arr, int node, int start, int end) {
        if (start == end) {
            tree[node] = arr[start];
        } else {
            int mid = (start + end) / 2;
            build(arr, 2 * node + 1, start, mid);
            build(arr, 2 * node + 2, mid + 1, end);
            tree[node] = __gcd(tree[2 * node + 1], tree[2 * node + 2]);
        }
    }

    int query(int node, int start, int end, int l, int r) {
        if (r < start || end < l) {
            return 0;
        }
        if (l <= start && end <= r) {
            return tree[node];
        }
        int mid = (start + end) / 2;
        int left_sum = query(2 * node + 1, start, mid, l, r);
        int right_sum = query(2 * node + 2, mid + 1, end, l, r);
        return __gcd(left_sum, right_sum);
    }

public:
    SegmentTree(const vector<int>& arr) {
        n = arr.size();
        tree.resize(4 * n);
        build(arr, 0, 0, n - 1);
    }

    int query(int l, int r) {
        return query(0, 0, n - 1, l, r);
    }
};

void solve() {
	int n, q; cin >> n >> q;
	vector<int> a(n), dif(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n - 1; i++){
		dif[i] = abs(a[i] - a[i + 1]);
	}
	// for(int i = 0; i < dif.size(); i++) cout << dif[i] << ' ';
	// cout << endl;
	SegmentTree segTree(dif);
	while(q--){
		int l, r; cin >> l >> r;
		l--; r--; r--;
		cout << segTree.query(l, r) << ' ';
	}
}

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 && j < n; j++){
			temp = (char)((int)s[j] - j);
			if(m < temp){
				m = temp;
				idx = j;
			}
		}
		ans += m;
		s.erase(s.begin() + idx);
	}
	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;
}