ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: c++17 

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

using namespace std ;
  
int main(){
    int t ; 
    cin>>t ;
    while(t--){
        
       int a ;
       int l ;
       int r ;
       cin>>a ;
       cin>>l ;
       cin>>r ; 
       
       vector<int> vect(a , 0 ); 
       
       for(int i = 0 ; i < a ; i++){
           cin>>vect[i] ; 
       }
       l-- ; r-- ; 
      sort(vect.begin() , vect.begin() + l  ) ;     
      sort(vect.begin() + l  , vect.begin() + r + 1 ) ; 
      sort(vect.begin() + r + 1  , vect.end()) ; 
      long long sum1 = 0  ; 
       for(int i = l ; i <= r ; i++){
           sum1 += vect[i] ; 
       }     
       long long sum2 = sum1 ; 
       int i = r + 1  ; 
      int j = r ; 
       while(i < vect.size() and j >= l) {
           if(vect[i] > vect[j]) break ; 
           sum1 -= vect[j] - vect[i] ; 
           j-- ; i++ ; 
       }
       i = 0 ; 
       j = r ; 
       while( j >= l and i < l  ){
               if(vect[i] > vect[j]) break ; 
           sum2 -= vect[j] - vect[i] ; 
           j-- ; i++ ; 
       }
       cout<<min(sum1 , sum2 )<<endl ; 
    }
} 













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

using namespace std;

#define datatype int



datatype n,q;

datatype tmp;

char chr;

string str; 

void solve(){

    int l,r;

    cin>>n>>l>>r;

    vector<datatype> arr(n);

    vector<datatype> arr2(n);

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

    {

        cin>>arr[i];

        arr2[i]=arr[i];

    }

    sort(arr.begin(),  arr.begin()+r);

    sort(arr2.begin()+l-1,arr2.end());

    int ln = r-l+1;

    long long sum1=0,sum2=0;

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

        sum1+=arr[i];

    }

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

        sum2+=arr2[l+i-1];

    }

    cout<<min(sum1,sum2);

}

    

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int t = 1;

    cin>>t;

    while(t--){

        solve();

        cout<<endl;

    }

}





//     template <int len = 1>

// void subset_sum(int n) {

//     if (n >= len) {

//         subset_sum<std::min(len*2, maxn)>(n);

//         return;

//     }
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 436 ms):
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
using ll = long long;
int a[N],b[N];
void solve()
{
    int n,m;cin>>n>>m;
    multiset<int> sa;
    multiset<int> sb;
    ll sum = 0;
    for(int i = 1;i <= n;++ i)
    {
        cin>>a[i];
        sum += a[i];
    }
    sa.insert(a + 1,a + 1 + n);
    for(int i = 1;i <= m;++ i)
    {
        cin>>b[i];
        sum -= b[i];
    }
    if(sum)
    {
        cout<<"NO"<<'\n';
        return;
    }
    sb.insert(b + 1,b + 1 + m);
    bool flag = true;
    //cout<<sa.size()<<' '<<sb.size()<<'\n';
    while(sa.size() && sb.size())
    {
        int x = *sa.rbegin();
        int y = *sb.rbegin();
        //cout<<"x = "<<x<<' '<<"y = "<<y<<'\n';
        if(x > y)
        {
            flag = false;
            break;
        }
        if(x == y)
        {
            sa.erase(sa.find(x));
            sb.erase(sb.find(y));
        }
        if(x < y)
        {
            sb.erase(sb.find(y));
            sb.insert(y/2);
            sb.insert((y + 1)/2);
        }
    }
    if(sb.empty()) cout<<"YES"<<'\n';
    else cout<<"NO"<<'\n';
}
int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int _;cin>>_;
    while(_--)solve();
    return 0;
}

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

#define int long long

using namespace std;

const int N=2e5+10;

int T,n,m,a,b,ans;

void init()

{

    ans=0;

}

void solve()

