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

Solution 1 (runtime: 108 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int c= 1e9 ;


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

  int t;
  cin>>t;
  while(t--){
    ll n, l, r;
    cin>>n>>l>>r;
    ll a;
    vector<ll> left, right, mymain;
    
    for(ll i=0; i<l-1; i++){
        cin>>a;
        left.push_back(a);
    }
    for(ll i=0; i<r-l+1; i++){
        cin>>a;
        mymain.push_back(a);
    }
    for(ll i=0; i<n-r; i++){
        cin>>a;
        right.push_back(a);
    }
    
    sort(left.begin(), left.end());
    sort(right.begin(), right.end());
    sort(mymain.begin(), mymain.end());
    ll mp=mymain.size()-1, lp=0, rp=0;
    
    ll sum=0;
    for(ll i=0; i<mymain.size(); i++){
        sum+=mymain[i];
    }
    ll ans=sum;
    
    
    while((mp>=0 && lp<left.size()) && mymain[mp] > left[lp]){
        sum-=mymain[mp]-left[lp];
        mp--;
        lp++;
    }
    // //edit.\]
    // for(auto x : left){cout<< x << ' ';}
    // cout<<endl;
    // for(auto x: right){ cout<< x <<' ';}
    // cout<< endl;
    // cout<<sum<<" \n"; //edit
    ll suml=sum;
    sum=ans;
    
    mp=mymain.size()-1, lp=0, rp=0;
    while((mp>=0 && rp<right.size()) && mymain[mp] > right[rp]){
        sum-=mymain[mp]-right[rp];
        mp--;
        rp++;
    }
    // cout<<sum<<" \n"; //edit
    ans=min(suml, sum);
    
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

#define int long long

#define pb push_back

using vec=vector<int>;

using omap=map<int,int>;

signed main(){

    int t; cin>>t;

    while(t--){

        int n; cin>>n;

        int l,r; cin>>l>>r;

        

        vec v(n); vec a; vec b;

        for(int i=0;i<n;i++) cin>>v[i];

        

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

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



       

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

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



        // int sum1=accumulate(a.begin(),a.end()-(r-l+1),0); 

        // int sum2=accumulate(b.begin(),b.end()-(r-l+1),0);

        int sum1=0; int sum2=0;

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

            sum1+=a[i];

            sum2+=b[i];

        }

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

        



    }

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

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

#define ll long long
 
using namespace std;
 
int main(){
    int tt;
    cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        set <int> e[n+1],ee[n+1];
        vector<int> d(n+1);
        for(int i=1;i<n;i++){
            int a,b;
            cin>>a>>b;
            e[b].insert(a);
            e[a].insert(b);
            ee[b].insert(a);
            ee[a].insert(b);
            d[b]++;
            d[a]++;
        }
        int maxd=0;
        vector <int> m;
        
        for(int i=1;i<=n;i++){
            if(d[i]>maxd) maxd=d[i];
        }
        for(int i=1;i<=n;i++){
            if(d[i]==maxd) m.emplace_back(i);
        }
        int ans;
        if (m.size()>= 3){
            ans = 2*maxd - 1;
        }
        else if(m.size()==2){
            bool f=true;
            for(auto v:e[m[0]]){
                if (v==m[1]){
                    ans=2*maxd-2;
                    f=false;
                }
                
            }
            if(f)
                ans=2*maxd-1;
        }
        else{
            ans=maxd;
            int p=m[0];
            for(auto it=e[p].begin();it!=e[p].end();it++){
                int t=*it;
                ee[t].erase(p);
                ee[p].erase(t);
            }
            maxd=0;
            for(int i=1;i<=n;i++){
                d[i]=ee[i].size();
                if(d[i]>maxd) maxd=d[i];
            }
            ans+=maxd-1;
        }
        
        if(n==2) cout<<0<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}

Solution 2 (runtime: 186 ms):
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second

using namespace std;
const int N=2e5+5,M=N*2;
int read(){
  int x=0,f=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=x*10+c-48;c=getchar();}
  return x*f;
}
struct{
  int to[M],nx[M],hd[N],t;
  void add(int u,int v){to[++t]=v,nx[t]=hd[u],hd[u]=t;}
}g;
int t;
void solve(){
  int n=read();
  g.t=0;
  for(int i=1;i<=n;i++)g.hd[i]=0;
  vector<int> in(n+5);
  for(int i=1;i<n;i++){
    int u=read(),v=read();
    in[u]++,in[v]++;
    g.add(u,v),g.add(v,u);
  }
  if(n==2){
    printf("0\n");
    return;
  }
  int mx=0,q1=0,q2=0;
  for(int i=1;i<=n;i++){
    if(in[i]>mx){
      mx=in[i];
      q1=i;
      q2=0;
    }
    else if(in[i]==mx){
      q2=i;
    }
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    if(i==q1)continue;
    if(i==q2)continue;
    bool f1=0,f2=0;
    // 找到相邻点
    for(int j=g.hd[i];j;j=g.nx[j]){
      if(g.to[j]==q1){
        f1=1;
      }
      if(g.to[j]==q2){
        f2=1;
      }
    }
    // 必须相邻
    ans=max(ans,mx+in[i]-2);
    // 若不必相邻
    if((!f1)||(q2&&(!f2))){
      ans=max(ans,mx+in[i]-1);
    }
  }
  if(q1&&q2){
    bool f=0;
    for(int i=g.hd[q1];i;i=g.nx[i])
      if(g.to[i]==q2)f=1;
    ans=max(ans,mx+mx-2);
    if(!f)
      ans=max(ans,mx+mx-1);
  }
  printf("%d\n",ans);
  return;
}

signed main(){
  #ifndef ONLINE_JUDGE
    freopen("","r",stdin);
    freopen("","w",stdout);
  #endif
  t=read();
  while(t--){
    solve();
  }
  return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

using ll = long long;

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

    while(t--){
        ll n, l, r;
        cin >> n >> l >> r;     
        l--, r--;

        vector<ll> a(n);
        for(ll i=0; i<n; i++) cin >> a[i];

        vector<ll> b = a;
        sort(b.begin(), b.end());
        ll sum = 0;
        map<ll,ll> mp;
        for(ll i=0; i<(r-l+1); i++){
            sum += (b[i]);
            mp[b[i]]++;
        }

        if(l==0 || r==n-1){
            cout << sum << endl;
            continue;
        }
        //if not
        //l != 0 && r != n-1
        ll sum1 = 0, sum2 = 0;
        multiset<ll> st1, st2;
        for(ll i=0; i<=r; i++){
             st1.insert(a[i]);
        }
        for(ll i=l; i<n; i++){
             st2.insert(a[i]);
        }
        auto it1 = st1.begin(), it2 = st2.begin();
        ll size1 = r-l+1, size2 = r-l+1;
        while(size1!=0 && it1!=st1.end()){
            sum1 += *it1;
            it1++;
            size1--;
        }
        while(size2!=0 && it2!=st2.end()){
            sum2 += *it2;
            it2++;
            size2--;
        }
        ll ans = min(sum1, sum2);
        cout << ans << endl;
        
    }
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
#define BOOST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

using namespace std;
 
int main(){
    BOOST
    
    int t;
    cin >> t;
    while (t--){
        int n, l, r;
        cin >> n >> l >> r;
        vector<int> esq(n+1);       // 1-base index
        vector<int> dir(n+1);
        for (int i=1; i<=n; i++){
            cin >> esq[i];
            dir[i] = esq[i];
        }
        // Esquerda: a[1..r]
        sort(esq.begin() + 1, esq.begin() + r + 1);
        ll soma_1 = 0;
        for (int i = 1; i <= r - l + 1; i++){
            soma_1 += esq[i];
        }
        
        // Direita: a[l..n]
        sort(dir.begin() + l, dir.end());
        ll soma_2 = 0;
        for (int i = l; i <= r; i++){
            soma_2 += dir[i];
        }
        
        cout << min(soma_1, soma_2) << endl;
    }
}
Problem: 2050B - Transfusion
Language: c++17 

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

using namespace std;





int main(){

    int t;

    cin>>t;



    while(t--){

        int n;

        cin>>n;



        long long oddSum =0,evenSum=0;

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

            long long num;

            cin>>num;

            if(i%2==0) evenSum+=num;

            else oddSum+=num;

        }



        long long evens = n/2;

        long long odds = n-evens;



        bool ans=true;



        if(oddSum%odds!=0 || evenSum%evens!=0) ans=false;

        if(ans && oddSum/odds != evenSum/evens) ans=false;



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

        else cout<<"NO"<<endl;

    }

    return 0;

}

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        long long int n;

        cin>>n;

        vector<int>ritik(n);

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

        cin>>ritik[i];

        long long int sum_o=0,sum_e=0;

        long long int c1=0,c2=0;

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

            if(i%2==0){

              sum_e+=ritik[i];  

              c1++;

            }

            else{

                sum_o+=ritik[i];

                c2++;

            }

        }

        if(sum_e/c1==sum_o/c2 && sum_e%c1==0&& sum_o%c2==0){

            cout<<"YES"<<endl;

        }

        else

            cout<<"NO"<<endl;

    }

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

