ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 61 ms):
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define ld long double
#define pll pair<ll,ll>
#define pllv pair<ll,vector<ll>>
#define all(a) a.begin(),a.end()
#define ump unordered_map
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define DEATH_NOTE ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define rep(a,b) for(ll i=a;i<b;i++)
//const ll sz=1001;
const ll mod=1e9+7;
const ll INF=1e18+10;

void solve()
{
    string n;
    cin>>n;
    ll cnt2 = 0;
    ll cnt3 = 0;
    ll sumOfDigits = 0;
    for(auto x:n) {
        ll num = x-'0';
        sumOfDigits+= num;
        if (num == 2) cnt2++;
        if( num == 3) cnt3++;
    }
    ll limit = 10;
    //cout<<"Cnt2"<<cnt2<<" and  cnt3"<<cnt3<<endl;
    for(ll nof2 = 0 ; nof2<min(limit,cnt2+1); nof2++) {
            for(ll nof3 = 0 ; nof3<min(limit,cnt3+1) && nof3<9; nof3++) {
                ll addSum = 2*nof2 + 6*nof3;
                if ((addSum + sumOfDigits) % 9 ==0) {
                    cout<<"Yes"<<endl;
                    return;
                }
            }
    }
    cout<<"NO"<<endl;
}
int main()
{
    DEATH_NOTE

    ll t;
    t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
}


Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int freq2=0,freq3=0,sum=0;
        string s;
        cin>>s;
        int n = s.size();
        vector<int >v(n);
        for(int i=0;i<n;i++){
            v[i]=s[i]-'0';
            sum+=v[i];
            if(v[i]==2){
                freq2++;
            }else if(v[i]==3){
                freq3++;
            }
        }
        int x =9-sum%9;
        if(x==9){
            yes;
            continue;
        }
        if(x==1 and (freq2>=5 or (freq2 >=2 and freq3>= 1))){yes;}
        else if (x==2 and freq2>=1){yes;}
        else if(x==3  and (freq2 >=6 or freq3>=2 or (freq2>=3 and freq3>=1))){yes;}
        else if(x==4  and freq2>=2 ){yes;}
        else if(x==5  and (freq2>=7 or (freq2>=1 and freq3 >=2) or(freq2>=4 and freq3>=1))){yes;}
        else if(x==6  and (freq2>=3 or freq3>=1)){yes; }
        else if(x==7  and ((freq3>=1 and freq2>=5) or freq2>=8 or (freq2>=2 and freq3 >=2) )){yes;}
        else if(x==8  and (freq2>=4 or (freq2>=1 and freq3>=1))){yes;}
        else{
            no;
        }
    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 343 ms):
#include<bits/stdc++.h>

using namespace std;

int t;

int n ;

vector<int> arr;



int main(){

    cin>>t;

    while(t--){

        cin>>n;

           for(int i =0;i<n;i++){

        int x;

        cin>>x;

        arr.push_back(x);

    }

    int tail =0;

    int head = 1;

    while(head<n){

        int subt = min(arr[tail],arr[head]);

        arr[tail]=arr[tail]-subt;

        arr[head]=arr[head]-subt;

        tail++;

        head++;

    }

    

    bool flag=true;

    for(int i =0;i<n-1;i++){

        if(arr[i+1]<arr[i])

        flag = false;

        // cout<<arr[i];

    }

    // cout<<"\n";

    if(flag){

        cout<<"YES"<<"\n";

    }else{

        cout<<"NO"<<"\n";

    }

    arr.clear();

    }

 return 0;

    

}

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>

using namespace std;



void solve() {

int n;

cin >> n;

vector<int> arr(n);

for (int &x : arr) cin >> x;

int j = -1;

for (int i = 0; i < n - 1; i++) {

if (arr[i] > arr[i + 1]) {

j = i;

}

}



if (j == -1) {

cout << "YES\n";

return;

}



for (int i = 0; i < j; i++) {

int min_val = min(arr[i], arr[i + 1]);

arr[i] -= min_val;

arr[i + 1] -= min_val;

}



if (is_sorted(arr.begin(), arr.end())) {

cout << "YES\n";

} else {

cout << "NO\n";

}

}



int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);



int t;

cin >> t;