{

    cin>>n>>m;

    init();

    multiset<int> x,y;

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

    {

        cin>>a;

        x.insert(a);

    }

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

    {

        cin>>b;

        y.insert(b);

    }

    if(n==m)

    {

        for(multiset<int>::iterator it=x.begin(),it1=y.begin();it!=x.end();it++,it1++)

        if(*it!=*it1) {cout<<"NO"<<endl; return ;}

        cout<<"YES"<<endl;

        return ;

    }

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

    {

        while(1)

        {

            if(!y.size()||!x.size()) {cout<<"NO"<<endl; return ;}

            multiset<int>::iterator it=y.end();

            multiset<int>::iterator it1=x.end();

            it--;

            it1--;

            if(*it>*it1)

            {

                y.insert((*it)/2);

                y.insert((*it+1)/2);

                y.erase(it);

                break;

            }

            if(*it<*it1)

            {

                cout<<"NO"<<endl;

                return ;

            }

            if(*it==*it1)

            {

                x.erase(it1);

                y.erase(it);

            }

        }

    }

    for(multiset<int>::iterator it=x.begin(),it1=y.begin();it!=x.end();it++,it1++)

    if(*it!=*it1) {cout<<"NO"<<endl; return ;}

    cout<<"YES"<<endl;

}

signed main()

{

    std::ios::sync_with_stdio(false);

    cin.tie(0);cout.tie(0);

    cin>>T;

    while(T--) solve();

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

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N =1e5+10;

ll a[N],b[N];

void solve()
{
	int n,l,r;cin>>n>>l>>r;
	for(int i=1;i<=n;++i) cin>>a[i];
	for(int i=1;i<=n;++i) b[i]=a[i];
	
	sort(a+1,a+1+r);
	sort(b+l,b+1+n);
	
	ll ans1=0,ans2=0;
	for(int i=1;i<=r-l+1;++i) ans1+=a[i];
	for(int i=1;i<=r-l+1;++i) ans2+=b[i+l-1];
	
	cout<<min(ans1,ans2)<<'\n';
}

signed main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _;cin>>_;
	while(_--) solve();
	return 0;
}

Solution 2 (runtime: 77 ms):
#include <algorithm>

#include <iostream>

#include <vector>



using integer = unsigned long long;



template <typename T>

std::istream& operator >>(std::istream& input, std::vector<T>& v)

{

    for (T& a : v)

        input >> a;



    return input;

}



void answer(integer x)

{

    std::cout << x << '\n';

}



integer check(std::vector<unsigned> a, size_t b, size_t e, size_t k)

{

    std::sort(a.begin() + b, a.begin() + e);



    integer s = 0;

    for (size_t i = 0; i < k; ++i)

        s += a[b+i];



    return s;

}



void solve(const std::vector<unsigned>& a, unsigned l, unsigned r)

{

    const size_t n = a.size(), k = r - l + 1;



    const integer p = check(a, 0, r, k), s = check(a, l-1, n, k);

    answer(std::min(p, s));

}



void test_case()

{

    size_t n;

    std::cin >> n;



    unsigned l, r;

    std::cin >> l >> r;



    std::vector<unsigned> a(n);

    std::cin >> a;



    solve(a, l, r);

}



int main()

{

    std::cin.tie(nullptr)->sync_with_stdio(false);



    size_t t;

    std::cin >> t;



    while (t-- > 0)

        test_case();



    return 0;

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

Solution 1 (runtime: 187 ms):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
    ll n,l,r; cin>>n>>l>>r;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    l--;
    vector<ll> left(a.begin(),a.begin()+r), right(a.begin()+l,a.end());
    sort(right.begin(),right.end());
   sort(left.begin(),left.end());
    ll mn=0;
    ll cnt=0;
    ll cnt1=0;

    for (ll i = 0; i <r-l; i++) {
        cnt+=left[i];
        cnt1+=right[i];
    }
    cout << min(cnt,cnt1) << endl;

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

    return 0;
}