Solution 1 (runtime: 343 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
    ll n;
    cin >> n;
    vector<int> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 1; i < n; i++)
    {
        if (a[i] < a[i-1])
        {
            cout << "NO\n";
            return;
        }
        ll c = min(a[i], a[i -1]);
        a[i] -= c;
        a[i-1] -= c;
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


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

void solve(){
    ll n;
    cin>>n;
    ll a[n];
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    bool f=false;
    if (n==2){
        if (a[1]<a[0]){
            f=true;
        }
    }
    else{
        for (int i=0;i<n-1;i++){
            if (a[i]>a[i+1]){
                f=true;
            }
            a[i+1]=a[i+1]-a[i];
        }
        
    }
    if (f){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }
}

int main() {
    int T;
    cin>>T;
    while(T--){
        solve();
    }
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 61 ms):
// Problem: C. Registration system
// Contest: Codeforces - Codeforces Beta Round 4 (Div. 2 Only)
// URL: https://codeforces.com/problemset/problem/4/C
// Memory Limit: 64 MB
// Time Limit: 5000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define pb push_back
#define m_p make_pair
#define sz size()
#define yes cout<<"YES"<<endl;
#define m1 cout<<"-1"<<endl;
#define no cout<<"NO"<<endl;
#define take(a) for(int i=0;i<a.size();i++)cin>>a[i];
#define get(a) for(int i=0;i<a.size();i++)cout<<a[i]<<' ';cout<<endl;
#define vi vector<long long int>
#define vp vector<pair<long long int,long long int>>
#define vb vector<bool>
#define p_r pair<long long int  ,long long  int>
#define mp map<long long int  ,long long  int>
#define ump unordered_map<string  ,long long  int>
#define st set<long long int>
#define mst multiset<long long int>
#define ll long long
#define MX INT_MAX
#define MN INT_MIN
#define srt(a) sort(a.begin(),a.end())
#define rev(x) reverse(x.begin(),x.end())
#define p_sum(a) for(int i=1;i<a.size();i++)a[i]+=a[i-1];
#define s_sum(a) for(int i=a.size()-1;i>=1;i--)a[i-1]+=a[i];
#define el "\n"
#define tb "\t"
#define F first
#define S second
#define p(x) cout<<x<<el
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll b_src(vi &a,ll f,ll l,ll n){
    ll m=f+(l-f)/2;
    while(f<=l){
        if(a[m]==n)return m;
        else if(a[m]<n)return b_src(a,m+1,l,n);
        else return b_src(a,f,m-1,n);
    }
    return -1;
}

ll gcd(ll a, ll b){
    return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return (a / gcd(a, b)) * b;
}

bool isPowerOfTwo(ll n){
    return n > 0 and (n & (n - 1)) == 0;
}

void solve(){
	string s;       cin>>s;

	for(ll i=1;i<s.size();i++){
        ll c=i,j=i-1;

        while(j>=0 && s[c]>s[j]+1 && s[c]>'0'){
            s[c]--;
            swap(s[c],s[j]);
            c--;j=c-1;
        }
	}
	cout<<s<<el;
}

signed main() {
    fast;
    ll tc=1;      cin>>tc;
    while(tc--){
        solve();
    }
}


Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<typename A,typename B> bool minimize(A& a,const B& b) {return a > b ? a = b, 1 : 0;}
template<typename A,typename B> bool maximize(A& a,const B& b) {return a < b ? a = b, 1 : 0;}

using namespace std;
string s;

void solve() {
    cin>>s;
    int n=(int)s.size();
    for(int i=0;i<n;i++){
        int ma=s[i]-'0',k=-1;
        for(int j=i+1;j<min(n,i+9);j++){
            if(s[j]-'0'-(j-i)>ma){
                ma=s[j]-'0'-(j-i);
                k=j;
            }
        }
        if(k==-1) continue;
        s[k]=ma+'0';

        for(int j=k;j>i;j--) swap(s[j],s[j-1]);
    }
    cout<<s<<'\n';
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int t;
    cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

using namespace std;

#define cin(v) for (auto& i : v) cin >> i;
#define cout(v) for (auto& i : v) cout << i << " "; cout << endl;
#define endl "\n"
#define all(a) a.begin(), a.end()
#define int long long
const int MOD = 998244353;

void myprog();

int32_t main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int t = 1;
        //cin >> t;
        while (t-- > 0)
                myprog();
        return 0;
}



void myprog() {
        int n;
        cin >> n;

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

        map<int, int> mp;
        

        for(int i = 0; i < n; i++){
                mp[v[i]] = i;
        }

        vector<pair<int, int>> ans;

        reverse(all(a));
        for(int i = 0; i < n; i++){
                for(int j = i + 1; j < n; j++){
                        ans.push_back({j, i});
                }
        }

        for(int i = 0; i < n; i++){
                for(int j = 0; j < n - 1; j++){
                        if(mp[a[j]] > mp[a[j + 1]]){
                                ans.push_back({a[j + 1], a[j]});
                                swap(a[j], a[j + 1]);
                        }
                }
        }

        cout << ans.size() << endl;

        for(auto &[u, v] : ans){
                cout << u + 1 << " " << v + 1 << endl;
        }
}



Solution 2 (runtime: 1484 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
void solve() {
    ll n;
    cin>>n;
    vl c(n+1),a(n+1);
    for(ll i=1;i<=n;i++)cin>>c[i];
    vector<vector<ll>> ans;
    for(ll i=n;i>=2;i--){
        for(ll j=i-1;j>=1;j--){
            ans.push_back({i,j});
        }
    }
    for(int i=n;i>=1;i--)a[i]=n-i+1;
    for(int i = n;i>=1;i--)
    {
        // i->c
        // j->a
        if(a[i]==c[i])continue;
        int temp = a[i];
        int j =i;
        vector<vector<ll>> ans2;
        while(j>=1 && c[i]!=a[j]){
            ans2.push_back({a[j],c[i]});
            int t2 = a[j];
            a[j] = temp;
            temp = t2;
            j--;
        }
        a[j] = temp;
        a[i] = c[i]; 
        for(int k=ans2.size()-1;k>=0;k--)ans.push_back(ans2[k]);
    } 
    cout<<ans.size()<<endl;
    for(auto it: ans)cout<<it[0]<<" "<<it[1]<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ll t=1;
    // cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;
void solve() {
    
     string n;
     cin>>n;

     long long sum=0;

     int cnt2=0,cnt6=0;

     for(int i=0;i<n.size();i++)
     {
        int k=n[i]-'0';
        sum +=k;
        if(k==2)cnt2++;
        if(k==3)cnt6++;
        // cout<<k<<" ";
        /* code */
     }
    //  cout<<endl;

    // cout<<sum<<endl;
     sum = (sum%9);
    //  cout<<sum<<endl;
     if(sum==0){
        cout<<"YES"<<endl;
        return;
     }
    //  cout<<cnt2<<"  and  "<<cnt6<<endl;

     if(sum & 1){

            sum=(9-sum);
     } 
     else{

        sum=(18-sum);
     }

    while(sum!=0){

        if(cnt6>0 && sum>5){
            sum -=6;
            cnt6--;
        }
        else if(cnt2>0 && sum>1){
            sum -=2;
            cnt2--;
        }
        else {
            break;
        }

    }

    if(sum==0){
        cout<<"YES"<<endl;
    }
    else {
        cout<<"NO"<<endl;
    }
     
}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    int t;
    cin >> t;

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

    return 0;
}


Solution 2 (runtime: 62 ms):
/**

*    author:  Pratik

*    created: 2025.02.22 21:08:56

**/

#include <bits/stdc++.h>

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int sum = 0, cnt2 = 0, cnt3 = 0;

        for(char c: s){

            sum += c - '0';

            if(c == '2') cnt2++;

            if(c == '3') cnt3++;

        }

        if(sum%9 == 0){

            cout<<"YES"<<endl;

            continue;

        }

        int rem = sum%9;

        int diff = (9-rem)%9;

        bool f = false;

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

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

                int z = 2*i + 6*j;

                if(z%9==diff){

                    f = true;

                    break;

                }

            }

            if(f) break;

        }

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

        else cout<<"NO"<<endl;

    }

    return 0;

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

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int l,r;
cin>>l>>r;
int temp=l^r;
int cnt=0;
while(temp!=0){temp>>=1;cnt++;}
cnt--;
//most significant differing in l,r bit is off 
int a=((1ll<<cnt)-1)|l; // xor with l to make it atleast l to keep "a" within range
// most significant differing bit in l,r is on
int b=a+1; // since r-l>1 b is always valid
int c=(a==l?r:l); // if a is l then b=l+1 so c can be from l+2 as r-l>1 
cout<<a<<" "<<b<<" "<<c<<endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while (t--) {
        solve();
    }
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 50;
const ll mod = 1e9 + 7;
#define PI 3.14159265358979324
#define lowbit(x) (x & (-x))
typedef pair<int, int> PII;
#define all(x) x.begin(), x.end()
//#define x first
//#define y second
map<ll, ll> mp, mp1;
ll a[N];
void solve() {
    int l, r;
    cin >> l >> r;
    int op = 0;
    for(int i = 32; i >= 0; i--){
        if((l & (1 << i)) != (r & (1 << i))){
            op = i;
            break;
        }
    }
    int p = (l << op) >> op;
    int res1 = p + (1 << op), res2 = p + (1 << op) - 1;
    if(res2 == l) cout << res1 << " " << res2 << " " << r << endl;
    else cout << l << " " << res1 << " " << res2 << endl;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

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

/*1 2 3 4
1 2 4 3*/
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
void solve() {
    int n, l, r;
    std::cin >> n >> l >> r;
    l--;
    r--;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    std::sort(a.begin(), a.begin() + l);
    std::sort(a.begin() + l, a.begin() + r + 1, std::greater<int>());
    std::sort(a.begin() + r + 1, a.end());
    int len = r - l + 1;
    long long s1 = 0, s2 = 0;
    for (int i = 0; i < len; i++) {
        if (i >= l) {
            s1 += a[l + i];
        } else {
            s1 += std::min(a[i], a[l + i]);
        }
        if (i + r + 1 >= n) {
            s2 += a[l + i];
        } else {
            s2 += std::min(a[i + r + 1], a[l + i]);
        }
    }
    std::cout << std::min(s1, s2) << '\n';
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int T = 1;
    std::cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 93 ms):
#include<bits/stdc++.h>
#define MOD (int)1000000007
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define rarr(i,a,b) for(int i=a;i>b;i--)
#define forrev(i,n) for(int i=n-1;i>=0;i--)
#define tc(t) int t; cin >> t; while (t--)
#define ll long long
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define pii pair<int, int>
#define vi vector < int >
#define vl vector < ll >
#define vpl vector <pair <ll , ll > >
#define vb vector<bool>
#define vs vector<string>
#define vpi vector <pair <int , int > >
#define pll pair<ll, ll>
#define mii map<int,int>
#define msi map<string,int>
#define sint set<int>
#define sstr set<string>
#define pb(x) push_back(x)
#define ss second
#define ff first
#define py cout<<'YES'<<endl;
#define pm cout<<'-1'<<endl;
#define pn cout<<'NO'<<endl;
#define pimp cout<<'IMPOSSIBLE'<<endl;
#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
using namespace std;
vector<ll> edges[100005];
bool isvisit[100005];
ll n, m, k;

void solve() {
    cin >> n >> m >> k;
    m--;
    vi v(n);
    for0(i, n) cin >> v[i];
    vi a = v;
    sort(a.begin()+m,a.end());
    vi b = v;
    sort(b.begin(),b.begin()+k,greater<ll>());
    ll sum1 = accumulate(a.begin() + m, a.begin() + k, 0LL);
    ll sum2 = accumulate(b.begin() + m, b.begin() + k, 0LL);
    cout<<min(sum1,sum2)<<endl;
}

int main() {
    FAST;
    tc(t) {
        solve();
    }
    return 0;
}