ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049C - MEX Cycle
Language: c++17 

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

using namespace std;

using ll = long long;

const ll inf = 4e18;

const int N = 2e5 + 5;

int n, x, y;

int a[N];

void solve(){

	cin >> n >> x >> y;

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

		a[i] = (i - 1) % 2;

	}

	if(n % 2 == 1)a[1] = 2;



	if(a[x] == a[y]){

		if(n % 2 == 0)a[x] = 2;

		else{

			if(x == 2)swap(a[x], a[1]);

			else if(y == n)swap(a[y], a[1]);

			else a[y] = 2;

		}

	}

	for(int i = 1;i <= n; ++ i)cout << a[i] << ' ';

		cout << '\n';



}



int main(){

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int _ = 1;cin >> _;

	while(_ --){

		solve();

	}

	return 0;

}

/*



*/

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

using namespace std;

#define ll long long

#define od(n) (n & 1)

#define loop(k) for (ll i = 0; i < k; i++)

#define out(k) cout << k << endl

ll ceil(ll a, ll b) { return (a + b - 1) / b; }

ll expo(ll a, ll b, ll mod)

{

    ll res = 1;

    while (b > 0)

    {

        if (b & 1)

            res = (res * a) % mod;

        a = (a * a) % mod;

        b = b >> 1;

    }

    return res;

}

ll pow(ll a, ll b)

{

    ll res = 1;

    while (b > 0)

    {

        if (b & 1)

            res = (res * a);

        a = (a * a);

        b = b >> 1;

    }

    return res;

}

ll mo(ll a, ll b) { return (a >= 0) ? a % b : ((a % b) + b) % b; }

void printv(vector<ll> v)

{

    loop(v.size()) cout << v[i] << " ";

    cout << endl;

}

void primeFactor(ll x, map<ll, ll> &mp)

{

    for (ll j = 2; j * j <= x; j++)

    {

        while (x % j == 0)

        {

            mp[j]++;

            x /= j;

        }

    }

    if (x > 1)

        mp[x]++;

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    ll t = 1;

    cin >> t;

    ll mod = 1e9;

    while (t--)

    {

        ll n, x, y;

        cin >> n >> x >> y;

        vector<int> v(n, 0);

        if (n & 1)

        {

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

                v[i] = !v[i - 1];

            v[n - 2] = 2;

            v[n - 1] = 1;

            if (v[x - 1] == v[y - 1])

            {

                vector<int> tmp(n);

                ll d = (n - 1) - min(x, y);

                int k = 0;

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

                    tmp[k++] = v[i];

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

                    tmp[k++] = v[i];

                v = tmp;

            }

        }

        else

        {

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

                v[i] = !v[i - 1];

            if (v[x - 1] == v[y - 1])

                v[x - 1] = 2;

        }

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

            cout << v[i] << " ";

        cout << endl;

    }

    return 0;

}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};

void solve(int T) {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (auto &i: v) cin >> i;
    if (n == 1) {
        cout << v[0];
        return;
    }
    ll ans = accumulate(v.begin(), v.end(), 0ll);
    while (v.size() > 1) {
        for (int i = 0; i < (int) v.size() - 1; ++i) {
            v[i] = v[i + 1] - v[i];
        }
        v.pop_back();
        ans = max(ans, abs(accumulate(v.begin(), v.end(), 0ll)));
//        cout << abs(accumulate(v.begin(), v.end(), 0ll)) << '\n';
    }
    cout << ans;

}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve(i);
        cout << '\n';
    }
}

Solution 2 (runtime: 62 ms):
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define TLE (double)clock() / CLOCKS_PER_SEC <= 0.95
#define int long long
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 1e6 + 5, M = 1e6 + 5, S = 1e6 + 5, inf = 0x3f3f3f3f3f3f3f3f, mod = 998244353;
int arr[N];
void solve()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	int ans = -0x3f3f3f3f;
	for(int now = n;now>=1;now--){
		int sum = 0;
		for(int i=1;i<=now;i++){
			sum+=arr[i];
		}
		if(now==n) ans = max(ans,sum);
		else ans = max(ans,max(sum,-sum));
		for(int i=1;i<=now;i++){
			arr[i] = arr[i+1]-arr[i];
		}
	}
	cout<<ans<<endl;
	 

}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
     cin >> T;
    for (int i = 1; i <= T; i++)
    {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 343 ms):