Solution 2 (runtime: 124 ms):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define t(ok) ok?cout<< YES<<endl:cout<<NO<<endl;
#define vll vector<long long>
#define vpll vector <pair<ll,ll>>
#define mll map<long long, long long>
#define all(x) x.begin(), x.end()
#define forn(i,n) for(int i = 0; i < n; i++)
#define mii map<int, int>
#define f(i,a,b) for(ll i = a;i<b;i++)
#define vc vector<char>
#define py cout << "YES" << endl
#define pn cout << "NO" << endl
#define vb vector<bool>
#define invec for (int i=0;i<n;i++) {cin>>v[i];} 
#define print_arr(vec, sz) for(int zwzq = 0; zwzq < sz ; zwzq++){cout << vec[zwzq] << ' ';}cout << endl;
#define fori(i, a, c) for(int i = a ; i < c ; i++)
#define ford(i, n, a) for (int i = n ; i >= a ; i--)
#define print(vec) for(int zwzq = 0; zwzq < vec.size() ; zwzq++){cout << vec[zwzq] << ' ';}cout << endl;
#define print_pair(vec) for(int zwzq = 0; zwzq < vec.size() ; zwzq++){cout << '[' <<vec[zwzq].first << ',' << vec[zwzq].second << ']' << ' ';}cout << endl;
const ll mod = 998244353;
using namespace std;
long long mod_sub(long long a, long long b, long long m){a = a % m; b = b % m;return (((a - b) % m) + m) % m;}
long long powermod(long long x, long long y, long long p){
    long long res = 1;
    x = x % p;
    if (x == 0){return 0;}
    while (y > 0){
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
   return res;
}


//for first see soln,for second try reverse or smaller optimal method, BIT question write one or two example in bit then solve
// FIND BRUTE FORCE FIRST 
int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    ll t;
    cin >> t;
    while (t--){


ll n,r,l;
    cin  >> n >>l>>r;
    l--;r--;
    vll v(n);
     for (int i=0;i<n;i++) {cin>>v[i];}
        multiset<int>a,b;
        for (int i = 0;i<=r;i++){
            a.insert(v[i]);
        }
        for (int i = l;i<n;i++){
            b.insert(v[i]);
        }
        long long a1=0LL,a2=0LL;
        auto it = a.begin();
        auto jt = b.begin();
        int k = r-l+1;
        while (k--){
            a1 += *it;
            it++;
            a2 += *jt;
            jt++;
        }
        cout<<min(a1,a2)<<endl;

    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 124 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int long long
// Whatever happens... God had made a plan for you.♡

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    int dp[4000][4000];
    while (t--)
    {
        string a, b, c;
        cin >> a >> b >> c;
        dp[0][0] = 0;
        for (int i = 0; i < a.size(); i++)
        {
            dp[i + 1][0] = dp[i][0] + (a[i] != c[i]);
        }
        for (int i = 0; i < b.size(); i++)
        {
            dp[0][i + 1] = dp[0][i] + (b[i] != c[i]);
        }
        for (int i = 1; i <= a.size(); i++)
        {
            for (int j = 1; j <= b.size(); j++)
            {
                dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != c[i + j - 1]), dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));
            }
        }
        cout << dp[a.size()][b.size()] << endl;
    }
}

Solution 2 (runtime: 1906 ms):
#include <iostream>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#define ll long long
using namespace std;

string a, b, c;

typedef pair<ll, ll> pii;
map<pii, ll> memo;

ll d(ll i, ll j) {

    if (memo.count({i, j})) return memo[{i, j}];

    if (i==0 && j==0) {
        return memo[{i, j}] = 0;
    }
    else if(i==0) {
        return memo[{i, j}] = d(0, j-1) + !(b[j-1]==c[i+j-1]);
    }
    else if(j==0) {
        return memo[{i, j}] = d(i-1, 0) + !(a[i-1]==c[i+j-1]);
    }

    return memo[{i, j}] = min(d(i-1, j) + !(a[i-1] == c[i+j-1]), d(i, j-1) + !(b[j-1] == c[i+j-1]));
}


int solve() {



    cin >> a >> b >> c;

    memo.clear();   



    cout << d(a.length(), b.length())<< "\n";




    return 0;


}
 
int main() {  
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 61 ms):
#include "bits/stdc++.h"
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define int long long

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const char nl = '\n';
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

void solve() {
	int n; cin >> n;
	vector<int> v(n); for (auto &x : v) cin >> x;

	int ans = accumulate(all(v), 0);

	while (sz(v) > 1) {
		ans = max(ans, abs(v[0] - v.back()));

		for (int i = 0; i < sz(v) - 1; i++)
			v[i] = v[i + 1] - v[i];
		v.pop_back();

		ans = max(ans, abs(v[0] - v.back()));
	}

	cout << ans << nl;
}

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

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

	return 0;
}


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

int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<long long> vec1(n);
        for(int i = 0; i < n; i++) {
            cin >> vec1[i];
        }
        
        if(n == 1) {
            cout << vec1[0] << endl;
            continue;
        }

        long long ans = LLONG_MIN;
        int m = n;

        for(int i = 0; i < n; i++) {
            long long sum = 0;
			for (int i = 0; i < m; i++) sum = (sum + vec1[i]) ;
			if (i == 0) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 0; i < m-1; i++) vec1[i] = (vec1[i + 1] - vec1[i]) ;
            m--;
        }
        
        cout << ans << endl;
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

