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

Solution 1 (runtime: 218 ms):
#include <bits/stdc++.h>
using namespace std;
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vector <pair<int,int>> res;
    int n; cin>>n;
    vector <int> A(n);
    for (auto &x: A) cin>>x;
    vector <int> vitri(n+1);
    for (int i=1;i<=n;i++) vitri[i]=i;
    vector <int> giatri(n+1);
    for (int i=1;i<=n;i++) giatri[i]=i;
    for (int i=0;i<n;i++){
        while (vitri[A[i]]!=n){
            int a=A[i];
            int b=giatri[vitri[a]+1];
            int c=vitri[a];
            int d=vitri[b];
            res.push_back({b,a});
            swap(giatri[c],giatri[d]);
            swap(vitri[a],vitri[b]);
        }
    }
    cout<<res.size()<<"\n";
    for (auto x: res) cout<<x.first<<" "<<x.second<<"\n";
}

Solution 2 (runtime: 281 ms):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(x) x.begin(), x.end()
#define pll pair<ll, ll>
#define vec vector
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const ll mod = 998244353;
ll fpow(ll a, ll b, ll m = -1)
{
	if (m != -1)
		a %= m;
	ll res = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
		{
			if (m != -1)
				res = res * a % m;
			else
			{
				res *= a;
			}
		}
		a = a * a;
		if (m != -1)
		{
			a %= m;
		}
		b /= 2;
	}
	return res;
}
int main()
{
	fast;
	// freopen("pails.in", "r", stdin);
	// freopen("pails.out", "w", stdout);
	ll t = 1;
	// cin >> t;
end:;
	while (t--)
	{
		ll n, k;
		cin >> n;
		vec<ll> v(n);
		for (int i = 0; i < n; i++)
		{
			cin >> v[i];
		}
		set<ll> st;
		ll mx = 0;
		vec<pll> ans;
		for (int i = 0; i < n; i++)
		{
			for(int j = i - 1; j >= 0; j--)
			{
				swap(v[j+1], v[j]);
				ans.push_back({v[j+1], v[j]});
			}
			ll in = 0;
			while(in < i && v[in]> v[in+1])
			{
				swap(v[in], v[in+1]);
				ans.push_back({v[in+1], v[in]});
				in++;
			}
		}
		reverse(all(ans));
		cout << ans.size() << '\n';
		for (int i = 0; i < ans.size(); i++)
		{
			cout << ans[i].first << ' ' << ans[i].second << '\n';
		}
		
	}
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include <queue>
#include<cmath>
#include <string>
#define vi vector<int>

#define pb push_back
#define vvi vector<vector<int>>
#define ll long long
#define pb push_back
#define ul unsigned long long int
#define lli long long int
#define vll vector<lli>
#define vvll vector<vector<lli>>
#define vul vector<ul>
#define vvul vector<vector<ul>>
#include <set>
using namespace std;
class number {
    public:
    vector<long long > fact ;
    ll mod;
    ll size;
    number(int n ,int k){
        this->mod = k;
        this->size = n;
        fact.resize(n+1);
        
        fact[0]=1;
        fact[1]=1;
        for (ll i=2;i<=n;i++){
            fact[i] = (fact[i-1]*i)%mod;
        }
        
       
        



    }
    int inv(ll a) {
        return a <= 1 ? a : mod - (long long)(mod/a) * inv(mod % a) % mod;
    }
    ll C(int n ,int k){
        if (k==0) return 1;
        if (k>n) return 0;
        if (n==k) return 1;
        ll t= fact[n] * inv(fact[k]*fact[n-k]%mod)%mod;
        return t;
    }
    
};
ll mod = 1e9+7;
//number num1(2e5+5 , 1e9+7);
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";

        

    
    
   

   
    


   





   
    

}
int main (){
    std::ios::sync_with_stdio(false);
    int t ;
    cin>>t;
    while (t--){
        solve();
    }
   // string a,b;
    
}

Solution 2 (runtime: 93 ms):
#include <iostream>
using namespace std;

long long int pow(int r,int n){
  long long int ans=1;
  while(n>0){
    ans*=r;
    n--;
  }
  return ans;
}