#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#include<algorithm>
typedef long long int ll;
using namespace std;
int main(){
    ll t;
    cin>>t;
    while(t--){
      ll n;
      cin>>n;  
      vector<int> arr(n);
      for(ll i=0;i<n;i++){
        cin>>arr[i];
      }
      bool ans=true;
      for(ll i=0;i<n-1;i++){
        int temp=arr[i];
        arr[i]=arr[i]-min(arr[i],arr[i+1]);
        arr[i+1]=arr[i+1]-min(temp,arr[i+1]);
        if(arr[i]>arr[i+1]){
            ans=false;
            break;
        }
      }
      if(ans){
        cout<<"YES"<<endl;
      }
      else{
        cout<<"NO"<<endl;
      }
    }

    
}

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

using namespace std;



int main() {

int t;

cin >> t;

while (t--) {

int n;

cin>>n;

vector<int>v(n);

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

cin>>v[i];

}

bool valid = true;

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

if (v[i]<=v[i+1]) {

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

v[i] = 0;

}else {

valid = false;

break;

}

}

if (valid) {

cout<<"YES"<<endl;

}else {

cout<<"NO"<<endl;

}

}

return 0;

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

Solution 1 (runtime: 218 ms):
#include<iostream>

#include<bits/stdc++.h>



using namespace std;



int main()

{

    int t;

    cin>>t;

    vector<long long>ans;



    while(t--)

    {

        int n, l, r;

        cin>>n>>l>>r;

        vector<long long>arr(n+1);

        vector<long long>l1;

        vector<long long>l2;

        vector<long long>l3;



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

        {

            long long a;

            cin>>a;

            arr[i] = a;

        }

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

        // cout<<arr[i];

        // cout<<endl;



        for(long long i=1; i<l; i++)

        l1.push_back(arr[i]);



        long long sum=0;

        for(long long i=l; i<=r; i++)

        {

            l2.push_back(arr[i]);

            sum+=arr[i];

        }

        long long sum2 = sum;



        for(long long i=r+1; i<=n; i++)

        l3.push_back(arr[i]);



        sort(l1.begin(), l1.end());

        // cout<<l1.size();

        sort(l2.begin(), l2.end());

        // cout<<l2.size();

        sort(l3.begin(), l3.end());

    // cout<<l3.size()<<endl;

    

        long long a=0, b=l2.size()-1;

        if(l1.size()>0)

        {

            while(l1[a]<l2[b] && a<l1.size() && b>=0)

            {

                sum+=l1[a];

                sum-=l2[b];

                a++;

                b--;

            }

        }



        a=0, b=l2.size()-1;

        

        if(l3.size()>0)

        {

            while(l3[a]<l2[b] && a<l3.size() && b>=0)

            {

                // cout<<a<<b<<endl;

                sum2+=l3[a];

                sum2-=l2[b];

                a++;

                b--;

            }

        }



        ans.push_back(min(sum, sum2));

    }

    for(long i=0; i<ans.size(); i++)

    cout<<ans[i]<<endl;



    return 0;

}



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

using namespace std;