int32_t main() 
{
    int n;
    cin>>n;
    vector<int>v(n);
    vector<pair<int,int>>ans;
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++){
      vector<int>q;
      for(int j=i;j<n;j++){
        q.push_back(v[j]);
      }
      sort(q.begin(),q.end());
      int x=-1,y=q.size()-1;
      for(int j=0;j<q.size();j++){
        if(q[j]==v[i]) x=j;
      }
      int z=x;
      while(x<y){
        ans.push_back({q[x+1],q[z]});
        x++;
        
      }
      while(z<y){
        ans.push_back({q[z],q[y]});
        y--;
      }
      while(z>0){
        ans.push_back({q[z],q[z-1]});
        swap(q[z],q[z-1]);
        z--;
      }
      
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

Solution 2 (runtime: 1218 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);

void solve()
{
    int n;
    cin >> n;
    vector<int> c(n);
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
    }
    vector<int> v1(n);
    for (int i = 0; i < n; i++)
    {
        v1[i] = i + 1;
    }
    vector<pair<int, int>> ans;
    for (int i = 0; i < n; i++)
    {
        int idx = find(v1.begin(), v1.end(), c[i]) - v1.begin();
        for (int j = idx; j < n - 1; j++)
        {
            ans.push_back({v1[j + 1], v1[j]});
            swap(v1[j], v1[j + 1]);
        }
        for (int j = n - 1; j > i; j--)
        {
            ans.push_back({v1[j], v1[j - 1]});
            swap(v1[j], v1[j - 1]);
        }
    }
    cout << ans.size() << endl;
    for (auto e : ans)
    {
        cout << e.first << " " << e.second << endl;
    }
    cout << endl;
}

signed main()
{
    fast;
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 108 ms):
					    		/*Jai Maa Bhawani*/
  #include <bits/stdc++.h>
  using namespace std;
  #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
  #define int long long
  #define TEST int t;cin>>t;while(t--)
  #define inf 5e18
  #define ll long long
  #define pb push_back
  const int N=2e5+10;
  void solve()
  {
  		int n;cin>>n;
  		vector<int>a(n);
  		for(int i=0;i<n;++i)cin>>a[i];
  		if(a[0]>a[1])
  		{
  			cout<<"NO"<<endl;
  			return;
  		}
  		for(int i=1;i<n;++i)
  		{
  			int mn=min(a[i],a[i-1]);
  			a[i]-=mn;
  			a[i-1]-=mn;
  		}
  		for(int i=1;i<n;++i)
  		{
  			if(a[i]<a[i-1])
  			{
  				cout<<"NO"<<endl;
  				return;
  			}
  		}
  		cout<<"YES"<<endl;
  		
  		
  		
  		
  	
  		
  		
  		
  	
	
		
	}
  		
  		
  		
  		
  		
  		
  		
  		
  		
  		
   
    signed main(){FAST TEST{solve();}}

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

using namespace std;



using ll = long long;

using vll = vector <ll>;



void tc () {

ll n;

cin >> n;

vll ve(n);

for (ll &i : ve) cin >> i;

ll j = 0;

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

if (ve[i-1] > ve[i]) j = i;

}

if (j == 0) {

cout << "YES\n";

return;

}

auto fop = [&](ll i) {

ll minN = min(ve[i], ve[i+1]);

ve[i] -= minN;

ve[i+1] -= minN;

};

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

fop(i);

}

cout << (is_sorted(ve.begin(), ve.end()) ? "YES" : "NO") << '\n';

}



int main () {

ll T; cin >> T; while (T--) { tc(); }

return 0;

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

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

using namespace std;

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

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

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

        bool valid_sort = true;
        int inflection_point = 0;
        for(int i=1; i<n; i++) {
            int j = i-1;

            while(j-1>=inflection_point && valid_sort) {
                int subtract_val = min(arr[j], arr[j-1]);
                arr[j] -= subtract_val;
                arr[j-1] -= subtract_val;
                
                if(arr[j-1] > arr[j]) {
                    valid_sort = false;
                }

                j--;
            }

            if(arr[i-1] > arr[i]) {
                valid_sort = false;
            }

            inflection_point = i-1;
        
        }

        if(valid_sort) {
            cout<<"YES"<<endl;
        } else {
            cout<<"NO"<<endl;
        }
    }

    return 0;
}

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