while (t--) solve();



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 327 ms):
#include <bits/stdc++.h>

void solve()
{
    int n;
    std::cin >> n;
    
    std::vector<int> a(n);
    for(int& _ : a)
        std::cin >> _;
        
    for(int i = 0; i < n - 1; ++i)
    {
        int d = std::min(a[i], a[i + 1]);
        a[i] -= d;
        a[i + 1] -= d;
        
        if(a[i] > a[i + 1])
        {
            std::cout << "NO\n";
            return;
        }
    }
    
    std::cout << "YES\n";
}

int main()
{
    int t;
    std::cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 312 ms):
#include<bits/stdc++.h>

using namespace std;

int n;

int a[222222];

void sl(){

	cin>>n;

	for(int i=0;i<n;i++){

		cin>>a[i];

	}

	for(int i=0;i<n-1;i++){

		int b=a[i];

		a[i]-=min(a[i],a[i+1]);

		a[i+1]-=min(b,a[i+1]);

	}

	bool f=1;

	for (int i=1;i<n;i++) {

    	if (a[i]<a[i-1]) {

        	f=false;

        	break;

    	}

	}

	if(f) cout<<"YES"<<endl;

	else cout<<"NO"<<endl; 

}

int main(){

	int T;

	cin>>T;

	while(T--) sl();

	return 0; 

}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 109 ms):
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
void solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int j=0;
    for(int i=1;i<n;i++) if (a[i-1]>a[i]) j=i;
    if (j==0) {
        cout<<"YES"<<endl;
        return;
    }
    for (int i=0;i<j;i++) {
        int minn=min(a[i],a[i+1]);
        a[i]-=minn;
        a[i+1]-=minn;
    }
    if (is_sorted(a.begin(),a.end())) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
signed main() {
#ifdef ACM_LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    IOS;
    int t;
    cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}




Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>



using namespace std;



// #define ls p << 1

// #define rs p << 1 | 1



typedef long long LL;

typedef pair<int, int> PII;



const int N = 100010;

const LL inf = 1e18;



void solve(){

	int n;

	std::cin >> n;

	

	std::vector<LL> a(n + 1);

	for (int i = 1; i <= n; i ++) std::cin >> a[i];



	for (int i = 1; i < n; i ++){

		if (a[i] > a[i - 1]){

			LL d = a[i] - a[i - 1];

			LL minv = std::min(a[i], a[i + 1]);



			LL cnt = d;

			if (minv != 0) cnt /= minv;

			a[i] -= minv * cnt;

			a[i + 1] -= minv * cnt;

		}

	}



	bool ok = true;

	for (int i = 1; i <= n; i ++){

		if (a[i - 1] > a[i]){

			ok = false;

			break;

		}

	}



	if (ok) std::cout << "YES\n";

	else std::cout << "NO\n";

}



int main(){

	std::ios::sync_with_stdio(false);

	std::cin.tie(nullptr);

	std::cout.tie(nullptr);



	int T;

	std::cin >> T;

	//T = 1;

	while (T --){

		solve();

	}



	return 0;

}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <map>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;

#define af assert(false)
#define el cout << endl
#define ff(x) cout <<#x<<" = "<<x<<", "
#define fff(x, l, r) { cout<<#x<<"["<<l<<", "<<r<<"]: ";for(int i=l;i<=r;++i)cout<<x[i]<<" ";cout<<endl; }

inline int read() {   
    #define gc getchar();
    bool f = 0;
    int a = 0; 
    char c = gc;
    while (c < '0' || c > '9') {
        if (c == '-') f = 1;
        c = gc;
    }
    while (c >= '0' && c <= '9') {
        a = (a << 1) + (a << 3) + (c ^ 48);
        c = gc;
    }
    return f ? -a : a;
    #undef gc
}

const int N = 1e5 + 10;
int a[N];
int n, l, r;

long long solve(int x, int y) {
    vector<int> v;
    for(int i=x;i<=y;++i)v.push_back(a[i]);
    sort(v.begin(),v.end());
    long long ans = 0;
    for(int i=0;i<r-l+1;++i){
        ans += v[i];
    }
    return ans;
}

void Main(){
    n=read(),l=read(),r=read();
    a[0]=0;
    for(int i=1;i<=n;++i){
        a[i]=read();
    }
    printf("%lld\n", min(solve(1, r), solve(l, n)));
}