int main() {
  int t;
  cin>>t;
  for(int i=0;i<t;i++){
    long long int l,r;
    cin>>l>>r;
    int b=r,count=0,sum=0;
    while(b>0){
      b=b/2;
      count++;
    }
    count--;
    while(count>0){
      long long int f=pow(2,count);
      if(l == f - 1){
        cout<<l + sum<<" "<<l + 1 + sum<<" "<<l + 2 + sum<<endl;
        break;
      }
      else if(r-l==2){
        cout<<r + sum<<" "<<r - 1 + sum<<" "<<l + sum<<endl;
        break;
      }
      else if(f - 2 >= l && f <= r){
        cout<<f + sum<<" "<<f - 1 + sum<<" "<<f - 2 + sum<<endl;
        break;
      }
      else if(f - 2 >= l && f > r){
        count--;
      }
      else{
        l-=f;
        r-=f;
        sum+=f;
        count--;
      }
    }
  }
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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

void solve() {
   long long l,r;
   cin>>l>>r;
   long long ans=0;
   long long a,b,c;
   for(int i=30;i>=0;i--){
      long long l1=0;
      long long r1=0;
      if(l & (1<<i)) l1=1;
      if(r & (1<<i)) r1=1;
      if(l1==r1) ans+= l1*(1<<i) ;
      else{
         a=ans+(1<<i);
         b=a-1;
         break;
      }
   }
   for(int i=l;i<=r;i++){
      if(i!=a && i!=b){
         c=i;
         break;
      }
   }
   cout<<a<<" "<<b<<" "<<c<<endl;
   
   
}

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

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

    return 0;
}


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

string dectobin(long long int n)
{
    string s="";
    while(n>0)
    {
        if(n%2==1)
        {
            s+='1';
        }
        else if(n%2==0)
        {
            s+='0';
        }
        n=n/2;
    }
    int cnt=s.size();
    while(cnt<=31){
    s+='0';cnt++;}
reverse(s.begin(),s.end());
    return s;
}

int bintodec(string s)
{
    int num=0;
    int len=s.length();
    for(int i=0;i<=len-1;i++)
    {
        if(s[i]=='1')
        num+=pow(2,len-1-i);
    }
    return num;
}

int main() {
	int t;cin>>t;
	while(t--)
	{
	    long long int l,r;cin>>l>>r;
	    string lstr=dectobin(l);
	    string rstr=dectobin(r);
	    string temp=lstr;
	    //cout<<rstr<<endl;
	    for(int i=0;i<32;i++)
	    {
	        if(lstr[i]!=rstr[i])
	        {
	            for(int j=i+1;j<32;j++)
	            {
	                rstr[j]='0';
	                lstr[j]='1';
	            }
	            break;
	        }
	    }
	    long long int a=bintodec(rstr);
	    long long int b=bintodec(lstr);
	    if(temp==lstr)
	    {
	        cout<<a<<" "<<b<<" "<<a+1<<endl;
	    }
	    else
	    cout<<a<<" "<<b<<" "<<l<<endl;
	    
	    
	    
	}

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

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
void solve(){
long long l,r;
	cin>>l>>r;
	long long k=l^r;
	long long u=0;
	while(k!=0){
		k=k/2;
		u=u+1;
	}
	u=u-1;
	long long o=(long long)pow(2,u);
	long long s=r-(r%o);
	if(l%o==o-1){
		cout<<s+1<<" "<<s<<" "<<s-1<<endl;
	}else{
		cout<<s<<" "<<s-1<<" "<<s-2<<endl;
	}
}
int main(){
	int t;
	cin>>t;
	while(t){
		solve();
		t--;
	}
}


Solution 2 (runtime: 61 ms):
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
template<class T, class _Cmp = std::less<T>>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, _Cmp, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
using namespace std;
using ll = long long;
using ld = long double;
#ifdef LOCAL
#include "debug.hpp"
#else
#define debug(...)
#endif

void Solve(){
    ll l, r;
    cin >> l >> r;
    ll diff;

    ll val = 0;
    for(ll bit = 31; bit >= 0 ; bit--){
        if(((l>>bit)&1) != ((r>>bit)&1)){
            diff = bit;
            break;
        }
        else if((l>>bit)&1) val += (1 << bit);
    }

    ll ans = 0;
    ans = (1 << (diff + 1)) - 1;
    ans <<= 1;
    // cout << ans << "\n";
    debug(diff)
    ll a = (1 << diff) - 1 + val;
    ll b = a + 1;
    ll c;
    for(ll i = l; i <= r; i++) if(i != a && i!=b) {c = i; break;}

    cout << a << " " << b << " " << c << "\n";

}

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

    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; i++){
        // cout << "Case #" << i << ": ";
        // cerr << "Case #" << i << ": \n";
        Solve();
    }

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: c++17 

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt;
    cin >> tt;
    while (tt--) {
        int n, m;
        cin >> n >> m;
        vector<int> a(n), b(m);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < m; i++) {
            cin >> b[i];
        }
        multiset<int> sa(a.begin(), a.end());
        multiset<int> sb(b.begin(), b.end());
        bool ok = true;
        while (!sa.empty() && !sb.empty() && (int) sa.size() >= (int) sb.size()) {
            auto ita = prev(sa.end());
            auto itb = prev(sb.end());
            int x = *ita;
            int y = *itb;
            sb.erase(itb);
            if (x == y) {
                sa.erase(ita);
                continue;
            }
            if (y < x) {
                break;
            }
            sb.insert(y / 2);
            sb.insert((y + 1) / 2);
        }
        ok &= sa.empty() && sb.empty();
        cout << (ok ? "YES" : "NO") << '\n';
    }
    return 0;
}