#include <algorithm>

#include <cstring>



using namespace std;



const int N = 200010;



int t, n, a[N];



int main() {

	scanf("%d", &t);

	while (t--) {

		memset(a, 0, sizeof(a));

		/*

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

			a[i] = 0;

		*/

		scanf("%d", &n);

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

			scanf("%d", &a[i]);

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

			if (a[i]) {

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

				a[i] -= minVal;

				a[i + 1] -= minVal;

			}

		}

		bool flag = true;

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

			if (a[i]) {

				flag = false;

				break;

			}

		}

		if (flag)

			printf("YES\n");

		else

			printf("NO\n");

	}

	return 0;

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

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define el '\n'

void solv() {
    string s, ans="";
    cin>>s;
    for(int i=0;i<s.size();i++) {
        int z=s[i]-'0', p=i;
        for(int j=i;j<min((int)s.size(), i+10);j++) {
            if(s[j]-'0'-(j-i) > z) {
                z = s[j]-'0'-(j-i);
                p=j;
            }
        }
        
        while(p>i) {
            swap(s[p], s[p-1]);
            p--;
        }
        s[i]=z+'0';
    }
    cout<<s<<el;
}


int32_t main() {
    int t=1;
    cin >> t;
    while (t--) {
        solv();
    }
    return 0;
}


Solution 2 (runtime: 92 ms):
// Online C++ compiler to run C++ program online

#include <iostream>

#include<vector>

using namespace std;



int main() {

int t;

cin>>t;

while(t--){

string s;

cin>>s;

//   vector<string> arr(n);

//   int size=0 , x=0;

for(int j=0;j<s.size();j++){

int count=0;

for(int i=0;i<s.size()-1;i++){

if((s[i]-'0'<s[i+1]-'1') && s[i+1]!=0 ){

s[i+1]--;

swap(s[i], s[i+1]);

} else{

count++;

}

}

if(count==s.size()-1) break;

}

cout<<s<<endl;

}



return 0;

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

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

#define ll long long
#define vi vector<int>
#define si set<int>
#define ui unordered_set<int>
#define vll vector<long long>
#define f(i, l, h) for(int i = l; i < h; i++)
#define cf(i, l, h) for(int i = l; i <= h; i++)
#define rf(i, h, l) for(int i = h; i >= l; i--)
#define pb push_back

void solution() {
	string s;
	cin >> s;
	int n = s.size();
	f(i, 0, n) {
		int m = s[i] - '0';
		int pos = i;
		f(j, i, min(i + 10, n)) {
			if(s[j] - '0' - (j - i) > m) {
				m = s[j] - '0' - (j - i);
				pos = j;
			}
		}
		rf(j, pos, i) {
			s[j] = s[j - 1];
		}
		s[i] = m + '0';
	}
	cout << s << endl;
}

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

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

 void solve(){
string s;
cin >> s;
int n=s.size();
for(int i=1; i<n; i++){
    int curr=s[i]-'0';
    for(int j=i; j>0; j--){
        int second=s[j]-'0';
        int first=s[j-1]-'0';
        if(second==0)break;
        if(second-1>first){
            s[j]=s[j-1];
            s[j-1]=(second-1)+'0';
        }else break;
    }
}
cout << s << endl;
 }
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<stdio.h>

int main(){

    int t;

    scanf("%d", &t );

    while(t--){

    int n;

    scanf("%d", &n);

    long long a[n];

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

        scanf("%lld", &a[i]);

    }

    int h=0;

    if(n>2){

    int b = a[1] - a[0];

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

        if(a[i] < b || b <0){

            h=1;

            printf("NO\n");

            break;

        }

        else{

            b = a[i] - b;

        }

    }

        if(h==0){

            printf("YES\n");

        }

    }

    else if(n ==2){

        if(a[1] < a[0]){

            h=1;

            printf("NO\n");

        }

        else{

            printf("YES\n");

        }

    }

    else if(n==1){

        printf("YES\n");

    }

    }

return 0;

}

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

#include <vector>

using namespace std;



void solve(){

    int n;

    cin >> n;

    vector<long long> a(n);

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

        cin >> a[i];

    }

    

    long long cur = a[0];

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

        if(cur > a[i]){

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

            return;

        }

        cur = a[i] - cur;

    }

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

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t;

    cin >> t;

    while(t--){

        solve();

    }

    return 0;

}