int main() {
    // freopen("1.in", "r", stdin);
    int t = read();
    while(t--)Main();
    
    return 0;
}

Solution 2 (runtime: 281 ms):
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int Q,a[N],b[N],l,r,n;

int main(){
	scanf("%d",&Q);
	while(Q--){
		scanf("%d%d%d",&n,&l,&r);
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			b[i]=a[i];
		}
		sort(a+1,a+r+1);
		sort(b+l,b+n+1);
		long long sum=0,res=0;
		for(int i=1;i<=r-l+1;i++) res+=a[i];
		for(int i=l;i<=r;i++) sum+=b[i];
		printf("%lld\n",min(sum,res));
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 140 ms):
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    long long t;
    cin >> t; 

    while (t--)
    {
        long long n, k;
        cin >> n >> k; 
        long long arr[n];

        
        for (long long i = 0; i < n; i++) {
            cin >> arr[i];
        }

        
        map<long long, long long> freq;
        for (long long num : arr) {
            freq[num]++;
        }
        
        vector<pair<long,long>>p;
        for(auto it : freq)
        {
               p.push_back({it.second,it.first});
        }
        sort(p.begin(),p.end());
        
        long long count = p.size();
        for(auto it:p)
        {
               if(k>=it.first)
               {
                     k-=it.first;
                     count--;
               }
               else
               {
                     break;
               }
        }
        if(count<=0)
        cout<<1<<endl;
        else
        cout << count << endl;
        
    }

    return 0;
}


Solution 2 (runtime: 218 ms):
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t--){
        int n,k;
        map<int,int>m;
        cin>>n>>k;
        int arr[n];
        for (int i=0;i<n;i++){
            cin>>arr[i];
            m[arr[i]]++;
        }
        vector<int>v;
        for (auto x:m){
            v.push_back(x.second);
        }
        sort(v.begin(),v.end());
        int a=v.size();
        int i=0;
        while (k>0 && a>1){
            k-=v[i];
            if (k>=0){
            a--;
            i++;
            }
        }
        cout<<a<<'\n';
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

using ll = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    int cases;

    std::cin >> cases;
    
    for (int i = 0; i < cases; i++) {
        ll size = 0;
        std::cin >> size;
        std::vector<int> v(size, 0);

        for (int j = 0; j < size; j++) {
            std::cin >> v[j];
        }

        if (size == 2) {
            if (v[1] >= v[0])
                std::cout << "Yes" << std::endl;
            else
                std::cout << "No" << std::endl;
            continue;
        }

        bool ans = true;
        ll curr = v[0];
        for (int j = 1; j < size-1; j++) {
            curr = v[j] - curr;
            if (curr < 0 || curr > v[j + 1]) {
                ans = false;
                break;
            }
        }

        if (ans) {
            std::cout << "Yes" << std::endl;
        }
        else {
            std::cout << "No" << std::endl;
        }
    }

    return 0;
}

Solution 2 (runtime: 312 ms):
#include<iostream>

#include<string>

#include<algorithm>

#include<vector>

#include<climits>

#include<stack>

#include<queue>

#include<set>

#include<map>

#include<unordered_set>

#include<cmath>

using namespace std;



