ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

using namespace std ;

typedef long long int ll ; 

int main()
{
    ll n ;
    cin >> n ;
    vector<ll> a(n) ;
    for( ll i = 0 ; i < n ; i++ )
    {
        cin >> a[i] ;
    }
    
    //LOGIC
    
    vector<pair<ll,ll>> ans ;
    for( ll i = 0 ; i < n ; i++ )
    {
        ll b = a[i] ;
        vector<pair<ll,ll>> vc1, vc2, vc3 ; 
        for( ll j = i + 1 ; j < n ; j++ )
        {
            if( i < n && j < n && a[i] > a[j] )
            {
                vc2.push_back( { a[i] , a[j] } ) ;
            }
            else if( i < n && j < n ) // this says that all the members are greater than a[i] 
            {
                vc1.push_back( { a[j] , a[i] } ) ;
            }
        }
        sort( vc1.begin() , vc1.end() ) ;
        sort( vc2.begin() , vc2.end() ) ;
        reverse( vc2.begin() , vc2.end() ) ;
        for( ll i = vc1.size(); i-- > 0; )
        {
            vc3.push_back( { vc1[i].second , vc1[i].first } ) ;
        }
        for( ll i = 0 ; i < vc1.size() ; i++ )
        {
            ans.push_back(vc1[i]) ;
        }
        for( ll i = 0 ; i < vc3.size() ; i++ )
        {
            ans.push_back( vc3[i] ) ;
        }
        for( ll i = 0 ; i < vc2.size() ; i++)
        {
            ans.push_back( vc2[i] ) ;
        }
    }
    
    cout << ans.size() << endl ;
    for( ll i = 0; i < ans.size() ; i++ )
    {
        cout << ans[i].first << " " << ans[i].second << endl ;
    }
    return 0 ;
}

Solution 2 (runtime: 1109 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()

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

    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    // ll cnt=0;
    vector<pair<ll,ll>> ans;
    for(ll i=n-1;i>=0;i--)
    {
        for(ll j=0;j<n-1;j++)
        {
            if(a[j]<a[j+1])
            {
                swap(a[j],a[j+1]);
                ans.pb({a[j],a[j+1]});
            }
        }
    }
    for(ll i=n-1;i>=0;i--)
    {
        for(ll j=0;j<n-1;j++)
        {
            if(a[j]>a[j+1])
            {
                swap(a[j],a[j+1]);
                ans.pb({a[j],a[j+1]});
            }
        }
    }
    reverse(all(ans));
    cout<<ans.size()<<endl;
    for(auto &[x,y]:ans)
    {
        cout<<y<<" "<<x<<endl;
    }
    // cout<<cnt<<endl;
    // for(auto &[x,y,z]:ans)
    // {
    //     if(z==0)
    //     {
    //         cout<<x<<" "<<y<<endl;
    //     }
    // }
    // for(auto &[x,y,z]:ans)
    // {
    //     if(z==1)
    //     {
    //         cout<<y<<" "<<x<<endl;
    //         cout<<x<<" "<<y<<endl;
    //     }
    // }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;

LL a[55];
void solve()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	LL ans = -1e18;
	int num = n;
	for (int i = 1; i <= n; i++)
	{
		LL sum = 0;
		for (int i = 1; i <= num; i++) sum += a[i];
		if (i == 1) ans = max(ans, sum);
		else ans = max(ans, max(sum, -sum));
		for (int i = 1; i < num; i++) a[i] = a[i + 1] - a[i];
		num--;
	}
	cout << ans << endl;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
 
long long a[1010];
 
int main(){
	int t;
	cin >> t;
	while (t--){
		int n;
		cin >> n;
		
		for (int i = 1; i <= n; i++){
		    cin >> a[i];
		}
		
		int now = n;
		long long ans = INT_MIN;
		for (int i = 1; i <= n; i++){
			long long sum = 0;
			for (int i = 1; i <= now; i++){
			    sum = (sum + a[i]);
			}
			if (i == 1) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 1; i < now; i++){
			    a[i] = (a[i + 1] - a[i]);
			}
			now--;
		}
		cout << ans << endl; 
	}
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):

/* Programmed by : https://www.linkedin.com/in/ritik-shankar-537741264/ */

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

