ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: c++17 

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

int main(){
    int t;
    cin>>t;
    while (t--)
    {
        int n;
        cin>>n;
        long long int a[n];
        long long int ans =INT_MIN;
        long long int sum=0;

        for (int i = 0; i < n; i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
        ans=max(ans,sum);
        for (int j = 0; j < n-1; j++)
        {
                a[j]=a[j+1]-a[j];
        }
        int now=n-1;
        for (int i = 1; i < n; i++)
        {
            sum=0;
            for (int j = 0; j < now; j++)
            {
                sum+=a[j];
            }
            
            ans=max(ans,max(sum,-sum));
            for (int j = 0; j < now; j++)
            {
                a[j]=a[j+1]-a[j];
            }
            now--;
        }
        cout<<ans<<endl;

        
    }
}

Solution 2 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define X(a) (a).begin(), (a).begin()
#define ii pair<int,int>
typedef long long int ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;cin>>n;
        vector<ll>a(n);
        for(int i=0;i<n;i++) cin>>a[i];
        if(n==1){
            cout<<a[0]<<endl;continue;
        }
        ll res=INT_MIN;
        int k=1;
        while(n!=1){
            ll x=0;
            for(int i=0;i<n;i++) x+=a[i];
            n--;
            for(int i=0;i<n;i++) a[i]=a[i+1]-a[i];
            if(!k) res=max(res,abs(x));
            else{
                res=max(res,x);k=0;
            }
            
        }
        cout<<max(res,abs(a[0]))<<endl;
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 203 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
 cin>>t;
  while(t--){
    int n,l,r;
    
    cin>>n>>l>>r;
    l=l-1;
    r=r-1;
    vector<int> v;
    for(int i=0;i<n;i++){
       int a;
       cin>>a;
       v.push_back(a);
    }
     vector<int> left;
     vector<int> right;
     for(int i=0; i<=r;i++){
      left.push_back(v[i]);
     }
     for(int i=l; i<n;i++){
      right.push_back(v[i]);
     }
     int k=r-l+1;
     sort(left.begin(),left.end());
     sort(right.begin(),right.end());
     long long int sum_left=0, sum_right=0;
     for(int i=0;i<k;i++){
      sum_left=sum_left+left[i];
     }
     for(int i=0;i<k;i++){
      sum_right=sum_right+right[i];
     }
    //  for(int value:left){
    //   cout<<value<<" ";
    //  }
    //  cout<<endl;
    //  for(int value:right){
    //   cout<<value<<" ";
    //  }
    //  cout<<endl;
    //  cout<<sum_left <<" "<<sum_right<<endl;
     cout<<min(sum_left,sum_right)<<endl;
  }
return 0;
}

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

#include<algorithm>

#define int long long



using namespace std;



const int N = 1e5;

int t , n , l , r;

int a[N+10] , b[N+10] , c[N+10];



bool cmp( int x , int y ){

    return x > y;

}



signed main(){

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

        cin >> n >> l >> r;

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

            cin >> a[i];

            b[i] = c[i] = a[i];

        }

        sort( b + l , b + n + 1 );

        sort( c + 1 , c + r + 1 , cmp );

        int b_ans , c_ans;b_ans = c_ans = 0;

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

            b_ans += b[i] , c_ans += c[i];

        }cout << min( b_ans , c_ans ) << endl;

    }

    return 0;

}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 233 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
const int INF = 2e9;
int deg[N], id[N];
vector <int> v[N];
bool cmp(int i, int j) {
	return deg[i] > deg[j];
}
void solve() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		deg[i] = 0, id[i] = i;
		v[i].clear();
	}
	for(int i = 1; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		deg[x]++, deg[y]++;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	sort(id + 1, id + n + 1, cmp);
	int cnt = 1;
	for(int i = 2; i <= n; i++) {
		if(deg[id[i]] != deg[id[i - 1]]) break;
		cnt++;
	}
	if(cnt >= 3) {
		printf("%d\n", deg[id[1]] * 2 - 1);
		return;
	}
	int ans = deg[id[1]];
	deg[id[1]] = 0;
	for(auto t : v[id[1]]) {
		deg[t]--;
	}
	sort(id + 1, id + n + 1, cmp);
	ans += deg[id[1]] - 1;
	printf("%d\n", ans);
}
int main() {
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);
    int T = 1;
	scanf("%d", &T);
	while(T--) solve();

    return 0;
}

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