int main() {

int t;

cin>>t;

int n;

while(t--) {

cin>>n;

vector<int>v(n);

for(int i=0; i<n; i++) {

cin>>v[i];

}

int small;

for(int i=0; i<n-1; i++) {

small = min(v[i], v[i+1]);

v[i] = v[i] - small;

v[i+1] = v[i+1] - small;

}

bool f = false;

for(int i=0; i<n-1; i++) {

if(v[i]>v[i+1]) {

f = true;

break;

}

}

if(f) {

cout<<"NO"<<"\n";

} else {

cout<<"YES"<<"\n";

}

}

return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 62 ms):
/*
[[ ⣇⣿⠘⣿⣿⣿⡿⡿⣟⣟⢟⢟⢝⠵⡝⣿⡿⢂⣼⣿⣷⣌⠩⡫⡻⣝⠹⢿⣿⣷ ]],
[[ ⡆⣿⣆⠱⣝⡵⣝⢅⠙⣿⢕⢕⢕⢕⢝⣥⢒⠅⣿⣿⣿⡿⣳⣌⠪⡪⣡⢑⢝⣇ ]],
[[ ⡆⣿⣿⣦⠹⣳⣳⣕⢅⠈⢗⢕⢕⢕⢕⢕⢈⢆⠟⠋⠉⠁⠉⠉⠁⠈⠼⢐⢕⢽ ]],
[[ ⡗⢰⣶⣶⣦⣝⢝⢕⢕⠅⡆⢕⢕⢕⢕⢕⣴⠏⣠⡶⠛⡉⡉⡛⢶⣦⡀⠐⣕⢕ ]],
[[ ⡝⡄⢻⢟⣿⣿⣷⣕⣕⣅⣿⣔⣕⣵⣵⣿⣿⢠⣿⢠⣮⡈⣌⠨⠅⠹⣷⡀⢱⢕ ]],
[[ ⡝⡵⠟⠈⢀⣀⣀⡀⠉⢿⣿⣿⣿⣿⣿⣿⣿⣼⣿⢈⡋⠴⢿⡟⣡⡇⣿⡇⡀⢕ ]],
[[ ⡝⠁⣠⣾⠟⡉⡉⡉⠻⣦⣻⣿⣿⣿⣿⣿⣿⣿⣿⣧⠸⣿⣦⣥⣿⡇⡿⣰⢗⢄ ]],
[[ ⠁⢰⣿⡏⣴⣌⠈⣌⠡⠈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣬⣉⣉⣁⣄⢖⢕⢕⢕ ]],
[[ ⡀⢻⣿⡇⢙⠁⠴⢿⡟⣡⡆⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣵⣵⣿ ]],
[[ ⡻⣄⣻⣿⣌⠘⢿⣷⣥⣿⠇⣿⣿⣿⣿⣿⣿⠛⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ ]],
[[ ⣷⢄⠻⣿⣟⠿⠦⠍⠉⣡⣾⣿⣿⣿⣿⣿⣿⢸⣿⣦⠙⣿⣿⣿⣿⣿⣿⣿⣿⠟ ]],
[[ ⡕⡑⣑⣈⣻⢗⢟⢞⢝⣻⣿⣿⣿⣿⣿⣿⣿⠸⣿⠿⠃⣿⣿⣿⣿⣿⣿⡿⠁⣠ ]],
[[ ⡝⡵⡈⢟⢕⢕⢕⢕⣵⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣿⣿⣿⣿⣿⠿⠋⣀⣈⠙ ]],
[[ ⡝⡵⡕⡀⠑⠳⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢉⡠⡲⡫⡪⡪⡣ ]],
*/
/* #pragma GCC optimize(2) */
#include <iostream>
using namespace std;
#define endl '\n'
#define ll long long
#define Debug(x) cout << #x << ':' << x << endl
#define all(x) (x).begin(), (x).end()

void solve() {
        int l, r;
        cin >> l >> r;
        int k = 31 - __builtin_clz(l ^ r);
        int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
        cout << a << ' ' << b << ' ' << c << endl;
}

signed main() {
        ios::sync_with_stdio(false);
        cin.tie(0);

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

        return 0;
}


Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{

  int t;
  cin >> t;
  while (t--)
  {
    ll l, r;
    cin >> l >> r;

    ll ans = 0, a, b, c;

    for (int i = 30; i >= 0; i--)
    {

      ll lB = 0, rB = 0;

      if (l & (1LL << i))
      {
        lB = 1;
      }

      if (r & (1LL << i))
      {
        rB = 1;
      }

      if (lB == rB)
      {
        ans += lB * (1LL << i);
      }
      else
      {
        ans += (1LL << i);
        a = ans;
        b = ans - 1;
        break;
      }
    }

    for (int i = l; i <= r; i++)
    {
      if (i != a && i != b)
      {
        c = i;
        break;
      }
    }

    cout << a << " " << b << " " << c << endl;
  }
}
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 874 ms):
#include <bits/stdc++.h>
using namespace std;

#define ll long long