int main(){

    long long int t;

    cin>>t;

    while(t--){

        long long int n,l,r;

        cin>>n>>l>>r;

        vector<long long int> a(n+1);

        vector<long long int> set1;

        vector<long long int> set2;

        long long int sum = 0;

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

            cin>>a[i];

            if(i<=r){set1.push_back(a[i]);}

            if(i>=l){set2.push_back(a[i]);}

        }

        long long int req_ele=r-l+1;

        sort(set1.begin(),set1.end());

        long long int sum1=0;

        for(long long int i=0;i<req_ele;i++){

            sum1 += set1[i];

        }

        sort(set2.begin(),set2.end());

        long long int sum2=0;

        for(long long int i=0;i<req_ele;i++){

            sum2 += set2[i];

        }

        cout<<min(sum1,sum2)<<"\n";

    }

}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 1280 ms):
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
int main(){
    int n;
    cin>>n;
    
    int c[n];
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    
    ll count=0;
    
    vector<pair<int,int>> ans;
    
    for(int i=0;i<n;i++){
        vector<pair<int,int>> v,z;
        for(int j=i+1;j<n;j++){
            if(c[i]<c[j]){
                count+=2;
                v.push_back({c[j],c[i]});
                z.push_back({c[i],c[j]});
            }
        }
        sort(v.begin(),v.end());
        sort(z.begin(),z.end());
        reverse(z.begin(),z.end());
        for(int k=0;k<v.size();k++){
            ans.push_back(v[k]);
        }
        for(int k=0;k<v.size();k++){
            ans.push_back(z[k]);
        }
        
        v={};
        for(int j=i+1;j<n;j++){
            if(c[i]>c[j]){
                count++;
                v.push_back({c[i],c[j]});
            }
        }
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        for(int k=0;k<v.size();k++){
            ans.push_back(v[k]);
        }
        
    }
    
    
    
    // for(int i=0;i<n;i++){
    //     for(int j=i+1;j<n;j++){
    //         if(c[i]>c[j]){
    //             count++;
    //             v.push_back({c[i],c[j]});
    //         }
    //     }
    // }
    
    cout<<count<<endl;
    
    for(int i=0;i<ans.size();i++){
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
    
    
    
    
    return 0;
}

Solution 2 (runtime: 1280 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define repi(i, s, n) for (int i = s; i < n; i++)
#define rep(n) for (int i = 0; i < n; i++)
#define co(n) cout << n << "\n"
#define cendl cout << "\n"
#define vint(v, n) vector<int> v(n, 0)
#define inp(a) int a; cin >> a
#define inp2(a, b) int a, b; cin >> a >> b
#define inp3(a, b, c) int a, b, c; cin >> a >> b >> c
mt19937 rng(time(0));
void solve() {
   int n;
   cin>>n;
   map<int,int> mp;
   vector<vector<int>> ans(n,vector<int> (n,0));
   int ansd=n*(n-1);
   rep(n)
   {
    inp(t);
    mp[t]=i;
   }
   for(int i=1;i<n;i++)
   {
        for(int j=i+1;j<=n;j++)
        {
            if(mp[j]<mp[i])
            {
                ans[i-1][j-1]=1;
                ansd--;
            }
        }
   }
   vector<vector<int>> dp(n+1,vector<int> (n+1,1));
   co(ansd);
   vector<int> pos(n,0);
   rep(n)
   pos[i]=i+1;
   for(int i=1;i<=n;i++)
   {
    for(int j=1;j<n;j++)
    {
        if(ans[pos[j]-1][pos[j-1]-1]==0)
        {
            if(dp[pos[j]][pos[j-1]]==1){
            cout<<pos[j]<<" "<<pos[j-1]<<endl;
            dp[pos[j]][pos[j-1]]=0;
            swap(pos[j],pos[j-1]);
            }
            
        }
    }
   }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // inp(t);
    // while (t--) 
    solve();
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 280 ms):
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define f0r(i, n) for (int i = 0; i < (n); ++i)
#define fnr(i, n, k) for (int i = (n); i < (k); ++i)
#define forl(a, l) for (auto a : l)
#define ctn(x) cout << x << '\n'
#define ctl(lst)                          \
  for (auto &a : (lst)) cout << a << ' '; \
  cout << endl;
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define ub(v, x) (upper_bound(all(v), x) - begin(v))
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define sz(v) (v).size()

using namespace std;
template <class T>
using V = vector<T>;
using ll = long long;
using vi = V<int>;
using pi = pair<int, int>;
using Adj = V<vi>;

void dfs(Adj &adj, int v, vi &par) {
	forl (c, adj[v]) {
		if (c == par[v]) continue;
		par[c] = v;
		dfs(adj, c, par);
	}
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

	int T;
	cin >> T;
	while (T--) {
		int N, u, v;
		cin >> N;
		vi deg(N);
		Adj adj(N);
		f0r(i, N-1) {
			cin >> u >> v;
			adj[--u].pb(--v);
			adj[v].pb(u);
			deg[u]++, deg[v]++;
		}
		vi maxes, par(N);
		int mx = 0;
		f0r(i, N) {
			if (deg[i] > mx) {
				mx = deg[i];
				maxes = {i};
			} else if (deg[i] == mx) maxes.pb(i);
		}
		dfs(adj, 0, par);
		int mx1 = 0, mx2 = 0;
		int v1 = maxes[0], v2 = maxes.size() == 1 ? maxes[0] : maxes[1];
		f0r(i, N) {
			if (i != v1) mx1 = max(mx1, deg[v1] + deg[i] - 1 - (par[v1] == i || par[i] == v1));
			if (i != v2) mx2 = max(mx2, deg[v2] + deg[i] - 1 - (par[v2] == i || par[i] == v2));
		}
		ctn(max(mx1, mx2));
	}
}


Solution 2 (runtime: 233 ms):
// mode: short code
/*
practicing..
*/
#include<bits/stdc++.h>

void solve() {
    int n;
    std::cin >> n;

    std::vector<std::vector<int>> adj(n);
    for (int i = 1; i < n; i++) {
        int u, v;
        std::cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    std::vector<int> deg(n);
    for (int i = 0; i < n; i++) {
        deg[i] = adj[i].size();
    }

    int res = 0;
    for (int u = 0; u < n; u++) {
        for (int v : adj[u]) {
            res = std::max(res, deg[u] + deg[v] - 2);
        }
    }

    std::vector<int> p(n);
    iota(p.begin(), p.end(), 0);
    sort(p.begin(), p.end(), [&](int x, int y) {
        return deg[x] > deg[y];
    });
    
    for (int u : {p[0], p[1]}) {
        std::vector<bool> del(n);
        del[u] = true;
        for (int v : adj[u]) {
            del[v] = true;
        }
        for (int v = 0; v < n; v++) {
            if (!del[v]) {
                res = std::max(res, deg[u] + deg[v] - 1);
            }
        }
    }

    std::cout << res << '\n';
    return;
}

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

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }

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

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while(t--){
        int n; 
        cin >> n;
        vector<long> a(n);
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }

        bool p = true;
        for(int i = n - 1; i >= 1; i--){
            if(a[i-1] > a[i]){
                long x = a[i-1] - a[i];
                int id = i - 2; 
                
                if(id < 0){  
                    p = false;
                    break;
                }

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

                if(a[id] < 0){  
                    p = false;
                    break;
                }
            }
        }

        if(p){
            for(int i = 0; i + 1 < n; i++){
                if(a[i] > a[i+1]){
                    p = false;
                    break;
                }
            }
        }

        cout << (p ? "YES\n" : "NO\n");
    }

    return 0;
}


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