Solution 2 (runtime: 421 ms):
//bismillah
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define rep(a, i) for (int i = 0; i < (a); i++)
#define read(a, n) for (int i = 0; i < (n); i++) { cin >> a[i]; }
#define pB pop_back
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define int long long
#define pi pair<long long, long long>
int mod = 998244353;

void solve(){
    int n, m; cin >> n >> m;
    multiset<int> a;
    rep(n, i){
        int aa; cin >> aa;
        a.insert(aa);
    }
    multiset<int> b;
    rep(m, i){
        int aa; cin >> aa;
        b.insert(aa);
    }


    rep(2*n-m, i){
        if(b.empty()){
            cout << "NO";
            return;
        }
        
        int cur = *prev(b.end());
        b.erase(prev(b.end()));

        if(a.find(cur) != a.end()){
            a.erase(a.find(cur));
        }
        else{
            if(cur & 1){
                b.insert(cur/2);
                b.insert(cur/2 + 1);
            }

            else{
                b.insert(cur/2);
                b.insert(cur/2);
            }
        }
        
    }

    if(b.empty()) cout << "YES";
    else
    cout << "NO";
}

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

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<iostream>
#include<vector>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        string n;
        cin>>n;
        int sum=0,count2=0,count3=0;
        for(char ch:n){
            int digit=ch-'0';
            sum+=digit;
            if(ch=='2') count2++;
            else if(ch=='3') count3++;
        }

        long long digitSum=0;
        int ans=0;
        for(int i=0;i<=count2;i++){
            for(int j=0;j<=count3;j++){
                digitSum=(long long)sum%9+(long long)(2*i+6*j);
                if(digitSum%9==0){
                    ans=1;
                    break;
                }
            }
            if(ans==1) break;
        }

        if(ans){
            cout<<"yes";
        }else{
            cout<<"no";
        }
        cout<<endl;
    }
    return 0;
}

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

using namespace std;

#define int long long



signed main () {

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



    int tt; cin >> tt;

    

    while (tt--) {

        string s; cin >> s;

        int n = s.size();

        vector<int> a (n);

        for(int i = 0; i < n; i++) a[i] = s[i] - '0';

        

        vector<vector<int>> dp (n + 1 , vector<int> (10 , 0));

        

        dp[0][a[0] % 9] = 1;

        if(a[0] * a[0] < 10) dp[0][(a[0] * a[0]) % 9] = 1;

        

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

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

              if(dp[i - 1][j]){

                  dp[i][(j + a[i]) % 9] = 1;

                 if(a[i] * a[i] < 10) dp[i][(j + a[i] * a[i]) % 9] = 1;

              }

          }

        }

        

        cout << (dp[n - 1][0] ? "YES\n" : "NO\n");

    }



    return 0;

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

Solution 1 (runtime: 1077 ms):
#include<iostream>
#include<set>
#include<map>
#include<queue>
using namespace std;


int input[100010];