void solve(){
    int n,m;
    cin>>n>>m;
    multiset<ll> s1,s2;
    ll sum1=0,sum2=0;
    for(int i=0;i<n;i++) {int a;cin>>a;s1.insert(-a);sum1+=a;}
    for(int i=0;i<m;i++) {int a;cin>>a;auto k = s1.find(-a);if(k==s1.end()){s2.insert(-a);sum2+=a;}else{s1.erase(k);sum1-=a;}}
    
    if(sum1!=sum2){
        cout<<"NO\n";
        return;
    }
    
    while(s1.size() && s2.size()){
        if(*s1.begin() == *s2.begin()){
            s1.erase(s1.begin());
            s2.erase(s2.begin());
        }
        else if(abs(*s1.begin()) > abs(*s2.begin())){
            cout<<"NO\n";
            return;
        }
        else{
            int p = abs(*s2.begin());
            s2.erase(s2.begin());
            int a=p/2,b=p/2+p%2;
            s2.insert(-a);
            s2.insert(-b);
        }
    }
    
    if(s1.size() == 0 && s2.size() ==0)
        cout<<"YES\n";
    else{
        cout<<"NO\n";
    }
    
}

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

    return 0;
}

Solution 2 (runtime: 874 ms):
#include<bits/stdc++.h>
using namespace std;

int n, m, t;
multiset<int> a, b;

int main()
{
    cin >> t;
    while(t--)
    {
        a.clear(); b.clear();
        cin >> n >> m;
        int soma = 0;
        for(int i = 0; i < n; i++)
        {
            int x; cin >> x;
            soma += x; a.insert(x);
        }
        for(int i = 0; i < m; i++)
        {
            int x; cin >> x;
            soma -= x; b.insert(x);
        }
        if(soma != 0)
        {
            cout << "No" << endl;
            continue;
        }
        while(b.size())
        {
            auto x = b.begin();
            int x1 = *x;
            auto y = a.lower_bound(x1);
            int y1 = *y;
            if(*a.begin() > x1) break;
            if(y != a.end() && y1 == x1)
            {
                a.erase(y); b.erase(x);
            }
            else
            {
                b.erase(x);
                b.insert(x1/2);
                b.insert((x1+1)/2);
            }
        }
        if(a.size())
        {
            cout << "No" << endl;
        }
        else
        {
            cout << "Yes" << endl;
        }
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 343 ms):
#include <bits/stdc++.h>

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int n;

        cin >> n;

        int a[n + 1];

        int y = 1;

        for (int i = 1; i <= n; i++)

        {

            cin >> a[i];

            if (i > 1)

                a[i] -= a[i - 1];

            if (a[i] < 0)

              {

                 y = 0;

              //   cout<<y<<"  ";

              //  break;

              } 



        }

        if (y == 1)

            cout << "YES" << endl;

        else

            cout << "NO" << endl;

    }

}

Solution 2 (runtime: 359 ms):
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int N=2e5+5;

int n,m;

int a[N];

signed main() {

int T;

cin>>T;

while(T--)

{

cin>>n;

for(int i=1;i<=n;i++) cin>>a[i];

int ok=1;

for(int i=2;i<=n;i++)

{

if(a[i]>=a[i-1])

{

a[i]-=a[i-1];

a[i-1]=0;

}

else

{

ok=0;

break;

}

}

if(ok) cout<<"YES\n";

else cout<<"NO\n";

}

return 0;

}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 78 ms):
#include <iostream>
#include <vector>
#define int int64_t


using namespace std;

bool compare_vv(vector<char>& a, vector<char>& b) {
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] < b[i]) {
            return true;
        }
        if (a[i] > b[i]) {
            return false;
        }
    }
    return false;
}