using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t > 0){
        t--;
        int n;
        cin >> n;
        vector <vector <int>> ne(n+1);
        vector <int> deg(n+1);
        for(int i = 0; i < n - 1; i++){
            int a, b;
            cin >> a >> b;
            deg[a]++;
            deg[b]++;
            ne[a].push_back(b);
            ne[b].push_back(a);
        }
        int ma = 0, max_deg = 0, num = 0;
        for(int i = 1; i < n+1; i++){
            if(max_deg < deg[i]){
                max_deg = deg[i];
                num = 1;
            }
            else if (max_deg == deg[i])
                num++;
            for(int j = 0; j < deg[i]; j++){
                ma = max(ma, deg[i] + deg[ne[i][j]] - 2);
            }
        }
       
        int ma1 = 0;
        if(num > 1)
            for(int i = 1; i < n + 1; i++){
                int num1= 0;
                if (deg[i] == max_deg){
                    for(int j = 0;  j < deg[i];j++){
                        if(deg[ne[i][j]] == max_deg)
                            num1++;
                    }
                    if(num1 < num - 1){

                        ma = 2 * max_deg - 1;
                        break;
                    }
                }
            }
        else{
            for(int i = 1; i < n+1; i++){
                if(deg[i] > ma1 && deg[i] < max_deg)
                    ma1 = deg[i];
            }
            for(int i = 1; i < n+1; i++){
                if(deg[i] == ma1){
                    bool x = 1;
                    for(int j = 0; j < deg[i];j++){
                        if(deg[ne[i][j]] == max_deg)
                            x = 0;
                    }
                    if(x){
                        ma = max_deg + ma1 - 1;
                        break;
                    }
                }
            }
        }

        cout << ma << endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

typedef long long ll;

int main() {
  int t;
  cin >> t;
  
  while (t--) {
    int n;
    cin >> n;
    
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ans += a[i];
    }
    
    int last = n - 1;
    while (last > 0) {
      ll cur_sum = 0;
      for (int i = 0; i < last; i++) {
        a[i] = a[i + 1] - a[i];
        cur_sum += a[i];
      }
      last--;
      
      ans = max(ans, max(cur_sum, -cur_sum));
    }
    
    cout << ans << endl;
   }
}

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

using namespace std;

// rename macro of operations using typedef
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef vector<string> vss;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<ll,ll>> vpl;
typedef vector<vector<int> > vvii;
typedef vector<vector<ll> > vvll;

// rename macro of opearations using define
#define fori(i,s,n) for(i=s; i<n; i++)
#define nl "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sij(x) ((ll)(x).size())

// const values 
ll Mod = 1e9+7;
int mod = 1e9+7;
double pie = 3.141592653589793 ;
int inf = INT_MAX;
ll Inf = 1e18 ;

/********define global variable here********/

/*******************Code Start from here**********/



void solve()
{
    int n;
		cin >> n;
        vll a(n+1);
		for (int i = 1; i <= n; i++) cin >> a[i];
		int now = n;
		long long ans = -1e18;
		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;

}

int32_t main()
{
     fast_cin();

     int t=1;
     cin >> t;
     for(int it=1;it<=t;it++)
     {
        // cout << "Case #" << it << ": \n";
        solve(); 
     }

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

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


bool sorted(vector<int> a,int n){
    for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
           return false;
        }      
    }
    return true;
}


int main(){
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        vector<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]){
                a[i+1]=a[i+1]-a[i];
                a[i]=0;
                
            }
        }


        if(sorted(a,n)){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

    }
}

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

using namespace std;

#define ll long long

void solve ()

{

int n;

cin>>n;

vector<int>v;

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

{

int c;

cin>>c;

v.push_back(c);

}

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

{

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

v[i]-=m;

v[i+1]-=m;

}

bool flag=1;

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

{

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

{

flag=0;

break;

}

}



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

else cout<<"NO"<<endl;



}