void swap(int &a, int &b){
    int temp =a;
    a=b;
    b=a;
}

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

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

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

    int count = 0;
    vector<pair<int,int> > result;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            if(input[i]==arr[j]){
                for(int l=j+1;l<n;l++){
                    count+=1;
                    result.push_back(pair<int,int>(arr[l], arr[j]));
                    
                }
                for(int l=n-1;l>=j+1;l--){
                    count+=1;
                    result.push_back(pair<int,int>(arr[j], arr[l]));
                    
                }
                
                
                for(int l=j-1;l>=i;l--){
                    count++;
                    result.push_back(pair<int,int>(input[i], arr[l]));
                    arr[l+1] = arr[l];
                }
                arr[i] = input[i];
                break;
            }
        }
        // for(int l=0;l<n;l++){
        //     cout<<arr[l]<<" ";
        // }
        // cout<<endl;

    }

    cout<<result.size()<<endl;
    for(int i=0;i<result.size();i++){
        cout<<result[i].first<<" "<<result[i].second<<endl;
    }
}

Solution 2 (runtime: 390 ms):
//Shraddha aur Saburi
//Om Sai Ram
//Om Namah Shivay

#pragma GCC optimize("O3","O2")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
#include <utility>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <array> 
#include <assert.h>
using namespace std;

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

	int n;
	cin>>n;

	long long a[n];

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

	vector<pair<int,int> > ans;

	for(int i=0;i<n-1;i++){
		set<int> big;
		set<int,greater<int> > big1,small;
		for(int j=i+1;j<n;j++){
			if(a[i]<a[j]){
				big.insert(a[j]);
				big1.insert(a[j]);
			}
			else{
				small.insert(a[j]);
			}
		}

		for(auto x:big){
	
			ans.push_back({x,a[i]});
		}
		for(auto x:big1){
			ans.push_back({a[i],x});
		}

		for(auto x:small){
			ans.push_back({a[i],x});
		}
	}


	cout<<ans.size()<<"\n";
	for(int i=0;i<ans.size();i++){
		cout<<ans[i].first<<" "<<ans[i].second<<"\n";
	}


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

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

#define endl "\n"
#define ull unsigned long long
#define ll long long
#define int long long
#define PLL pair<ll, ll>
#define PULL pair<ull, ull>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define lep(i,a,b) for(int i=(a);i>=(b);i--)
#define sci(x) cin >> (x)
#define pli(x) cout << (x) << " ";
#define pll(x) cout << (x) << '\n';
#define yes cout << "Yes" << '\n';
#define no cout << "No" << '\n';
#define ls i << 1
#define rs i << 1 | 1
#define pb push_back
using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a(n + 1);
    rep(i, 1, n) cin >> a[i];
    sort(a.begin() + l, a.begin() + r + 1, greater<int>());
    sort(a.begin() + 1, a.begin() + l);
    sort(a.begin() + r + 1, a.end());
    int M1 = 0, M2 = 0;
    rep(i, 1, r - l + 1) {
        if (r + i > n || a[l + i - 1] <= a[r + i]) {
            rep(j, l + i - 1, r) M1 += a[j];
            break;
        } 
        M1 += a[r + i];
    }
    rep(i, 1, r - l + 1) {
        if (i == l || a[l + i - 1] <= a[i]) {
            rep(j, l + i - 1, r) M2 += a[j];
            break;
        } 
        M2 += a[i];
    }
    // cerr << M2 << endl;
    cout << min(M1, M2) << endl;
}   

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

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

#include<vector>

#include<algorithm>

#include<cmath>

using namespace std;

using ll=long long;

void solve(){

    int l,r,n;

    cin>>n>>l>>r;

    vector<ll>a(n+1);

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

    //由于整个进行反转的话，前面和后面不相等的元素就影响不到当前的点

    //所以要想可以影响大的话，就需要从1开始，所以现在的需要计算的是

    //[1,r][l,n]的最小值

    vector<ll>val1,val2;

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

        val1.push_back(a[i]);

    }

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

        val2.push_back(a[i]);

    }

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

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

    ll _val1=0,_val2=0;

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

        _val1+=val1[i];

        _val2+=val2[i];

    }

    cout<<min(_val1,_val2)<<'\n';

    return ;

}