void solve()
{
    int n;
    cin>>n;
    vector<int> arr(n);
    forn(i,n)cin>>arr[i];
    if(is_sorted(all(arr))){
        cout<<"YES"<<endl;
        return;
    }
    bool flag=true;
    for(int i=0;i+1<n;i++){
        int mini = min(arr[i],arr[i+1]);
        arr[i]-=mini;
        arr[i+1]-=mini;

    }
    // for(auto& ele:arr)cout<<ele<<" ";
    // cout<<endl;
    if(is_sorted(all(arr)))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
int main()
{
    fast_cin();
    ll t;
    cin >> t;
    for (int it = 1; it <= t; it++)
    {
        solve();
    }
    return 0;
}

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

#define X first
#define Y second
#define pb push_back
#define pii pair<int,int>
#define spacce cerr << "====" << endl
const int maxn = 2e5 + 5;
const int INF = 1e9;
const int MOD = 998244353;
void solve()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin>>a[i];
    for(int i = 0; i < n-1; i++)
    {
        if(a[i] > a[i+1])
        {
            cout << "NO" << endl;
            return;
        }
        a[i+1] -= a[i];
        a[i] = 0;
    }
    cout << "YES" << endl;
}

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

    bool tc = 1;
    int ttt = tc ? (cin >> ttt, ttt) : 1;

    while(ttt--)
        solve(), spacce;

    return 0;
}



//    _  __   ________   _      _____
//   / |/ /__/_  __/ /  (_)__  / ___/
//  /    / _ \/ / / _ \/ / _ \/ (_ / 
// /_/|_/\___/_/ /_//_/_/_//_/\___/   is real.
//
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 93 ms):
// #include<bits/stdc++.h>
// using namespace std;
// #define int long long
 
// void solve() {
//     int n,k;
//     cin>>n>>k;
//     vector<int> arr(n);
//     for(int i=0;i<n;i++){
//         cin>>arr[i];
//     }
//     map<int,int> mp;
//     for(int i=0;i<n;i++){
//         mp[arr[i]]++;
//     }
//     vector<pair<int,int>> vect;
//     for(auto it = mp.begin(); it != mp.end(); it++){
//         vect.push_back({it->second,it->first});
//     }
//     sort(vect.begin(),vect.end());
//     int ans = vect.size();
//     int i=0;
//     while(k != 0){
//          k = k - vect[0].first;
//          i++;
//          ans--;
//     }
//     if(ans == 0){
//         cout<<'1'<<endl;
//         return;
//     }
//     cout<<ans<<endl;
// }
 
// signed main() {
//     ios::sync_with_stdio(0);
//     cin.tie(0);
//     int t = 1;
//     cin >> t;
//     while(t--) {
//         solve();
//     }
//     return 0;
// }


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

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);

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

    map<int, int> freq;
    for (int i = 0; i < n; i++) {
        freq[arr[i]]++;
    }

   priority_queue<int, vector<int>, greater<int>> minHeap;
   for (auto it = freq.begin(); it != freq.end(); ++it) {
    minHeap.push(it->second);
}

    int uniqueCount = freq.size();
    while (!minHeap.empty() && k >= minHeap.top()) {
        k -= minHeap.top();
        minHeap.pop();
        uniqueCount--; 
    }

    if(uniqueCount == 0){
        cout<<'1'<<endl;
        return;
    }
    cout << uniqueCount << endl;
}

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

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


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

using namespace std;

int main() {
	int t;
	cin>>t;
	while(t>0) {
		int n,k;
		cin>>n>>k;
		vector<int> v;
		map<int,int> st;
		for(int i=0;i<n;i++) {
			 int x;cin>>x;
			 v.push_back(x);
			 st[x]++;
		}
		if(k==0) {
			cout<<st.size()<<endl;
		}
		else if(k==n) {
			cout<<1<<endl;
		}
		else {
			int ans= st.size();
			vector<int> v;
			for(auto it:st) {
				v.push_back(it.second);
			}
			sort(v.begin(),v.end());
			int i=0;
			int m= v.size();
			while(k>0 && i<m) {
				if(v[i]<=k) {k-=v[i]; ans--;}
				i++;
			}
			cout<<ans<<endl;
		}
		t--;
	}
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

using namespace std;

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

    vector<pair<int, int>> ans;
    vector<bool> vis(n+1, false);
    for (int i = place.size() - 1; i >= 0; i--) {
        int x = place[i]-1, y = i;
        vis[place[i]] = true;
        while (x > 0) {
            if (!vis[x]) {
                ans.push_back({ place[i], x });
                //cout << place[i] << ' ' << x << endl;
            }
            x--;
        }

        //cout << "---------" << endl;

        while (y) {
            x++;
            if (vis[x])
                continue;
            ans.push_back({ x, place[i] });
            //cout << x << ' ' << place[i] << endl;
            y--;
        }

        cout << endl;
    }

    cout << ans.size() << endl;
    for (auto x : ans)
        cout << x.first << ' ' << x.second << endl;

    return 0;
}