int main()

{

ios_base::sync_with_stdio(false);

cin.tie(NULL);

cout.tie(NULL);

// #ifndef ONLINE_JUDGE

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

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

// #endif

int t;

cin >> t;

while (t--)

solve();

}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 124 ms):
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define endl '\n'
#define int long long
#define ld long double
#define PII pair<int,int>
#define mod 1000000007
#define INF 1e18+9
#define yes() cout << "YES\n"
#define no() cout << "NO\n"
#define yn(c) (c) ? yes() : no()
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define inpt(a, n) for(int i=0; i<n; i++) cin >> a[i];

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  return uniform_int_distribution<int>(x, y)(rng);
}

void solve(){
	int n, k; cin >> n >> k;
	map<int, int> cnt;
	for(int i=0; i<n; i++){
		int x; cin >> x;
		cnt[x]++;
	}
	vector<PII> vals;
	for(auto x:cnt) vals.push_back({x.S, x.F});
	sort(all(vals));
	int ans = vals.size();
	for(auto x:vals){
		if(k >= x.F && ans > 1){
			k -= x.F; ans--;
		}else break;
	}
	cout << ans << endl;
}

signed main(){
#ifdef ONLINE_JUDGE
	ios::sync_with_stdio(0); cin.tie(0);
#endif
	int tt;
	cin >> tt;
	while(tt--)
		solve();
	return 0;
}

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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        long long n, k;
        cin >> n >> k;
        map<long long, long long> mp;
        for (long long i = 0; i < n; i++)
        {
            long long temp;
            cin >> temp;
            mp[temp]++;
        }
        vector<long long> arr;
        for (auto it : mp)
        {
            arr.push_back(it.second);
        }
        stable_sort(arr.begin(), arr.end());
        long long ans = arr.size();
        long long i = 0;
        long long num = arr.size();
        for (i = 0; i < arr.size(); i++)
        {
            k = k-arr[i];
            if (k<0)
            {
                break;
            }
            ans--;
        }
        int finalans = max(ans,1LL);
        cout<<finalans<<endl;
    }
}
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 n, l, r;

      cin >> n >> l >> r;

      vector<int> a(n);

      vector<int> b;

      vector<int> c;

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

         cin >> a[i];

      } 

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

         b.push_back(a[i]);

      }

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

         c.push_back(a[i]);

      }

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

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

      long long s1 = 0, s2 = 0;

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

         s1 += b[i];

      }

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

         s2 += c[i];

      }

      cout << min(s1, s2) << "\n";

   }

    return 0;

}

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

#define log(x) cout << x << "\n"

using namespace std;
int n;
int l;
int r;
int t;
void reversesub(int a[],int l,int r);
long long sumvec(vector<int> v, int stop);

int main(){
        cin >> t;
        while ( t > 0){
                cin >> n >> l >> r;
                int a[n];
                for (int i= 0; i < n; i++){
                        cin >> a[i];
                }
                l--;
                vector<int> b(r, 0);

                //cout << "size: " << b.size() << " b: \n";
                for(int i = 0; i < b.size(); i++){
                        //cout << "i: " << i << ", b[i]: ";
                        b[i] = a[i];
                        //cout << b[i] << "\n";
                }
                //cout << "\n";
                long long minsum = (long long)1E18;
                if (!b.empty()){
                        sort(b.begin(), b.end());
                        minsum = min(minsum, sumvec(b, r-l));
                        //cout << "s1: " << sumvec(b, r-l) << "\n";
                }
                
                vector<int> c(n-l, 0);
                //cout << "size: " << c.size() <<", c: \n";
                for(int i = 0; i < c.size(); i++){
                        c[i] = a[l+i];
                        //cout <<"i: "<< i << "c[i]: " << c[i] << "\n";
                }
                //cout << "\n";
                
                if(!c.empty()){
                        sort(c.begin(), c.end());
                        minsum = min(minsum, sumvec(c, r-l));
                        //cout << "s2: " << sumvec(c, r-l) << "\n";
                }
                
                t--;
                cout << minsum << "\n";
        }
        

        return 0;
}