int main(){

    int _;

    cin>>_;

    while(_--)solve();

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 77 ms):
/**
 *    author:  Rohit
 *    created: 2024.12.27 19.18.34
 **/
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        string s ;
        cin>>s;
        int three = 0 ;
        int two = 0;
        long long total = 0 ;
        bool flag = false;
        for(auto i :s ){
            if(i=='2'){
                two++;
            }else if(i=='3'){
                three++;
            }
            total += (i -'0');
        }
        for(int i = 0 ;i<=two ; i++){
            for(int j = 0; j<=three ; j++){
                long long totall  = total ;
                totall += 2*i + 6*j ;
                if(totall%9==0){
                    flag = true ;
                    break;
                }
            }
            if(flag==true){
                break;
            }
        }
        if(flag){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

Solution 2 (runtime: 1686 ms):
#include <ostream>

#include <cstdio>

#include <algorithm>

#include<list>

#include<queue>

#include <iostream>

#include <cstring>

#include <math.h>

#include <cmath>

#include <string>

using namespace std;

int t,total,num2,num3;

char num[100005];

int main(){

    scanf("%d",&t);

    while (t--)

    {

        total = 0;

        num2 = 0;

        num3 = 0;

        scanf("%s",num);

        for (int i = 0; i < strlen(num); i++)

        {

            total += (num[i] - '0');

            if (num[i] == '2')

            {

                num2 ++;

            }

            if (num[i] == '3')

            {

                num3 ++;

            }

            

        }

        if (total%9 == 0)

        {

            printf("YES\n");

            continue;

        }

        

        if ((total%9)%2 == 0)

        {

            total = 18-(total%9);

        }else{

            total = 9-(total%9);

        }



        int temp = num2+num3;

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

       {

        if (total == 0)

        {

            printf("YES\n");

            break;

        }

        

         if (total>=6 && num3>0)

         {

            total -= 6;

            num3--;

         }

         else if (total>=2 && num2>0)

         {

            total -= 2;

            num2--;

         

         

         

       }

       

        

    }

    if (total == 0)

    {

        continue;

    }

    

    printf("NO\n");

        

}

    

    return 0;

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

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

#define int long long
#define sp ' '

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    int c = sum;
    if (n == 1)
    {
        cout << a[0] << endl;
        return;
    }

    for (int i = 1; i < n; i++)
    {
        vector<int> b;
        for (int i = 0; i < a.size() - 1; i++)
            b.push_back(a[i + 1] - a[i]);

        int s = accumulate(b.begin(), b.end(), 0LL);
        c = max( c , max(s, -s));
        a = move(b);
    }
    cout << c << endl;
}
signed main(void)
{
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}


Solution 2 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        vector<ll> a(n);
        ll ans=0;
        for(int i=0; i<n; i++){
            cin >> a[i];
            ans+= a[i];
        }
        int s=a.size();
        while(s>1){
            ans = max(ans, abs(a[s-1] - a[0]));
            for(int i=0; i<s-1; i++){
                a[i] = a[i+1] - a[i];
            }
            a.pop_back();
            s-=1;
        }
        cout << ans << "\n";
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read(){
	ll n=0; int f=1;
	char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=-1; c=getchar();}
	while(c>='0'&&c<='9') n=(n<<1)+(n<<3)+c-'0',c=getchar();
	return n*f;
}
int n,l,r;
const int N=1e5+5;
ll a[N],s[N];
int main(){
	int T=read();
	while(T--){
		n=read(),l=read(),r=read();
		for(int i=1;i<=n;i++) a[i]=read();
		sort(a+1,a+l);
		sort(a+l,a+r+1);
		sort(a+r+1,a+n+1);
		for(int i=1;i<=n;i++) s[i]=s[i-1]+a[i];
		int len=r-l+1;
		ll ans=s[r]-s[l-1];
		for(int p=1;p<=min(len,l-1);p++){
			ans=min(ans,s[r-p]-s[l-1]+s[p]);
		}
		for(int p=1;p<=min(len,n-r);p++){
			ans=min(ans,s[r-p]-s[l-1]+s[r+p]-s[r]);
		}
		printf("%lld\n",ans);
	}

	return 0;
}



Solution 2 (runtime: 124 ms):
def solve():

    n,l,r=tuple(map(int,input().split()))

    a=list(map(int,input().split()))

    l-=1

    r-=1

    ll=a[:r+1]

    rr=a[l:]

    ll.sort()

    rr.sort()

    print(min(sum(ll[0:r-l+1]),sum(rr[0:r-l+1])))

T=int(input())

for _ in range(T):

    solve()