ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
const int M=1e9+7;
vector<vector<int>>dp;
int help(int i,int j,string &a,string &b,string &c,int n,int m){
    if(i==n and j==m){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    int pos=i+j;
    int res=1e9;
    if(i<n){
        int cost=help(i+1,j,a,b,c,n,m)+(c[pos]!=a[i]);
        res=min(res,cost);
    }
    if(j<m){
        int cost=help(i,j+1,a,b,c,n,m)+(c[pos]!=b[j]);
        res=min(res,cost);
    }
    return dp[i][j]=res;
}
void solve(){
  
  
     string a,b,c;
     cin>>a>>b>>c;
     int n=a.size();
     int m=b.size();
     dp.assign(n+1,vector<int>(m+1,-1));
     cout<<help(0,0,a,b,c,n,m)<<endl;
   
}


signed main() {
	int t;
	cin>>t;
	while(t--){
	    solve();
	}

}


Solution 2 (runtime: 108 ms):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define all(x) (x).begin() + 1, (x).end()
#define fr(i, n) for (int i = 1; i <= n; i++)
#define vvi vector<vector<int>>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

const int M = 1e9 + 7;
string a, b, c;
int n, m;

vvi dp;

int matcher(int ind1, int ind2, int ind3)
{
    if (ind1 == n && ind2 == m)
    {
        return 0;
    }
    if (dp[ind1][ind2] != -1)
        return dp[ind1][ind2];
    if (ind1 == n)
    {
        if (b[ind2] == c[ind3])
            return dp[ind1][ind2] = matcher(ind1, ind2 + 1, ind3 + 1);
        return dp[ind1][ind2] = 1 + matcher(ind1, ind2 + 1, ind3 + 1);
    }
    if (ind2 == m)
    {
        if (a[ind1] == c[ind3])
            return dp[ind1][ind2] = matcher(ind1 + 1, ind2, ind3 + 1);
        return dp[ind1][ind2] = 1 + matcher(ind1 + 1, ind2, ind3 + 1);
    }
    if (a[ind1] == c[ind3] && b[ind2] == c[ind3])
    {
        return dp[ind1][ind2] = min(matcher(ind1 + 1, ind2, ind3 + 1), matcher(ind1, ind2 + 1, ind3 + 1));
    }
    if (a[ind1] == c[ind3])
        return dp[ind1][ind2] = min(matcher(ind1 + 1, ind2, ind3 + 1), 1 + matcher(ind1, ind2 + 1, ind3 + 1));
    if (b[ind2] == c[ind3])
        return dp[ind1][ind2] = min(matcher(ind1, ind2 + 1, ind3 + 1), 1 + matcher(ind1 + 1, ind2, ind3 + 1));

    return dp[ind1][ind2] = min(1 + matcher(ind1 + 1, ind2, ind3 + 1), 1 + matcher(ind1, ind2 + 1, ind3 + 1));
}

void solve()
{
    // Your code here
    cin >> a >> b >> c;
    n = a.size(), m = b.size();
    dp.clear();
    dp.resize(n + 10, vi(m + 10, -1));
    cout << matcher(0, 0, 0) << endl;
}

signed main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;



int main(){

    int t;

    cin >> t;

    while(t--){

        int n;

        cin >> n;

        string h;

        cin >> h;

        int i = 0;

        int j = n - 1;

        if(h[0] == 's' || h[0] == '.'){

            i++;

        }

        if(h[n - 1] == 'p' || h[n - 1] == '.'){

            j--;

        }

        bool flag1 = 0;

        bool flag2 = 0;

        for(int p = i; p <= j; p++){

            if(h[p] == '.') continue;

            if(h[p] == 's') flag1 = 1;

            if(h[p] == 'p') flag2 = 1;

        }

        if(flag1 && flag2){

            cout << "NO" << endl;

        } else {

            cout << "YES" << endl;

        }

    }

}

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

#define deb cout<<"#"<<endl;

#define pse system("pause");

using namespace std;

using i64=long long;

using f64=double;

using str=string;

using vint=vector<int>;

using pii=pair<int,int>;

constexpr int inf = 2e9;

constexpr i64 inf64 = 9e18;

constexpr int md = 1e9+7;

constexpr int N = 3e5+10;







void init() {



}



void solve(){

    int n;cin>>n;

    str s;cin>>s;

    s=' '+s;

    int x{},y{};

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

        if (s[i]=='s') x++;

        else if (s[i]=='p') y++;

    }



    if (x==0||y==0||(y==1&&s[n]=='p')||(x==1&&s[1]=='s')) {

        cout<<"YES"<<'\n';

    }

    else {

        cout<<"NO"<<'\n';

    }

}

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

    //init();

    int _=1;

    cin>>_;

    while(_--){

        solve();

    }

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