long long sumvec(vector<int> v, int stop){
        long long sum = 0;
        for(int i = 0;i < stop; i++){
                sum += v[i];
        }
        return sum;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC ("unroll-loops")

typedef long long ll;
ll N = 200005, mod = 1e9 + 7;


void solve() {

    string num;
    cin >> num;

    ll sum = 0, two = 0, thr = 0;
    for (int i = 0; i < num.size(); i++) {
        sum += (num[i] - '0');
        if (num[i] - '0' == 2) two++;
        else if (num[i] - '0' == 3) thr++;
    }

    if (sum % 9 == 0) {
        cout << "YES"; return;
    }

    ll tmp = sum;
    for (int i = 0; i < two; i++) {
        tmp += 2;
        if (tmp % 9 == 0) {
            cout << "YES"; return;
        }
    }

    for (int i = 0; i <= min(10ll, two); i++) {
        tmp = sum + i * 2;
        for (int j = 0; j < thr; j++) {
            tmp += 6;
            if (tmp % 9 == 0) {
                //  cout << i << " " << j << " " << tmp << endl;
                cout << "YES"; return;
            }
        }
    }
    cout << "NO";

}

int main() {

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        cout << "\n";
    }
    return 0;
}



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

using namespace std;



int main() {

	// your code goes here

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        

        map<int,int> count;

        int sum=0;

        for(int i=0;i<s.length();i++){

            sum=sum+(s[i]-'0');

            if(s[i]=='2'){

                count[2]++;

            }

            if(s[i]=='3'){

                count[6]++;

            }

        }

        int n=count[2]+3*count[6];

        if(sum%9==0){

            cout<<"yes"<<endl;

            continue;

        }

        else if(n==0){

            cout<<"no"<<endl;

            continue;

        }

        //cout<<n<<" "<<sum<<endl;

        bool f1=false;

        int ss=0;

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

            sum=sum+2;

            ss=ss+2;

            if(sum%9==0){

                //cout<<i<<endl;

                if(i<=count[2]){

                    cout<<"yes"<<endl;

                    f1=true;

                    break;

                }

                if(i>count[2]){

                    int count2s=i;

                    int s2=ss/6;

                    if(count[2]>=(count2s-3*s2)){

                        cout<<"yes"<<endl;

                        f1=true;

                        break;

                    }

                    

                }

            }

        }

        

        if(!f1){

            cout<<"no"<<endl;

        }

    }

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

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

using namespace std;

#define rep(i, l, r) for(int i = (l); i < (r); ++i)
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define sz(v) (int)v.size()
#define dbg(x) "[" #x " = " << (x) << "]"
#define file(task) if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }

template<typename T>
bool minimize(T& a, const T& b){
    if(a > b) return a = b, true;
    return false;
}

template<typename T>
bool maximize(T& a, const T& b){
    if(a < b) return a = b, true;
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll calc(ll a, ll b, ll c){
    return (a ^ b) + (b ^ c) + (a ^ c);
}

void testcase(){
    ll l, r;
    cin >> l >> r;

    ll x = 63 - __builtin_clzll(r ^ l);
    ll m = l | ((1LL << x) - 1);
    ll n = m + 1;
    ll o = -1;
    for(ll i = l; i <= r; ++i){
        if(i != m && i != n){
            o = i;
            break;
        }
    }
    cout << m << ' ' << n << ' ' << o << '\n';
//    cout << calc(m, n, o) << '\n';
}

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

#ifdef LOCAL
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
#endif // LOCAL

    int T = 1; cin >> T;
    while(T--){
        testcase();
    }

    return 0;
}


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

using namespace std;
//abeke

typedef long long ll;
typedef unsigned long long ull;

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define speed ios::sync_with_stdio( false); cin.tie(nullptr); cout.tie(0);
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define eb emplace_back
#define nl '\n'
#define f first
#define s second
#define gcd __gcd
#define ins insert
#define clz(x) __builtin_clz(x)
const int inf = INT_MAX;
const int mod = 998244353;
const int N = 2e5;