// #define int ll

using namespace std;

#define uint unsigned int

#define ull unsigned long long

#define rep(i, a, b) for (register int i = (a); i <= (b); ++i)

#define per(i, a, b) for (register int i = (a); i >= (b); --i)

#define clr(a) memset(a, 0, sizeof(a))

#define gint greater<int>()

#define ll long long

#define db double

#define vin vector<int>

#define vll vector<ll>

#define pint pair<int, int>

#define all(x) x.begin(), x.end()

#define tint tuple<int, int, int>

#define umap unordered_map

#define uset unordered_set

const int oo = 0x3f3f3f3f;

const ll INF = 1e18;

const int P = 998244353;

const ll md = 1e9 + 7;

int dx[] = { 0, -1, 0, 1, 0, -1, 1, 1, -1 };

int dy[] = { 0, 0, -1, 0, 1, -1, -1, 1, 1 };

const int N = 200005;

int t = 1, n, m, k, x, y, z;

int res = oo, rss = -oo, sum = 0, rs = 0;

int a[N], b[N], c[N], dp[N], w[N], v[N];

string s, ss, sk;

void solve(){

    cin >> n;

    rep(i, 1, n)cin >> a[i];

    rep(i, 1, n - 1){

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

        a[i] -= x;

        a[i + 1] -= x;

    }

    rep(i, 1, n - 1){

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

            cout << "NO" << endl;

            return;

        }

    }

    cout << "YES" << endl;

}

signed main(){

    std::ios::sync_with_stdio(false);

    cin.tie(0);

    cin >> t;

    while(t--)

        solve();

    return 0;

}
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

#define ll long long
#define ld long double
#define pme pair<int, int>
#define pb push_back
#define pf push_front
#define sz size()
#define endL cout << '\n'
#define breaks for(int i=0; i<30; i++) cout << "-"
#define read(a, n) for(auto i=0; i<n; ++i) cin >> a[i]
#define read2d(a, n, m) for(auto i=0; i<n; ++i) for(auto j=0; j<m; j++) cin >> a[i][j]
#define print(a, n) for(auto i=0; i<n; ++i) cout << a[i] << ' '
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

#define MAX 200005
#define MOD 1000000007

using namespace std;

int main() {
    IO;

    int tc = 1;
    //cin >> tc;
    while (tc--) {
        int n, m, ans = 0, a[1005], b[1005];
        unordered_map<int, int> mp;
        cin >> n; read(b, n);
        for (int i = 1; i <= n; i++) mp[b[i-1]] = 0, a[i - 1] = i;

        vector <pme> v; int i = 0;
        for (int i = 0; i < n; i++) {
            int j = b[i] + mp[b[i]] - 1;
            while (j < n - 1) v.pb({ a[j + 1],a[j] }), mp[a[j + 1]]--, swap(a[j], a[j + 1]), j++;
            while (j > i) v.pb({ a[j],a[j - 1] }), mp[a[j - 1]]++, swap(a[j], a[j - 1]), j--;
        }

        cout << v.sz << '\n';
        for (auto x : v) cout << x.first << ' ' << x.second << '\n';
    }
    return 0;
}