Solution 1 (runtime: 108 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define yes cout<<"YES\n"
#define no  cout<<"NO\n"

void solve(){
    
    int n,k;
    cin>>n>>k;
    map<int,int>m;
    vector<int>v;
    
    for (int i=1; i<=n; ++i) {
        int x;
        cin>>x;
        m[x]++;
    }
    
    for(auto it:m)
        v.push_back(it.second);
    sort(v.begin(),v.end());
    int s=(int)v.size();
    
    for (int i=0; i<v.size(); ++i) {
        if(k>=v[i]){
            k-=v[i];
            s--;
        }
        else break;
    }
    s?cout<<s<<endl:cout<<1<<endl;
}

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


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

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        for(int i=0; i<n; i++) cin >> a[i];
        sort(a.begin(), a.end());
        vector<int> cnt = {1};
        for(int i=1; i<n; i++){
            if(a[i] == a[i-1]) cnt.back()++;
            else cnt.push_back(1);
        }
        sort(cnt.begin(), cnt.end());
        int m = cnt.size();
        bool flag = 0;
        for(int i=0; i<m; i++){
            if(cnt[i] > k){
                cout << m-i << "\n";
                flag=1;
                break;
            }
            k-=cnt[i];
        }
        if(!flag) cout << 1 << "\n";
    }
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

#define MOD 1000000000
#define ll long long

void solve() {
    int n; cin>>n;
    vector<int> arr(n), sorted(n, 0);
    for (int i=0; i<n; i++) cin>>arr[i];
    int total = n*(n-1);
    int count = 0;
    int j, curr;
    for (int i=0; i<n; i++) {
        curr = arr[i];
        j = i;
        while (j>0 && sorted[j-1]>curr) {
            count++;
            sorted[j] = sorted[j-1];
            j--;
        }
        sorted[j] = curr;
    }
    cout<<total-count<<"\n";
    int index;
    for (int i=0; i<n; i++) {
        index = lower_bound(sorted.begin()+i, sorted.end(), arr[i]) - sorted.begin();
        for (int j=index+1; j<n; j++) cout<<sorted[j]<<" "<<sorted[index]<<"\n";
        for (int j=n-1; j>index; j--) cout<<sorted[index]<<" "<<sorted[j]<<"\n";
        for (int j=index-1; j>=i; j--) {
            cout<<sorted[j+1]<<" "<<sorted[j]<<"\n";
            swap(sorted[j], sorted[j+1]);
        }
    }
}
 
int main() {
	ios_base::sync_with_stdio(false);  
	cin.tie(nullptr);

    solve();

    return 0;
}

Solution 2 (runtime: 1233 ms):
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int main() {
        int n;
        cin>>n;
        int a[n],p[n+1];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=n;i>0;i--){
            p[n-i+1]=i;
        }
        
        vector<pair<int,int>>v;
        for(int i=2;i<=n;i++){
            for(int j=1;j<i;j++){
                v.push_back({i,j});
            }
        }
        for(int i=0;i<n-1;i++){
            int target=a[i],index,targetindex=i;
            for(int j=1;j<=n;j++){
                if(target==p[j]){
                    index=j;
                    break;
                }
            }
            for(int j=index;j>i+1;j--){
                v.push_back({p[j],p[j-1]});
                swap(p[j],p[j-1]);
            }
        }
        cout<<v.size()<<endl;
        for(auto i:v){
            cout<<i.first<<' '<<i.second<<endl;
        }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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

void solve(int n, int k, vector<int> vec)
{
    vector<long long> frequencies;
    sort(vec.begin(), vec.end());

    long long current = vec[0];
    long long count = 0;

    for (int i = 0; i < n; i++)
    {
        if (vec[i] == current)
        {
            count++;
        }
        else 
        {
            frequencies.push_back(count);
            current = vec[i];
            count = 1;
        }
    }
    frequencies.push_back(count);
    int fa = 0;
    for (int i = 0; i < frequencies.size(); i++)
    {
        fa++;
    }

    sort(frequencies.begin(), frequencies.end(), [](const long long &a, const long long &b) -> bool{
            return a > b;
        });

    if (k >= n)
    {
        cout << "1\n";        
        return;
    }
        
    long long target = n - k;
    long long cumulative = 0;
    long long r =0;
    for(auto f: frequencies){
        cumulative += f;
        r++;
        if(cumulative >= target){
            break;
        }
    }
    r = max(r, (long long)1);
    cout << r << "\n";

}

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

    while (cases--)
    {
        int n, k;
        cin >> n >> k;
        vector<int> vec(n);
        for (int i = 0; i < n; i++)
        {
            cin >> vec[i];
        }
        solve(n, k, vec);
    }
    return 0;
}