bool cmp (ll x, ll y) {
    return x > y;
}
ll minv(ll x, ll m) {
    ll res = 1, p = m - 2;
    while (p > 0) {
        if (p & 1) res = res * x % m;
        x = x * x % m;
        p >>= 1;
    }
    return res;
}
struct node {
    int lmn, lmx, rmx, rmn, x;
};
void solve() {
    int l, r;
    cin >> l >> r;
    ll a = 0, b = 0, c = 0;
    for (int i = 30; i >= 0; i--) {
        int x = (1<<i)&l;
        int y = (1<<i)&r;
        //cout << x << ' ' << y << nl;
        if (x != y) {
            a += (1<<i);
            break;
        } else if (x == y) {
            a += x;
            b += x;
        }
    }
    if (a == r || a == 1) {
        cout << a << " " << a - 1 << " " << a - 2 << nl;
    } else {
        cout << a << " " << a - 1 << " " << a + 1 << nl;
    }
}
int main()
{
    speed;
    int t = 1;
    cin >> t;
    while (t --> 0)
        solve();
    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int> 
#define vvi vector<vi>
#define int long long
#define vp vector<pair<int,int>>
#define all(v) v.begin(),v.end()
const int MOD=1e9+7;
const int N=1e5+10;

bool isPerfectSquare(long double x)
{
if (x >= 0) {
long long sr = sqrt(x);
return (sr * sr == x);
}
return false;
}
bool isPowerOfTwo(int n)
{
if (n == 0)
return false;
return (ceil(log2(n)) == floor(log2(n)));
}
int PositionRightmostSetbit(int n)
{
if (n == 0)
return 0;
int position = 1;
int m = 1;
while (!(n & m)) {
m = m << 1;
position++;
}
return position;
}
bool isprime(int n) {
bool is_prime = true;
if (n == 0 || n == 1) {
is_prime = false;
}
for (int i = 2; i <= n / 2; ++i) {
if (n % i == 0) {
is_prime = false;
break;
}
}
return is_prime;
}
void solve(){

int n,l,r;
cin>>n>>l>>r;
vi a(n);
rep(i,0,n) cin>>a[i];
vi one,two;
rep(i,0,r){
    one.push_back(a[i]);

}
rep(i,l-1,n){
    two.push_back(a[i]);
}
sort(all(one));
sort(all(two));
int val=r-l+1;
int i=0;
int sum1=0, sum2=0;
while(val--){
    sum1+=one[i];
    sum2+=two[i];
    i++;
}
cout<<min(sum1,sum2);
 
}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
cout<<endl;
}
}

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

using namespace std;



int main() {

    int t;

    cin >> t;



    while (t--) 

    {

     

     int n,l,r;

     cin>>n>>l>>r;

     vector<int>arr;

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

     {

      int x;

      cin>>x;

      arr.push_back(x);

     }



     vector<int>left;

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

     {

      left.push_back(arr[i]);

     }

     vector<int>right;

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

     {

      right.push_back(arr[i]);

     }

     vector<int>v;

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

     {

      v.push_back(arr[i]);

     }



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

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

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



     long long int sum=accumulate(v.begin(),v.end(),0LL);

     long long  int lsum=sum;

     int j=0;

     for(int i=v.size()-1;i>=0;i--)

     {

         if(j==left.size())

         break;

           if(left[j]<v[i])

           {

              lsum=lsum-v[i]+left[j];

              j++;

           }

           

     }

     long long int rsum=sum;

     j=0;

     for(int i=v.size()-1;i>=0;i--)

     {

         if(j==right.size())

         break;

         //cout<<right[j]<<" "<<v[i]<<endl;

           if(right[j]<v[i])

           {

              rsum=rsum-v[i]+right[j];

              j++; 

           }

        // cout<<rsum<<endl;

          

     }

    /* for(int i:left)

     cout<<i<<" ";

     cout<<endl;

     for(int i:right)

     cout<<i<<" ";

     cout<<endl;

     cout<<lsum<<" "<<rsum<<endl;*/



     cout<<min(rsum,lsum)<<endl;









    

     }



    

}