Solution 2 (runtime: 1155 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
void solve()
{
    int n; cin >> n;
    vector<int>cars(n);
    map<int, int>mp;
    for(int i = 0; i < n; i++){
        cin >> cars[i];
    }

    int count = 0;
    vector<pair<int, int>>v;
    
    pair<int, int>temp;
    for(int i = 0; i < n; i++){
        vector<int>overtakes;
        for(int j = cars[i] + 1; j <= n; j++){
            if(mp[j] == 0){
                overtakes.push_back(j);
                overtakes.push_back(cars[i]);
            }
        }
        for(int j = overtakes.size() - 1; j >= 0; j--){
            overtakes.push_back(overtakes[j]);
        }
        for(int j = cars[i] - 1; j >= 1; j--){
            if(mp[j] == 0){
                overtakes.push_back(cars[i]);
                overtakes.push_back(j);
            }
        }
        for(int j = 0; j < overtakes.size(); j+=2){
            // cout << overtakes[j] << " " << overtakes[j + 1] << endl;
            pair<int, int>p(overtakes[j], overtakes[j + 1]);
            v.push_back(p);
        }
        mp[cars[i]]++;
    }
    // for(int i = 0; i < v.size(); i++){
    //     int j = i + 1; 
    //     while(j < v.size()){
    //         if(v[j].second < v[i].second){
    //             swap(v[i], v[j]);
    //         }
    //         j++;
    //     }
    // }
    cout << v.size() << endl;
    for(auto i: v) cout << i.first << " " << i.second << endl;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll test = 1;
    // cin >> test;
    while(test--)
    {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

#define ll long long
#define _RUN_MORE_THAN_ONCE
#define _FASTER_IO ios::sync_with_stdio(false); cin.tie(nullptr)

void SOLVE() {

    ll n;
    cin >> n;

    ll max_n = 0;
    vector<ll> A(n);

    for (auto &a: A) {
        cin >> a;
        max_n = max(max_n, a);
    }

    A.push_back(max_n);

    bool yes = true;

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

        ll min_n = min(A[i - 1], A[i]);
        
        A[i] -= min_n;
        A[i - 1] -= min_n;

        if ((A[i - 1] > A[i]) && (A[i] <= A[i + 1]) && (A[i] == 0)) {
            yes = false;
        }

    }

    cout << (yes ? "YES" : "NO") << '\n';

}

int main() {

    _FASTER_IO;

    ll tc;

    #ifndef _RUN_MORE_THAN_ONCE
        tc = 1;
    #else
        cin >> tc;
    #endif

    while (tc--) {
        SOLVE();
    }

    return 0;
}

Solution 2 (runtime: 374 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define inf INT_MAX
#define ff first
#define ss second
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pr1(a) for(auto& i:a) cout << i << " "; cout << "\n";
#define pr2(a) for(auto& i:a){for(auto& j:i){cout<<j<<" ";}cout<<"\n";}

const int mod = 1000000007;

void init_code() {
    fast_io;
#ifndef ONLINE_JUDGE    
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

int main() {
    ll t;cin>>t;
    while(t--){
        ll n;cin>>n;
        vector<ll> v(n);
        for(auto& i:v) cin>>i;
        
        ll i = n-2;
        while(i >= 0 && v[i] <= v[i+1]) i--;
        
        if(i == -1){
            cout<<"YES\n";
            continue;
        }
        
        for(int j=0;j<i;j++){
            ll mn = min(v[j], v[j+1]);
            v[j] -= mn;
            v[j+1] -= mn;
        }
        
        ll ok = 1;
        for(int i=1;i<n;i++){
            if(v[i-1] > v[i]){
                ok = 0;
                break;
            }
        }
        
        if(ok) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        map<int, int> mp;
        vector<int> arr;
        for(int i=0; i<n; i++){
            int x;
            cin>>x;
            mp[x]++;
        }

        for(auto i=mp.begin(); i!=mp.end(); i++)
            arr.pb(i->second);

        sort(arr.begin(), arr.end());  
        int count=arr.size();

        for(int i=0; i<arr.size(); i++){
            if(arr[i]<=k){
                k-=arr[i];
                count--;
            }
            else    break;
        }
        if(count==0)    count++;

        cout<<count<<"\n";
    }
}

Solution 2 (runtime: 264 ms):
#include <bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
	int t;
	cin>>t;
	while(t--){
		long long n,m;
		cin>>n>>m;
		mp.clear();
		for(int i=1;i<=n;i++){
			int a;
			cin>>a;
			mp[a]++;
		}
		multiset<int>st;
		for(auto b:mp)
			st.insert(b.second);
		int ans=st.size();
		for(int a:st){
			if(m>=a)ans--,m-=a;
		}cout<<max(1,ans)<<'\n';
	}
}
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;

using ll = long long;

void fileIO(){

#ifndef ONLINE_JUDGE

    freopen("../input.txt", "r", stdin);

    freopen("../output.txt", "w", stdout);

#endif

}





void solve(){

    int n;

    cin >> n;

    string s;

    cin >> s;

    int p_idx = n - 1, s_idx = 0;

    if (s_idx < n && s[s_idx] == 's') s_idx ++;

    if (p_idx >= 0 && s[p_idx] == 'p') p_idx --;

    int p_cnt = 0, s_cnt = 0;



    for (int i = s_idx ; i <= p_idx ; ++i) {

        p_cnt += s[i] == 'p';

        s_cnt += s[i] == 's';

    }



    //sspp



    if(p_cnt > 0 && s_cnt > 0){

        return void(cout << "NO\n");

    }



    cout << "YES\n";

}



int main(){

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

    fileIO();

    int t = 1;

    cin >> t;

    for (int it = 1; it <= t; it++)

    {

        solve();

    }



    return 0;

}

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

#define ep emplace_back

#define mp make_pair

using namespace std;

using i64=long long;



void solve() {

    int n;

    string s;

    cin >> n >> s;

    if(s[0] == 'p') {

        bool flag = false;

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

        flag |= (s[i] == 's');

        if(flag) cout << "NO\n";

        else cout << "YES\n";

    }

    else if(s[n-1] == 's') {

        bool flag = false;

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

        flag |= (s[i] == 'p');

        if(flag) cout << "NO\n";

        else cout << "YES\n";

    }

    else {

        bool flag[2] = {false, false};

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

            flag[0] |= (s[i] == 's');

            flag[1] |= (s[i] == 'p');

        }

        if(flag[0] && flag[1]) cout << "NO\n";

        else cout << "YES\n";

    }

}



int main() {

    ios::sync_with_stdio(false);

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



    int t;

    cin >> t;

    while(t--)

    solve();



    return 0;

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

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

static const int inf = 1e9;

void solve() {
    std::string a, b, res;
    std::cin >> a >> b >> res;
    int n = (int) a.size(), m = (int) b.size();
    int dp[n + 1][m + 1];
    std::fill(&dp[0][0], &dp[0][0] + (n + 1) * (m + 1), inf);
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = dp[i][0] + (a[i] != res[i]);
    }
    for (int j = 0; j < m; j++) {
        dp[0][j + 1] = dp[0][j] + (b[j] != res[j]);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = std::min(dp[i - 1][j] + (a[i - 1] != res[i + j - 1]),
                                dp[i][j - 1] + (b[j - 1] != res[i + j - 1]));
        }
    }
    std::cout << dp[n][m] << std::endl;
}

int main() {
    int tests;
    std::cin >> tests;
    while (tests--) {
        solve();
    }
}

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

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin>>t;
    
    while(t--){
    	string a,b,c;
    	cin>>a>>b>>c;
    	
    	int n = a.size(), m=b.size();
    	
    	vector<vector<int>> dp(n+1, vector<int>(m+1,INT_MAX));
    	
    	dp[0][0] = 0;
    	
	    for (int i=0; i<n; i++) {
	        dp[i+1][0] = dp[i][0] + (a[i] != c[i]);
	    }
	    for (int j=0; j<m; j++) {
	        dp[0][j+1] = dp[0][j] + (b[j] != c[j]);
	    }
    	
    	
    	for(int i=1; i<=n; i++){
    		for(int j=1; j<=m; j++){
    			
    			if(a[i-1]==c[i+j-1]){
    				dp[i][j] = dp[i-1][j];
    			}
    			else{
    				dp[i][j] = dp[i-1][j]+1;
    			}
    			
    			if(b[j-1]==c[i+j-1]){
    				dp[i][j] = min(dp[i][j-1], dp[i][j]);
    			}
    			else{
    				dp[i][j] = min(dp[i][j-1]+1, dp[i][j]);
    			}
    			
    		}
    	}
    	
    	cout<<dp[n][m]<<endl;
    	
    	
    	
    }
    

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

Solution 1 (runtime: 78 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,l,r;cin>>n>>l>>r;
  		vector<int>v(n);
  		for(int i=0;i<n;++i)cin>>v[i];
  		vector<int>a,b,c;
  		int sum=0;
  		for(int i=0;i<n;++i)
  		{
  			if(i<l-1)
  			{
  				a.pb(v[i]);
  			}
  			else if(i>=r)
  			{
  				c.pb(v[i]);
  			}
  			else
  			{
  				b.pb(v[i]);
  				sum+=v[i];
  			}
  		}
  		sort(a.begin(),a.end());
  		sort(b.begin(),b.end());
  		sort(c.begin(),c.end());
  		vector<int>temp=b;
  		int tsum=sum;
  		for(int i=0;i<a.size();++i)
  		{
  			if(b.size()==0)
  			{
  				break;
  			}
  			if(a[i]<b.back())
  			{
  				sum-=b.back();
  				sum+=a[i];
  				b.pop_back();
  			}
  		}  
  		for(int i=0;i<c.size();++i)
  		{
  			if(temp.size()==0)
  			{
  				break;
  			}
  			if(c[i]<temp.back())
  			{
  				tsum-=temp.back();
  				tsum+=c[i];
  				temp.pop_back();
  			}
  		}  			
  		cout<<min(sum,tsum)<<endl;
  		
  	
  		
  		
  		
  	
	
		
	}
  		
  		
  		
  		
  		
  		
  		
  		
  		
  		
   
    signed main(){FAST TEST{solve();}}

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

using namespace std;



int main() {

    int t;

    cin >> t;

    while (t>0) {

        int n, l, r;

        cin >> n >> l >> r;

        l--;

        vector<int> a(n);

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

            cin >> a[i];

        }

        

        vector<int> b(a.begin(), a.begin() + l);

        vector<int> c(a.begin(), a.end());

        sort(a.begin() + l, a.end());

        b.insert(b.end(), a.begin() + l, a.end());

        sort(c.begin(), c.begin() + r, greater<int>());

        

        long long sum1= 0;

        for (int i = l; i < r; i++) {

            sum1+= b[i];

        }

        

        long long sum2 = 0;

        for (int i = l; i < r; i++) {

            sum2+= c[i];

        }

        cout << min(sum1, sum2) << endl;

        t--;

    }

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

Solution 1 (runtime: 61 ms):
#include<bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(0);
    int t;
    cin >> t;
    while(t--)
    {
        int l, r;
        cin >> l >> r;
        int a = l;
        int k = l ^ r;
        for(int i = 31; i >= 0; i--)
        {
            if((1 << i) & k)
            {
                a = a | ((1 << i) - 1);
            }
        }
        int b = a + 1;
        int c = (a == l ? r : l);
        cout << a << " " << b << " " << c << endl;
    }
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
 
using i64 = long long;
 
void solve() {
    int l, r;
    std::cin >> l >> r;
    int k = 31 - __builtin_clz(l ^ r);
    int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
    std::cout << a << " " << b << " " << c << "\n";
}
 
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
 
    int t = 1;
    std::cin >> t;
 
    while (t--) {
        solve();
    }
}