Solution 2 (runtime: 249 ms):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int t;
    cin>>t;
        while(t--){
           int n, k;
           cin>>n>>k;
           vector<long long> a(n);
           map<long long, int> m;

           for(int i=0;i<n;i++){
            cin>>a[i];
            m[a[i]]++;
           }
           int uc = 0;
           vector<int> cnt;
           for(auto x:m){
            cnt.push_back(x.second); 
           }
           sort(cnt.begin(), cnt.end());
           for(int i=0;i<cnt.size();i++){
                if(cnt[i]<=k){
                    // cnt++;
                    k = k-cnt[i];
                }
                else uc++;
           }

           cout<<max(1, uc)<<endl;
           
           
           
    }
       
        // sort(a.begin(), a.end());

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

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

int main() {
    int tt;
    cin >> tt;
    while(tt--) {
        string n;
        cin >> n;
        int sum = 0,two = 0,three = 0;
        for(int i = 0;i < n.length();i++) {
            sum += n[i] - '0';
            if(n[i] == '2') two++;
            if(n[i] == '3') three++;
        }
        int remainder = sum%9;
        int t = 0;
        two = min(two,9);
        three = min(three,9);
        for(int i = 0;i <= two;i++) {
            for(int j = 0;j <= three;j++) {
                if((remainder + (i*2 + j*6)) % 9 == 0) {
                    t = 1;
                    break;
                }
            }
        }
        if(t == 1) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

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

using namespace std;



int main() 

{

    int t;

    cin >> t;

    while (t--) {

        string s;

      int n;

       cin>>s;

       n= s.length();

       int c2=0;

       int c3=0;

       int sum=0;

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

           if(s[i]=='2')c2++;

           else if(s[i]=='3')c3++;

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

       }



        int rem = sum % 9;

        if (rem == 0) {

            cout << "YES" << endl;

            continue;

        }

        bool flag = false;

        int temp = 0;

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

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

                int tmpsum=sum+i*2+j*6;

                if (tmpsum % 9 == 0) {

                    cout <<  "YES" << endl;

                    flag = true;

                    break;

                }

            }

            if(flag == true) break;

        }



        if(flag == false) cout << "NO" << endl;

    }

    return 0;

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

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

const long long MOD=1e9+7;

#define ll long long int
#define vi vector<int>
#define vl vector<long long int>
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long int>>
#define umps unordered_map<int, unordered_set<int>>
#define pb push_back
#define pq priority_queue<int>
#define pqp priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>>
#define fo(i,a, n) for (int i = a; i < n; i++)
#define fo_(i,a, n) for (int i = a; i > n; i--)


void solve(){
    int n,l,r; cin>>n>>l>>r; vl a(n);
    fo(i,0,n) cin>>a[i];
    vl left, right;
    for(int i=0; i<r; i++){
        left.pb(a[i]);
    }
    for(int i=l-1; i<n; i++){
        right.pb(a[i]);
    }
    sort(left.begin(), left.end());
    sort(right.begin(), right.end());
    
    ll mini = 1e18; ll sum=0;
    for(int i=0; i<r-l+1; i++){
        sum+= left[i];
    }
    mini = min(mini, sum);
    sum=0;
    for(int i=0; i<r-l+1; i++){
        sum+= right[i];
    }
    mini = min(mini, sum);
    cout<<mini<<endl;
}
 
// check if single Testcase is present && overflow && edgecases
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // ifstream cin("closing.in"); ofstream cout("closing.out"); // On Usaco
    int t = 1; cin >> t;
    for (int i = 1; i <= t; i++){
	// cout <<"Case #"<<i<<": ";
        solve();
   }
    return 0;
}


Solution 2 (runtime: 187 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,n) for(ll i=0; i<n; i++)