void update (int pos, std::string& input_d) {
    int max_ = input_d[pos];
    int max_idx_ = pos;
    vector<vector<char>> to_compare;


 
    for (int swap_idx = pos; 
        (swap_idx < (pos + 9)) && (swap_idx < input_d.size());
        ++swap_idx) {

        vector<char> to_push;
        to_push.push_back(input_d[swap_idx] - (swap_idx - pos));

        for (int i = pos; (i < (pos + 9)) && (i < input_d.size()); ++i) {
            if (i == swap_idx) {
                continue;
            } else {
                to_push.push_back(input_d[i]);
            }
        }
        to_compare.push_back(to_push);
    }
    
    vector<char> max_v = to_compare[0];
    max_idx_ = 0;
    for (int i = 1; i < to_compare.size(); ++i) {
        if (compare_vv(max_v, to_compare[i])) {
            max_v = to_compare[i];
            max_idx_ = i;
        }
    }
    
    max_ = input_d[pos + max_idx_] - max_idx_;

    for (int i = pos+max_idx_; i > pos; --i) {
        input_d[i] = input_d[i - 1];
    }
    input_d[pos] = max_;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        string input_d;
        cin >> input_d;
       
        for (int i = 0; i + 1 < input_d.size(); ++i)  {
            if (input_d[i] < input_d[i + 1] - 1) {
                char x = input_d[i];
                input_d[i] = input_d[i + 1] - 1;
                input_d[i + 1] = x;
                i -= 2;
                i = i < -1 ? -1 : i;
            }; 
        }
        cout << input_d << endl;
    }
}

Solution 2 (runtime: 108 ms):
#include <bits/stdc++.h>
using namespace std ;


int main (){
   int t  ;
   cin>>t ;
   while (t--){

   string s ;
   cin>> s ;
   vector<int>v ;
   for(int i = 0 ; i<s.size() ; i++){
      v.push_back(int(s[i] - '0')) ;
   }
   for(int i = 0 ; i<s.size() ; i++){
      int maxi = v[i] ;
      int maxidx = -1 ;
     
       for (int j = i; j < min(i + 10, (int)v.size()); j++) {
         if(v[j]-j+i> maxi){
            maxi = v[j] -j + i;
            maxidx = j ;
         }
      }
      while(maxidx>i){
         swap(v[maxidx],v[maxidx-1]) ;
         maxidx-- ;
      }
      v[i] = maxi ;

   
   }
   for(int i = 0 ; i< v.size() ;i++){
      cout<<v[i] ;
   }
   cout<<endl;
}
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;

#define lcm(a,b) (a*b/__gcd(a,b))
#define endl '\n'
#define int long long
#define rep(i,a,n) for(int i=a;i<n;i++)
#define vi vector<int>
#define vp vector<pair<int,int>>
#define pb push_back
#define printv(v) for(int i=0;i<v.size();i++){cout<<v[i]<<" ";}cout<<endl;
#define inputv(v) for(int i=0;i<v.size();i++){cin>>v[i];}
#define test(t) int t; cin>>t; while(t--)

bool isprime(int n){
    for(int i=2;i<=sqrt(n);i++){
        if(n<=1)return false;
        if(n%i==0){
            return false;
        }
    }
    return true;
}

void solve(){

    int n;
    cin>>n;
    vi v(n);inputv(v)
    int sum=accumulate(v.begin(),v.end(),0LL);
   
   while(v.size()>1){
   if(v.size()!=1) sum=max(sum,abs(v[0]-v[v.size()-1]));
else{
     sum=max(sum,abs(v[0]));
}
  vi temp;
        for (int i = 0; i < v.size() - 1; i++) {
            temp.pb(v[i + 1] - v[i]); 
        }
        v = temp; 

if(v.size()!=1) sum=max(sum,abs(v[0]-v[v.size()-1]));
else{
     sum=max(sum,abs(v[0]));
}


   }

   cout<<sum<<endl;

}

int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);

test(t){

solve();

}

return 0;
}

Solution 2 (runtime: 46 ms):
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<long long> order;
long long max(long long a, long long b)
{
    if(a>b)return a;
    return b;
}
int main()
{
    long long t;
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>t;
    for(long long q=0;q<t;q++)
    {
        long long n;
        cin>>n;
        order.clear();
        long long sum=0;
        for(long long i=0;i<n;i++)
        {
            long long x;
            cin>>x;
            sum+=x;
            order.push_back(x);
        }
        while(order.size()>1)
        {
            long long nsum1=0,nsum2=0,nsum=0;
            nsum1=order[order.size()-1]-order[0];
            nsum2=order[0]-order[order.size()-1];
            nsum=max(nsum1,nsum2);
            sum=max(sum,nsum);
            if(nsum1<nsum2)reverse(order.begin(),order.end());
            for(long long i=0;i<order.size()-1;i++)
            {
                order[i]=order[i+1]-order[i];
            }
            order.pop_back();
        }
        cout<<sum<<"\n";
    }
}