ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 7):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'
const ll mod = 998244353;
const int N = 2e5+10;
int head[200005],flag,du[200005];
struct node {
	int to,next;
} p[200005];
void add(int x,int y) {
	p[++flag].to=y;
	p[flag].next=head[x];
	head[x]=flag;
}
struct node1 {
	int a,b;
	friend bool operator <(node1 a,node1 b) {
		return a.b>b.b;
	}
};
int main() {
	//fastio;
	int T;
	cin>>T;
	while(T--) {
		int n;
		cin>>n;
		flag=0;
		for(int i=1; i<=n; i++) du[i]=0,head[i]=0;
		int mx1=0,num1=0,mx2=0,num2=0;
		for(int i=1; i<=n-1; i++) {
			int a,b;
			cin>>a>>b;
			add(a,b);
			add(b,a);
			du[a]++;
			du[b]++;
		}
		for(int i=1;i<=n;i++){
			if(du[i]>mx1) {
				mx2=mx1;
				mx1=du[i];
			}
			else if(du[i]>mx2) mx2=du[i]; 
		}
		for(int i=1;i<=n;i++){
			if(du[i]==mx1)num1++;
			else if(du[i]==mx2) num2++;
		}
		int ans=0;
		if(num1==1) {
			for(int i=1; i<=n; i++) {
				if(du[i]!=mx1) continue;
				int temp=num2;
				for(int t=head[i]; t; t=p[t].next) {
					if(du[p[t].to]==mx2) temp--;
				}
				if(temp==0) ans=mx1+mx2-2;
				else ans=mx1+mx2-1;
			}
			
		}
		else{
			for(int i=1; i<=n; i++) {
				if(du[i]!=mx1) continue;
				int temp=num1;
				ans=mx1+mx1-2;
				for(int t=head[i]; t; t=p[t].next) {
					if(du[p[t].to]==mx1) temp--;
				}
				if(temp!=1){
					ans++;
					break;
				}
			}
		}
		

		cout<<ans<<endl;
	}
	return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'
const ll mod = 998244353;
const int N = 2e5+10;
int head[200005],flag,du[200005];
struct node {
	int to,next;
} p[400005];
void add(int x,int y) {
	p[++flag].to=y;
	p[flag].next=head[x];
	head[x]=flag;
}
struct node1 {
	int a,b;
	friend bool operator <(node1 a,node1 b) {
		return a.b>b.b;
	}
};
int main() {
	//fastio;
	int T;
	cin>>T;
	while(T--) {
		int n;
		cin>>n;
		flag=0;
		for(int i=1; i<=n; i++) du[i]=0,head[i]=0;
		int mx1=0,num1=0,mx2=0,num2=0;
		for(int i=1; i<=n-1; i++) {
			int a,b;
			cin>>a>>b;
			add(a,b);
			add(b,a);
			du[a]++;
			du[b]++;
		}
		for(int i=1;i<=n;i++){
			if(du[i]>mx1) {
				mx2=mx1;
				mx1=du[i];
			}
			else if(du[i]>mx2) mx2=du[i]; 
		}
		for(int i=1;i<=n;i++){
			if(du[i]==mx1)num1++;
			else if(du[i]==mx2) num2++;
		}
		int ans=0;
		if(num1==1) {
			for(int i=1; i<=n; i++) {
				if(du[i]!=mx1) continue;
				int temp=num2;
				for(int t=head[i]; t; t=p[t].next) {
					if(du[p[t].to]==mx2) temp--;
				}
				if(temp==0) ans=mx1+mx2-2;
				else ans=mx1+mx2-1;
			}
			
		}
		else{
			for(int i=1; i<=n; i++) {
				if(du[i]!=mx1) continue;
				int temp=num1;
				ans=mx1+mx1-2;
				for(int t=head[i]; t; t=p[t].next) {
					if(du[p[t].to]==mx1) temp--;
				}
				if(temp!=1){
					ans++;
					break;
				}
			}
		}
		

		cout<<ans<<endl;
	}
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'
const ll mod = 998244353;
const int N = 2e5+10;
int head[200005],flag,du[200005];
struct node {
	int to,next;
} p[200005];
void add(int x,int y) {
	p[++flag].to=y;
	p[flag].next=head[x];
	head[x]=flag;
}
struct node1 {
	int a,b;
	friend bool operator <(node1 a,node1 b) {
		return a.b>b.b;
	}
};
int main() {
	//fastio;
	int T;
	cin>>T;
	while(T--) {
		int n;
		cin>>n;
		flag=0;
		for(int i=1; i<=n; i++) du[i]=0,head[i]=0;
		int mx1=0,num1=0,mx2=0,num2=0;
		for(int i=1; i<=n-1; i++) {
			int a,b;
			cin>>a>>b;
			add(a,b);
			add(b,a);
			du[a]++;
			du[b]++;
		}
		for(int i=1;i<=n;i++){
			if(du[i]>mx1) {
				mx2=mx1;
				mx1=du[i];
			}
		}
		for(int i=1;i<=n;i++){
			if(du[i]==mx1)num1++;
			else if(du[i]==mx2) num2++;
		}
		int ans=0;
		if(num1==1) {
			for(int i=1; i<=n; i++) {
				if(du[i]!=mx1) continue;
				int temp=num2;
				for(int t=head[i]; t; t=p[t].next) {
					if(du[p[t].to]==mx2) temp--;
				}
				if(temp==0) ans=mx1+mx2-2;
				else ans=mx1+mx2-1;
			}
			
		}
		else{
			for(int i=1; i<=n; i++) {
				if(du[i]!=mx1) continue;
				int temp=num1;
				ans=mx1+mx1-2;
				for(int t=head[i]; t; t=p[t].next) {
					if(du[p[t].to]==mx1) temp--;
				}
				if(temp!=1){
					ans++;
					break;
				}
			}
		}
		

		cout<<ans<<endl;
	}
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'
const ll mod = 998244353;
const int N = 2e5+10;
int head[200005],flag,du[200005];
struct node {
	int to,next;
} p[200005];
void add(int x,int y) {
	p[++flag].to=y;
	p[flag].next=head[x];
	head[x]=flag;
}
struct node1 {
	int a,b;
	friend bool operator <(node1 a,node1 b) {
		return a.b>b.b;
	}
};
int main() {
	//fastio;
	int T;
	cin>>T;
	while(T--) {
		int n;
		cin>>n;
		flag=0;
		for(int i=1; i<=n; i++) du[i]=0,head[i]=0;
		int mx1=0,num1=0,mx2=0,num2=0;
		for(int i=1; i<=n-1; i++) {
			int a,b;
			cin>>a>>b;
			add(a,b);
			add(b,a);
			du[a]++;
			du[b]++;
		}
		for(int i=1;i<=n;i++){
			if(du[i]>mx1) {
				mx2=mx1;
				mx1=du[i];
			}
		}
		for(int i=1;i<=n;i++){
			if(du[i]==mx1)num1++;
			else if(du[i]==mx2) num2++;
		}
		int ans=0;
		if(num1==1) {
			for(int i=1; i<=n; i++) {
				if(du[i]!=mx1) continue;
				int temp=num2;
				for(int t=head[i]; t; t=p[t].next) {
					if(du[p[t].to]==mx2) temp--;
				}
				if(temp==0) ans=mx1+mx2-2;
				else ans=mx1+mx2-1;
			}
			
		}
		else{
			for(int i=1; i<=n; i++) {
				if(du[i]!=mx1) continue;
				int temp=num1;
				ans=mx1+mx1-2;
				for(int t=head[i]; t; t=p[t].next) {
					if(du[p[t].to]==mx1) temp--;
				}
				if(temp!=1){
					ans++;
					break;
				}
			}
		}
		

		cout<<ans<<endl;
	}
	return 0;
}


Submission (verdict: Wrong answer on test 7):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'
const ll mod = 998244353;
const int N = 2e5+10;
int head[200005],flag,du[200005];
struct node {
	int to,next;
} p[200005];
void add(int x,int y) {
	p[++flag].to=y;
	p[flag].next=head[x];
	head[x]=flag;
}
struct node1 {
	int a,b;
	friend bool operator <(node1 a,node1 b) {
		return a.b>b.b;
	}
};
int main() {
	//fastio;
	int T;
	cin>>T;
	while(T--) {
		int n;
		cin>>n;
		flag=0;
		for(int i=1; i<=n; i++) du[i]=0,head[i]=0;
		int mx1=0,num1=0,mx2=0,num2=0;
		for(int i=1; i<=n-1; i++) {
			int a,b;
			cin>>a>>b;
			add(a,b);
			add(b,a);
			du[a]++;
			du[b]++;
		}
		for(int i=1;i<=n;i++){
			if(du[i]>mx1) {
				mx2=mx1;
				mx1=du[i];
			}
			else if(du[i]>mx2) mx2=du[i]; 
		}
		for(int i=1;i<=n;i++){
			if(du[i]==mx1)num1++;
			else if(du[i]==mx2) num2++;
		}
		int ans=0;
		if(num1==1) {
			for(int i=1; i<=n; i++) {
				if(du[i]!=mx1) continue;
				int temp=num2;
				for(int t=head[i]; t; t=p[t].next) {
					if(du[p[t].to]==mx2) temp--;
				}
				if(temp==0) ans=mx1+mx2-2;
				else ans=mx1+mx2-1;
			}
			
		}
		else{
			for(int i=1; i<=n; i++) {
				if(du[i]!=mx1) continue;
				int temp=num1;
				ans=mx1+mx1-2;
				for(int t=head[i]; t; t=p[t].next) {
					if(du[p[t].to]==mx1) temp--;
				}
				if(temp!=1){
					ans++;
					break;
				}
			}
		}
		

		cout<<ans<<endl;
	}
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
/**
 * created: 2025-02-24 17:16:34
 **/

#include <bits/stdc++.h>
using namespace std; 

#define ll long long
#define ld long double
#define log(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<class T, class ...Vals>
void logger(T names, Vals&&... values){
  cout << names << " = ";
  string delimiter = "";
  (..., (cout << delimiter << values, delimiter = ", "));
  cout << '\n';
}

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
// const int MOD = 998244353;

void boost(){ ios_base::sync_with_stdio(0); cin.tie(0); }

template<class T, class U> void logv(vector<pair<T,U>> x){
  for (int i = 0; i < x.size(); i++){
    cout << x[i].first << " " << x[i].second << '\n';
  }
}

template<class T> void logv(vector<T> x){
  for (int i = 0; i < x.size(); i++){
    cout << x[i] << " ";
  }
  cout << '\n';
}

void solve_val(int base, int l, int r){
  int msb=31;
  for (; msb >= 0; --msb){
    if ((r>>msb)&1){
      break;
    }
  }
  if ((l>>msb)&1){
    l -= (1<<msb);
    r -= (1<<msb);
    solve_val(base+(1<<msb), l,r);
  }
  int a1=(1<<msb);
  int a2=a1-1;
  int a3=l;
  cout << (base+a1) << " " << (base+a2) << " " << (base+a3) << "\n";
}

void solve(){
  int l,r; cin >> l >> r;
  solve_val(0,l,r);
}

int32_t main(){
  boost();
  int t;
  cin >> t;
  while(t--){
    solve();
  }
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
/**
 * created: 2025-02-24 17:16:34
 **/

#include <bits/stdc++.h>
using namespace std; 

#define ll long long
#define ld long double
#define log(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<class T, class ...Vals>
void logger(T names, Vals&&... values){
  cout << names << " = ";
  string delimiter = "";
  (..., (cout << delimiter << values, delimiter = ", "));
  cout << '\n';
}

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
// const int MOD = 998244353;

void boost(){ ios_base::sync_with_stdio(0); cin.tie(0); }

template<class T, class U> void logv(vector<pair<T,U>> x){
  for (int i = 0; i < x.size(); i++){
    cout << x[i].first << " " << x[i].second << '\n';
  }
}

template<class T> void logv(vector<T> x){
  for (int i = 0; i < x.size(); i++){
    cout << x[i] << " ";
  }
  cout << '\n';
}

void solve_val(int base, int l, int r){
  int msb=31;
  for (; msb >= 0; --msb){
    if ((r>>msb)&1){
      break;
    }
  }
  if ((l>>msb)&1){
    l -= (1<<msb);
    r -= (1<<msb);
    solve_val(base+(1<<msb), l,r);
  }
  int a1=(1<<msb);
  int a2=a1-1;
  int a3=l;
  cout << (base+a1) << " " << (base+a2) << " " << (base+a3) << "\n";
}

void solve(){
  int l,r; cin >> l >> r;
  solve_val(0,l,r);
}

int32_t main(){
  boost();
  int t;
  cin >> t;
  while(t--){
    solve();
  }
}



Submission (verdict: Wrong answer on test 1):
/**
 * created: 2025-02-24 17:16:34
 **/

#include <bits/stdc++.h>
using namespace std; 

#define ll long long
#define ld long double
#define log(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<class T, class ...Vals>
void logger(T names, Vals&&... values){
  cout << names << " = ";
  string delimiter = "";
  (..., (cout << delimiter << values, delimiter = ", "));
  cout << '\n';
}

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
// const int MOD = 998244353;

void boost(){ ios_base::sync_with_stdio(0); cin.tie(0); }

template<class T, class U> void logv(vector<pair<T,U>> x){
  for (int i = 0; i < x.size(); i++){
    cout << x[i].first << " " << x[i].second << '\n';
  }
}

template<class T> void logv(vector<T> x){
  for (int i = 0; i < x.size(); i++){
    cout << x[i] << " ";
  }
  cout << '\n';
}

void solve_val(int base, int l, int r){
  int msb=31;
  for (; msb >= 0; --msb){
    if ((r>>msb)&1){
      break;
    }
  }
  if ((l>>msb)&1){
    l -= (1<<msb);
    r -= (1<<msb);
    solve_val(base+(1<<msb), l,r);
  }
  int a1=(1<<msb);
  int a2=a1-1;
  int a3=l;
  if (a2==a3){
    a3=r;
  }
  cout << (base+a1) << " " << (base+a2) << " " << (base+a3) << "\n";
}

void solve(){
  int l,r; cin >> l >> r;
  solve_val(0,l,r);
}

int32_t main(){
  boost();
  int t;
  cin >> t;
  while(t--){
    solve();
  }
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
/**
 * created: 2025-02-24 17:16:34
 **/

#include <bits/stdc++.h>
using namespace std; 

#define ll long long
#define ld long double
#define log(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<class T, class ...Vals>
void logger(T names, Vals&&... values){
  cout << names << " = ";
  string delimiter = "";
  (..., (cout << delimiter << values, delimiter = ", "));
  cout << '\n';
}

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
// const int MOD = 998244353;

void boost(){ ios_base::sync_with_stdio(0); cin.tie(0); }

template<class T, class U> void logv(vector<pair<T,U>> x){
  for (int i = 0; i < x.size(); i++){
    cout << x[i].first << " " << x[i].second << '\n';
  }
}

template<class T> void logv(vector<T> x){
  for (int i = 0; i < x.size(); i++){
    cout << x[i] << " ";
  }
  cout << '\n';
}

void solve_val(int base, int l, int r){
  int msb=31;
  for (; msb >= 0; --msb){
    if ((r>>msb)&1){
      break;
    }
  }
  if ((l>>msb)&1){
    l -= (1<<msb);
    r -= (1<<msb);
    solve_val(base+(1<<msb), l,r);
  }
  int a1=(1<<msb);
  int a2=a1-1;
  int a3=l;
  if (a2==a3){
    a3=r;
  }
  cout << (base+a1) << " " << (base+a2) << " " << (base+a3) << "\n";
}

void solve(){
  int l,r; cin >> l >> r;
  solve_val(0,l,r);
}

int32_t main(){
  boost();
  int t;
  cin >> t;
  while(t--){
    solve();
  }
}



Submission (verdict: Accepted):
/**
 * created: 2025-02-24 17:16:34
 **/

#include <bits/stdc++.h>
using namespace std; 

#define ll long long
#define ld long double
#define log(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<class T, class ...Vals>
void logger(T names, Vals&&... values){
  cout << names << " = ";
  string delimiter = "";
  (..., (cout << delimiter << values, delimiter = ", "));
  cout << '\n';
}

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
// const int MOD = 998244353;

void boost(){ ios_base::sync_with_stdio(0); cin.tie(0); }

template<class T, class U> void logv(vector<pair<T,U>> x){
  for (int i = 0; i < x.size(); i++){
    cout << x[i].first << " " << x[i].second << '\n';
  }
}

template<class T> void logv(vector<T> x){
  for (int i = 0; i < x.size(); i++){
    cout << x[i] << " ";
  }
  cout << '\n';
}

void solve_val(int base, int l, int r){
  int msb=31;
  for (; msb >= 0; --msb){
    if ((r>>msb)&1){
      break;
    }
  }
  if ((l>>msb)&1){
    l -= (1<<msb);
    r -= (1<<msb);
    solve_val(base+(1<<msb), l,r);
    return;
  }
  int a1=(1<<msb);
  int a2=a1-1;
  int a3=l;
  if (a2==a3){
    a3=r;
  }
  cout << (base+a1) << " " << (base+a2) << " " << (base+a3) << "\n";
}

void solve(){
  int l,r; cin >> l >> r;
  solve_val(0,l,r);
}

int32_t main(){
  boost();
  int t;
  cin >> t;
  while(t--){
    solve();
  }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;

using dqi = deque<int>;
using vi = vector<int>;
using mii = unordered_map<int, int>;
using mip = unordered_map<int, pair<int, int>>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using spii = set<pair<int, int>>;
using ll = long long;

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

    for (int i = 0; i < num.size(); i++)
    {
        int max = 0;
        int ind = 0;
        for (int j = i + 1; j < num.size(); j++)
        {
            if (num[j] == '0')
                continue;
            int nn = num[j] - '0' - j + i;
            if (nn > max && nn > (num[i] - '0'))
            {
                max = nn;
                ind = j;
            }
        }
        if (max > 0)
        {
            num = num.substr(0, i) + to_string(max) + num.substr(i, ind - i) + num.substr(ind + 1);
        }
    }
    cout << num << endl;
}

int main()
{
    ll t;
    cin >> t;
    for (ll i = 0; i < t; i++)
        solve();

    return 0;
}


Submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>

using namespace std;

using dqi = deque<int>;
using vi = vector<int>;
using mii = unordered_map<int, int>;
using mip = unordered_map<int, pair<int, int>>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using spii = set<pair<int, int>>;
using ll = long long;

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

    for (int i = 0; i < num.size(); i++)
    {
        int max = 0;
        int ind = 0;
        for (int j = i + 1; j < min(i + 10, (int)num.size()); j++)
        {
            if (num[j] == '0')
                continue;
            int nn = num[j] - '0' - j + i;
            if (nn > max && nn > (num[i] - '0'))
            {
                max = nn;
                ind = j;
            }
        }
        if (max > 0)
        {
            num = num.substr(0, i) + to_string(max) + num.substr(i, ind - i) + num.substr(ind + 1);
        }
    }
    cout << num << endl;
}

int main()
{
    ll t;
    cin >> t;
    for (ll i = 0; i < t; i++)
        solve();

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

using dqi = deque<int>;
using vi = vector<int>;
using mii = unordered_map<int, int>;
using mip = unordered_map<int, pair<int, int>>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using spii = set<pair<int, int>>;
using ll = long long;

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

    for (int i = 0; i < num.size(); i++)
    {
        if (num[i] == '0')
            continue;
        int max = 0;
        int ind = 0;
        for (int j = i + 1; j < num.size(); j++)
        {
            int nn = num[j] - '0' - j + i;
            if (nn > max && nn > (num[i] - '0'))
            {
                max = nn;
                ind = j;
            }
        }
        if (max > 0)
        {
            num = num.substr(0, i) + to_string(max) + num.substr(i, ind - i) + num.substr(ind + 1);
        }
    }
    cout << num << endl;
}

int main()
{
    ll t;
    cin >> t;
    for (ll i = 0; i < t; i++)
        solve();

    return 0;
}


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;

using dqi = deque<int>;
using vi = vector<int>;
using mii = unordered_map<int, int>;
using mip = unordered_map<int, pair<int, int>>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using spii = set<pair<int, int>>;
using ll = long long;

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

    for (int i = 0; i < num.size(); i++)
    {
        int max = 0;
        int ind = 0;
        for (int j = i + 1; j < num.size(); j++)
        {
            if (num[j] == '0')
                continue;
            int nn = num[j] - '0' - j + i;
            if (nn > max && nn > (num[i] - '0'))
            {
                max = nn;
                ind = j;
            }
        }
        if (max > 0)
        {
            num = num.substr(0, i) + to_string(max) + num.substr(i, ind - i) + num.substr(ind + 1);
        }
    }
    cout << num << endl;
}

int main()
{
    ll t;
    cin >> t;
    for (ll i = 0; i < t; i++)
        solve();

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


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

using namespace std;

using dqi = deque<int>;
using vi = vector<int>;
using mii = unordered_map<int, int>;
using mip = unordered_map<int, pair<int, int>>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using spii = set<pair<int, int>>;
using ll = long long;

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

    for (int i = 0; i < num.size(); i++)
    {
        if (num[i] == '0')
            continue;
        int max = 0;
        int ind = 0;
        for (int j = i + 1; j < num.size(); j++)
        {
            int nn = num[j] - '0' - j + i;
            if (nn > max && nn > (num[i] - '0'))
            {
                max = nn;
                ind = j;
            }
        }
        if (max > 0)
        {
            num = num.substr(0, i) + to_string(max) + num.substr(i, ind - i) + num.substr(ind + 1);
        }
    }
    cout << num << endl;
}

int main()
{
    ll t;
    cin >> t;
    for (ll i = 0; i < t; i++)
        solve();

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>

using namespace std;

using dqi = deque<int>;
using vi = vector<int>;
using mii = unordered_map<int, int>;
using mip = unordered_map<int, pair<int, int>>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using spii = set<pair<int, int>>;
using ll = long long;

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

    for (int i = 0; i < num.size(); i++)
    {
        int max = 0;
        int ind = 0;
        for (int j = i + 1; j < min(i + 10, (int)num.size()); j++)
        {
            if (num[j] == '0')
                continue;
            int nn = num[j] - '0' - j + i;
            if (nn > max && nn > (num[i] - '0'))
            {
                max = nn;
                ind = j;
            }
        }
        if (max > 0)
        {
            num = num.substr(0, i) + to_string(max) + num.substr(i, ind - i) + num.substr(ind + 1);
        }
    }
    cout << num << endl;
}

int main()
{
    ll t;
    cin >> t;
    for (ll i = 0; i < t; i++)
        solve();

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;

using dqi = deque<int>;
using vi = vector<int>;
using mii = unordered_map<int, int>;
using mip = unordered_map<int, pair<int, int>>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using spii = set<pair<int, int>>;
using ll = long long;

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

    for (int i = 0; i < num.size(); i++)
    {
        int max = 0;
        int ind = 0;
        for (int j = i + 1; j < min(i + 10, (int)num.size()); j++)
        {
            if (num[j] == '0')
                continue;
            int nn = num[j] - '0' - j + i;
            if (nn > max && nn > (num[i] - '0'))
            {
                max = nn;
                ind = j;
            }
        }
        if (max > 0)
        {
            while (ind > i)
            {
                swap(num[ind], num[ind - 1]);
                ind--;
            }
            num[i] = char(max + '0');
        }
    }
    cout << num << endl;
}

int main()
{
    ll t;
    cin >> t;
    for (ll i = 0; i < t; i++)
        solve();

    return 0;
}