int main() {
    int t; cin>>t;
    while(t--) {
        ll n,l,r; cin>>n>>l>>r;
        l--; r--;
        vector<ll> u, v, w;
        
        f(c1, l) {
            ll a; cin>>a;
            u.push_back(a);
        }
        f(c2, r-l+1) {
            ll a; cin>>a;
            v.push_back(a);
        }
        f(c3, n-r-1) {
            ll a; cin>>a;
            w.push_back(a);
        }
        
        sort(v.rbegin(), v.rend());
        sort(u.begin(), u.end());
        sort(w.begin(), w.end());
        
        ll x = min(u.size(), v.size());
        ll ans1 = 0;
        f(c4, x) {
            ans1 += min(u[c4], v[c4]);
            // cout<<"."<<ans1<<endl;
        }
        for(ll i = x; i < v.size(); i++) ans1 += v[i];
        
        ll y = min(v.size(), w.size());
        ll ans2 = 0;
        f(c5, y) {
            ans2 += min(v[c5], w[c5]);
            // cout<<".."<<ans2<<endl;
        }
        for(ll i = y; i < v.size(); i++) ans2 += v[i];
        if(y==0) ans2 = ans1;
        else if(x==0) ans1 = ans2;

        cout<<min(ans1,ans2)<<endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 124 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
typedef vector<pl> vpl;
#define Fo(is, ls, rs) for(ll is = ls; is < (rs); ++is)
#define F(is, rs) for(ll is = 0; is < (rs); ++is)
#define FDo(is, ls, rs) for(ll is = (rs)-1; is >= (ls); --is)
#define FD(is, ls) for(ll is = (ls)-1; is >= 0; --is)
#define trav(is,vs) for(auto& is:vs)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define G(xs) ll xs; cin >> xs;
#define GS(ss) string ss; cin >> ss;
#define all(xs) (xs).begin(), (xs).end()
#define rall(xs) (xs).rbegin(), (xs).rend()
#define sz(xs) xs.size()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sp " "
#define ram(a,n) vl a(n); F(i,n) cin>>a[i];

void solve(){
    G(n) G(k) ram(a,n); map<ll,ll>m; vector<ll>v;
    F(i,n){
      m[a[i]]++;
    }
    vector<pair<ll,ll>>vpr(all(m));
    F(i,vpr.size()){
      v.pb(vpr[i].second);
    }
    sort(all(v));
    F(i,v.size()){
      ll fi=min(k,v[i]);
      k-=fi; v[i]-=fi;
      if(k==0)break;
    } ll si=-1;
    F(i,v.size()){
      if(v[i]!=0){
        si=i; break;
      }
    }
    if(si==-1) cout<<"1";
    else cout<<sz(v)-si;
    cout<<nl;
}

int main(){
    FAST;
    int T = 1;
    cin >> T;
    while(T--) {
        solve();
    }
	return 0;
}





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

#define endl '\n'
#define ll long long
#define lld long double
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tc    \
    ll t;     \
    cin >> t; \
    while (t--)
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

void solve()
{
    ll n, k;
    cin >> n >> k;
    map<ll, ll> m1;
    for (ll i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        m1[a]++;
    }
    vector<ll> v1;
    for (auto it : m1)
        v1.push_back(it.second);
    sort(v1.begin(), v1.end());
    ll i = 0;
    ll pp = 0;
    while (i < v1.size() && pp <= k)
        pp += v1[i++];
    cout << v1.size() + 1 - i << endl;
}

int main()
{
    IOS tc
    {
        solve();
    }
}
Problem: 2050D - Digital string maximization
Language: c++17 

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

using namespace std;

string solve() {
    string s; cin >> s;
    for(int i=1; i<s.size(); i++) {
        for(int j=i+9; j>=i; j--) {
            if(j >= s.size()) continue;
            if(s[j]-1 > s[j-1]) {
                s[j]--;
                swap(s[j], s[j-1]);
            }
        }
    }
    return s;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t;
    while(t--) cout << solve() << "\n";
    return 0;
}

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

using namespace std;



void solve(){

   string s;

   cin>>s;

   int n=s.length();

   int i=1;

   while(i<n){

    int current= i;

        while(s[current]!='0' && s[current]-s[current-1]>=2 && current>0){

            s[current]--;

            swap(s[current],s[current-1]);

            current--;

        }

        i++;

    }

    cout<<s<<endl;

}

int main(){

    int t;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

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

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
	int cases;
	cin>>cases;
	for(int i=0;i<cases;++i){
		string s;
		cin>>s;
		long long sm=0;
		int two=0;
		int three=0;
		for(int j=0;j<s.size();++j){
			int a=(int)(s[j]-'0');
			sm+=a;
			if(a==2){
				two++;
			}
			else if(a==3){
				three++;
			}
		}
		if(sm%9==0){
			cout<<"YES"<<endl;
		}
		else{
			bool ans=false;
			for(int j=0;j<=min(10,two);++j){
				for(int k=0;k<=min(10,three);++k){
					if((sm+2*j+6*k)%9==0){
						ans=true;
						break;
					}
				}
			}
			if(ans){
				cout<<"YES"<<endl;
			}
			else{
				cout<<"NO"<<endl;
			}
		}
	}
}

Solution 2 (runtime: 62 ms):
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        string s; cin >> s;
        int twos = 0, threes = 0, sum = 0;
        for(char n : s){
            int curr = n - '0';
            sum+=curr; if(curr==2){ twos++; } if(curr==3){ threes++; }
        }
        bool works = false;
        int need = 9 - (sum % 9);
        if(need % 2 == 1){ need+=9; }
        if(need/2 <= twos || (need >= 6 && threes >= 1 && (need-(6*threes > need ? need - (need % 6) : 6*threes))/2 <= twos)){ works = true; }
        if(works || need % 9 == 0){ cout << "YES" << endl; } else{ cout << "NO" << endl; }
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

#define int long long
#define pii pair<int,int>
#define vec vector

using namespace std;

void solve(){
    int n,l,r;
    cin>>n>>l>>r;

    vec<int> v(n);

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

    vec<int> v2 = v;
    int ans1=0;
    int ans2=0;

    sort(v.begin(), v.begin()+r);
    for(int i=0;i<=r-l;i++)
        ans1+=v[i];

    sort(v2.begin()+l-1, v2.end());
    for(int i=0;i<=r-l;i++)
        ans2+=v2[i+(l-1)];

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

}

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


Solution 2 (runtime: 202 ms):
#define ll long long int

#define tst unsigned int test=1; scanf("%u", &test); while(test--)

#include<bits/stdc++.h>

using namespace std;

const int M = 1e9+7;

int gcd(int a , int v){ if(v==0) return a; return gcd(v,a%v);}

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

void printBinary(int n){ for(int i =10; i>=0; i--){ cout<<((n>>i)&1) ;} cout<<endl;}

template < typename T> void inputVector(vector<T> &v , int n){ for(int i=0;i<n; i++){ T x; cin>>x; v.push_back(x);} }

template < typename T> void printVector(vector<T> &v ){ for(int i =0;i<v.size(); i++){ cout<<v[i]<<" ";} cout<<endl;}

template < typename T> void printmap(map<T,T>&m){for(auto it:m){cout<<it.first<<" "<<it.second<<endl;}}

template < typename T> void input2DVector(vector<vector<T>> &v , int row , int col){for(int i =0; i<row; i++){vector<T> temp; for(int j =0; j<col; j++){ T x; cin>>x; temp.push_back(x); } v.push_back(temp);}}

template < typename T> void print2dVector(vector<vector<T>> &v){ for(int i =0; i<v.size(); i++){ printVector(v[i]);} cout<<endl;}

int lower_bound(vector<int>&v , int s , int e , int target){int ans = v.size();while(s<=e){int mid = (s+e)/2;if(v[mid]>=target){ans = mid; e = mid-1;}else{s = mid+1;}}return ans;}

int upper_bound(vector<int>&v , int s , int e , int target){int ans = v.size();while(s<=e){int mid = (s+e)/2;if(v[mid]>target){ans = mid; e = mid-1;}else{s = mid+1;}}return ans;}

int main(){



    #ifndef ONLINE_JUDGE

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

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

    #endif

    tst{

        int n,l,r;

        cin>>n>>l>>r;

        l--;

        r--;

        vector<int>v;

        inputVector(v,n);

        int len = r-l+1;

        vector<int> set1,set2;

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

            set1.push_back(v[i]);

        }

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

            set2.push_back(v[i]);

        }

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

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

        ll ans1=0 , ans2 = 0;

        

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

            ans1+=set1[i];

            ans2+=set2[i];

        }

        

        

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

    }

    /*

        we cannot take element from 1 to l and r to n at same time -> 

        because after reversing we cannot place i1 and ik into the range of l and r;

        so iterate over 1 to r and l to n ; 

        take minimum of this;

    */

  



    return 0;

}