Solution 2 (runtime: 186 ms):
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned int
using namespace std;
constexpr int m=998244353;


void call(){
  int n;cin>>n;
  vector<int> v(n),ans(n);
  map<int,int> m;
  vector<pair<int,int> > sol;
  for(int i=0;i<n;i++){cin>>v[i];ans[i]=i+1;}
  for(int i=0,j=0;i<n;i++){
    for( j=i;j<n;j++){
      if(v[i]>v[j]){m[v[i]]=v[j];break;}
    }
    if(j==n)m[v[i]]=-1;
  }
  int k=0;
  while(k<n){
    for(int i=1;i<n;i++){
      if(m[ans[i-1]]==ans[i])break;
      sol.push_back({ans[i],ans[i-1]});
      int t=ans[i-1];
      ans[i-1]=ans[i];
      ans[i]=t;
    }
    k++;
  }
  cout<<sol.size()<<"\n";
  for(auto x : sol)cout<<x.first<<" "<<x.second<<"\n";
}


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1; 
  // cin>>t;
  while(t--){
    call();
    cout<<endl;
  }
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 780 ms):
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
 
void solve() {
    string s;
    cin>>s;
    
    int n = s.length();
    stack<int>st;
    for(int i=0;i<n;i++) {
        int x = s[i]-'0';
        int j=0;
        vector<int>arr;
        while(!st.empty() && st.top()<(x-j-1)) {
            arr.push_back(st.top());
            st.pop();
            j++;
        }
        st.push(x-j);
        int p = arr.size();
        for(int k=p-1;k>=0;k--) {
            st.push(arr[k]);
        }
    }
    
    string ans = "";
    while(!st.empty()) {
        ans = (char)(st.top() + '0') + ans;
        st.pop();
    }
    cout<<ans<<endl;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    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

const int N=1e5;



int32_t main() {

	ios::sync_with_stdio(0); 

	cin.tie(0);

	ll t;

	cin >> t;

	while (t--) {

		string s;

		cin>>s;

		ll n=s.size();

		for(ll i=0;i<s.size();i++){

			int in=0,idx=0;

			for(int j=i;j<min(n,i+10);j++){

				if(s[j]-j+i-'0'>in) {in=s[j]-j+i-'0'; idx=j;}

			}

			if(in!=s[i]-'0') {

				for(int j=idx-1;j>=i;j--){

					s[j+1]=s[j];

				}

				s[i]=char(in+'0');

			}

		}

		cout<<s<<"\n";

	}	

    return 0;

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

Solution 1 (runtime: 186 ms):
#include <iostream>

#include <vector>

#include <algorithm>

#include <map>

#include <set>

#include <queue>

#include <functional>

#include <cmath>

#include <numeric>

#include <stack>



#define int int64_t

using namespace std;



void solve()

{

    int n, l, r;

    cin >> n >> l >> r;

    vector<int> arr(n, 0);

    for (auto &i : arr)

        cin >> i;

    vector<int> temp;

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

        temp.push_back(arr[i]);

    sort(temp.begin(), temp.end());

    int sumOne = 0, sumTwo = 0;

    for (int i = 0; i < r - l + 1; i++)

        sumOne += temp[i];

    vector<int> tempp;

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

        tempp.push_back(arr[i]);

    sort(tempp.begin(), tempp.end());

    for (int i = 0; i < r - l + 1; i++)

        sumTwo += tempp[i];

    cout << min(sumOne, sumTwo) << "\n";

}



int32_t main()

{

    int t;

    cin >> t;

    while (t--)

        solve();

    return 0;

}



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

#define ll long long

#define endl "\n"

#define IOS \

    ios::sync_with_stdio(0);\

    cin.tie(0);\

    cout.tie(0);

using namespace std;

int main()

{

    IOS;

    int t ;

    cin>>t;

    while(t--)

    {



        ll n, l, r;

        cin>>n>>l>>r;

        vector<ll>v(n);

        vector<ll>v1;

        vector<ll>v2;

        

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

        {

            cin>>v[i];

        }

        

        ll ans = 0 ;

        ll ans1 = 0 ;

        ll j = r-l+1;



        for(int i = 0 ; i < r ;i++ )v1.push_back(v[i]);

        for(int i = l-1 ; i< n ;i++)v2.push_back(v[i]);

        

        sort(v1.begin() , v1.end());

        sort(v2.begin() , v2.end());

        

        for(int i = 0 ; i< j ;i++)ans += v1[i];

        for(int i = 0 ; i< j ;i++)ans1 += v2[i];



        cout<<min(ans,ans1)<<endl;



    }

}