ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049B - pspspsps
Language: c++17 

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

#include <string>

#include <unordered_map>



#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);

using ll = long long;





void solve()

{

    int n;

    std::cin >> n;



    std::string str;

    std::cin >> str;



    // sp.... -> possible

    // ....sp -> possible

    // ps impossible in any case



    // basically p should be leading and only one p is allowed 

    bool p = false, s = false; 

    if (str[0] == 's') str[0] = '.'; if (str[n-1] == 'p') str[n-1] = '.';



    for (char e : str)

    {

        if (e == 'p') p = true;

        if (e == 's') s = true;

    }

    (p && s) ? std::cout << "NO\n" : std::cout << "YES\n";

}



int main()

{

    inout;

    int t = 1;

    std::cin >> t;



    while (t--) solve();

}



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

using namespace std;

#define pi 3.1415926536

#define ll long long

#define el "\n"

#define rr(i,s,e) for(int i = s; i<e ; i++)

#define rrr(i,e,s) for(int i = e-1; i>=s; i--)

#define vi vector<int>

#define pb(e) push_back(e)

#define sv(a) sort(a.begin(),a.end())

#define yes cout << "YES" << el

#define no cout << "NO" << el

void solve()

{

    int n; cin >> n;

    string s; cin >> s;

    bool s_ok = false, p_ok = false;

    int ind;

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

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

            s_ok = true;

            ind = i;

        }else if(s[i] == 'p'){

            p_ok = true;

        }

        if(s[i] == 's' && p_ok){

            no;

            return;

        }

        if(s[i] == 'p' && s_ok && i != n-1 && ind != 0){

            no;

            return;

        }

    }

    yes;

    return;

}



int main(){

    #ifndef ONLINE_JUDGE



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



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



#endif 

   

    int t = 1;

    cin >> t;

    while(t--)

    {

        solve();

    }





    return 0;

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

Solution 1 (runtime: 62 ms):
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;


int main() {
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        ll a[n];
        ll sum = 0;
        for(int i = 0; i < n; i++){
            cin >> a[i];
            sum += a[i];
        }
        vector<ll>v;
        while(n > 1){
            ll add = 0;
            for(int i = 0; i < n-1; i++){
                v.push_back(a[i+1] - a[i]);
            }
            for(int i = 0; i < n-1; i++){
                add += v[i];
            }
            sum = max(sum, abs(add));
            n--;
            for(int i = 0; i < n; i++){
                a[i] = v[i];
            }
            v.clear();
        }
        cout << sum << endl;


    }

    return 0;
}



/*
ll gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

ll lcm(int a, int b){
    return a*b / gcd(a,b);
}
*/
/*
int knapSack(int W, const vector<int>& weights, const vector<int>& values, int n) {

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

    // Build the DP table
    for (int i = 1; i <= n; i++) {
        for (int w = 0; w <= W; w++) {
            if (weights[i - 1] <= w) {
                // Include the item or exclude it
                dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - weights[i - 1]] + values[i - 1]);
            } else {
                // Exclude the item
                dp[i][w] = dp[i - 1][w];
            }
        }
    }

    // The last cell of the DP table contains the maximum value
    return dp[n][W];
}
*/

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

void solve() {
	int n;
	cin>>n;
	vector<long long> a(n);
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		cin>>a[i];
		sum += a[i];
	}
	long long ans = sum;
	while (a.size() > 1) {
		vector<long long> tmp;
		for (int i = 0; i < a.size() - 1; i++) {
			tmp.push_back(a[i+1] - a[i]);
		}
		swap(a, tmp);
		sum = 0;
		for (int i = 0; i < a.size(); i++) {
			sum += a[i];
		}
		ans = max(ans, abs(sum));
	}
	cout<<ans<<'\n';;
	
}

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

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

using namespace std;

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

	while (t--) {
		string n;
		cin >> n;
		for (int i = 0; i < n.length(); ++i) {
			int s = n[i] - '0';
			//cout << s << " ";
			int m = s;
			int r = i;
			for (int j = i+1; j < min((int)(n.length()), i+10); ++j) {
				//cout << (int)n[j] - '0' << " ";
				if ((int)(n[j]-'0')-(j-i) > m) {
					r = j;
					m = n[j]-'0'-(j-i);
				}
			}
			for (int j = r-1; j >= i; --j) {
				n[j+1] = n[j];
			}
			n[i] = m + '0';
		}
		cout << n << "\n";
	}
}


Solution 2 (runtime: 78 ms):
#include <bits/stdc++.h>
using namespace std;
//197->817->861
//185->815
//11555->10321>10-121.
//33
int main(){
	   long long int t;
       cin >> t;
       while(t--){
           string x;
           cin>>x;
           int n=x.size();
		for(int i=0;i<n-1;i++){
			if(x[i]<x[i+1]-1){
				swap(x[i],x[i+1]);
				x[i]--;
				if(i>=1)
				i-=2;
			}
		}
		cout<<x<<endl;
           
       }
       
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--; // Convert to 0-based index
    r--; 

    vector<int> arr(n);
    for (int &x : arr) cin >> x;

    // Create brr: Sort the part of arr from l to n
    vector<int> brr = arr;
    sort(brr.begin() + l, brr.end());

    // Create crr: Sort the part of arr from 0 to r in descending order
    vector<int> crr = arr;
    sort(crr.begin(), crr.begin() + r + 1, greater<int>());

    // Compute sum of subarrays [l, r]
    long long sum_brr = 0, sum_crr = 0;
    for (int i = l; i <= r; i++) {
        sum_brr += brr[i];
        sum_crr += crr[i];
    }

    // Print the minimum sum
    cout << min(sum_brr, sum_crr) << "\n";
}

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

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

    return 0;
}


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

using namespace std;


int main()
{

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

        int n , l , r;
        cin >> n >> l >> r;
        long long sum = 0 ;
        vector < int > L , R;

        vector < int > v( n + 1 ) ;

        for( int i = 1 ; i <= n ; i ++ ){
            cin >> v[i];
            if( i >= 1 && i <= r )R.push_back(v[i]);
            if( i >= l && i <= n )L.push_back(v[i]);

        }
        sort(L.begin(),L.end());
        sort(R.begin(),R.end());

        long long sum1 = 0 , cnt = 0 ;
        while( cnt != r - l + 1 ){
            sum1 += L[cnt];
            cnt++;
        }

        long long sum2 = 0 ;
        cnt = 0 ;
        while(cnt != r-l+1){
            sum2+= R[cnt];
            cnt++;
        }

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


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

Solution 1 (runtime: 46 ms):
#include <iostream>
#include <cmath>
#include <stack>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <deque>
#include <iterator>
#include <queue>
using namespace std;
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

//g++ -o junior junior.cpp -g
typedef set<int>::iterator Iterator;
void solve()
{
    int size;
    std::cin>>size;
    long long arr[size];
    for (int i = 0; i < size; i++)
    {
        std::cin>>arr[i];
    }
    ///
    long long ans = 0;
    for (int i = 0; i < size; i++)
    {
        ans+=arr[i]; //init ans
    }
    
    while (size != 1)
    {
        long long sum=0;
        for (int i = 0; i < size-1; i++)
        {
            arr[i] = arr[i+1] - arr[i];
            sum+=arr[i];
        }
        sum=abs(sum);
        ans = max(sum,ans);
        size--;
    }
    std::cout<<ans;
}
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
int main()
{
    Fast;
    int test;
    std::cin>>test;    
    while (test--)
    {
        solve();
        std::cout<<endl;   
    } 
    return 0;
}

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

int main()
{
    int t;
    cin>>t;
    int n;
    vector<long long>a;
    int a0;
    while(t--)
    {
        cin>>n;
        for(int i=0; i<n; i++)
        {
            cin>>a0;
            a.push_back(a0);
        }
        long long ans=0;
        for(int i=0; i<a.size(); i++) ans+=a[i];
        int op=0;
        while(op<n-1)
        {
            op++;
            for(int i=0; i<n-op; i++) a[i] = a[i+1]-a[i];
            long long tans=0;
            for(int i=0; i<n-op; i++) tans += a[i];
            ans = max(ans, abs(tans));
        }
        cout<<ans<<endl;
        a.clear();
    }
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define vpii vector<pii>
#define F first
#define S second
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7;
const int INF = 1e9;

void solve() {

    string s;
    cin>>s;

    int two = 0;
    int thr = 0;
    int sum=0;

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

    // cout<<sum<<" "<<two<<" "<<thr<<" ";

        for(int i=0 ; i<=two ; i++){
            for(int j=0 ; j<=thr ; j++){
                if((sum + i*2 + j*6)%9==0){
                    cout<<"YES"<<endl;
                    return;
                }
            }
        }

        cout<<"NO"<<endl;

    

    
}

int main() {
    fast_io;

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

    return 0;
}

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

using namespace std;

#define ll long long

void fun()

{

	string a;

	cin >> a;

	ll len = a.size();

	ll r = 0;

	ll a2 = 0, a3 = 0;

	for (ll i = 0; i < len; i++)

	{

		ll tem = (a[i] - '0');

		if (tem == 2)a2++;

		if (tem == 3)a3++;

		r += tem;

		r %= 9;

	}

	for (ll i = 0; i <= a2; i++)

	{

		for (ll j = 0; j <= a3; j++)

		{

			ll tem = i * 2 + j * 6;

			tem += r;

			if (tem % 9 == 0)

			{

				cout << "YES" << endl;

				return;

			}

		}

	}

	cout << "NO" << endl;

}

int main()

{

	int o;

	cin >> o;

	while (o--)

	{

		fun();

	}

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

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

using namespace std;

#define debug(x) cout << '[' << #x << " is: " << x << "] " << endl;
#define imod(a , n) (a % n + n ) % n

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("ladder.in","r",stdin );
#define outF freopen("ladder.out" , "w" , stdout ) ;
#define sor(v) sort(v.begin() , v.end());
//#define print(v) for(auto f : v ) cout << f << " " ;
#define rsor(v) sort(v.rbegin() , v.rend());
#define rev(v) reverse(v.begin() , v.end());
#define scan(v) for(auto &it : v)cin >> it ;

#define logar(x , y) log(x) / log(y)
#define __sum(n) n * (n + 1) / 2
#define __lcm(a , b) a / __gcd(a , b) * b
#define pii pair<int , int >
#define ll long long
#define int ll
#define matrix vector<vector<ll>>
#define pii pair<int , int >

const int di[] = {1 , -1 , 0 , 0};
const int dj[] = {0 , 0 , 1 , -1};

const int mod = 1e9 + 7;
const int N = 1e6 + 6 ;

int check(int a1 ,int a2 ,int  a3 ,int  a4 ,int a5){


    return (a1 + a2 == a3) + (a2 + a3 == a4 )+ (a3 + a4 == a5) ;


}

int32_t main()

{   //inF;
    //inF;outF;
    fastio;

    int t ;
    cin >> t ;

    while(t--){

        int n ;
        cin >> n ;

        vector<int> v(n);
        for(auto &it : v)cin >> it ;
        if(v[1] < v[0])cout << "NO";
        else {
            string ans = "YES";
            int mn = min(v[1] , v[0]);
            v[1] -= mn , v[0] -= mn ;


            for(int i = 2 ; i < n ; i ++){
                if(v[i] < v[i - 1]){
                    v[i - 1] -= min(v[i - 1] , v[i - 2]);

                }
                if(v[i] < v[i - 1]){
                    ans = "NO";
                    break;
                }

                mn = min(v[i] , v[i-1]);
                v[i]-=mn,v[i-1]-=mn;

            }
            cout << ans ;
        }


        cout << '\n';
    }

}




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

using namespace std;

#define int long long

#define hallo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define endl '\n'



int32_t main() {

    // ifstream cin("addin.txt");

    // ofstream cout("addout.txt");

    hallo;

	int t;

	cin>>t;

	for (int count = 0; count<t; count++){

		int n;

		cin>>n;

		vector<int>v(n);

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

			cin>>v[i];

		}



		bool possible = true;

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

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

			// 	possible = false;

			// 	break;

			// }		

			

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

			v[i] -= mini;

			v[i+1] -= mini;

		}



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

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

				possible = false;

				break;

			}

		}







		if (possible){

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

		}

		else {

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

		}





	}

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

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

void solve()
{
    int n; cin>>n;
    vector<int>a(n);
    for(auto &i: a)
    cin>>i;

    int mx = *max_element(a.begin(),a.end());

    // if(mx == a[0]){
    //     no;
    //     return;
    // }
    if(a[0] > a[1]){
        no;
        return;
    }
    int dif = abs(a[0]-a[1]);
    for(int i=1; i<n-1; i++){
        if(dif > a[i+1]){
            no;
            return;
        }
        dif = abs(dif - a[i+1]);
    }
    yes;
}

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

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

    return 0;
}


Solution 2 (runtime: 93 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>;

void tc () {
    ll n;
    cin >> n;
    vll ve(n);
    for (ll &i : ve) cin >> i;
    ll j = 0;
    for (ll i = 1; i < n; i++) {
        if (ve[i-1] > ve[i]) j = i;
    }
    if (j == 0) { // all done
        cout << "YES\n";
        return;
    }
    auto fop = [&](ll i) {
        ll minN = min(ve[i], ve[i+1]);
        ve[i] -= minN;
        ve[i+1] -= minN;
    };
    for (ll i = 0; i < j; i++) {
        fop(i);
    }
    cout << (is_sorted(ve.begin(), ve.end()) ? "YES" : "NO") << '\n';
}

int main () {
    cin.tie(nullptr) -> sync_with_stdio(false);
    ll T; cin >> T; while (T--) { tc(); }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: c++17 

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

typedef long long ll;
//#define int long long
using namespace std;
const int mod = 998244353;
const int N = 2e5 + 5;


int a[N], b[N];


void solve() {
    int m, n;
    cin >> n >> m;
    ll sma = 0, smb = 0;
    int x;
    map<int, int, greater<> > mpa, mpb;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        sma += x;
        mpa[x]++;
    }
    for (int i = 0; i < m; ++i) {
        cin >> x;
        smb += x;
        mpb[x]++;
    }
    if (sma != smb) {
        cout << "No\n";
        return;
    }
    int z = n - m;
    for (auto &p: mpb) {
        int w = p.first, cnt = p.second;
        if (mpa[w] != 0) {
            int t = min(mpa[w], cnt);
            mpa[w] -= t;
            cnt -= t;
        }
        if (cnt > 0) {
            if (w % 2 == 0) {
                mpb[w / 2] += 2*cnt;
            } else {
                mpb[w / 2]+=cnt;
                mpb[w / 2 + 1]+=cnt;
            }
            z-=cnt;
            if (z < 0) {
                cout << "No\n";
                return;
            }
        }
    }
    cout << "Yes\n";


}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int _;
    cin >> _;
    while (_--)solve();
}


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

#include <vector>

#include <cstring>

#include <cmath>

#include <unordered_map>

#include <map>

#include <algorithm>

using namespace std;







int main()

{

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

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

    int T;

    cin >> T;

    while(T--)

    {

        int n, m;

        cin >> n >> m;

        map<int, int> uma;

        map<int, int> umb;

        int x;

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

        {

            cin >> x;

            uma[x]++;

        }

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

        {

            cin >> x;

            umb[x]++;

        }

        bool flag = 1;

        int res = n - m;

        for (auto it = umb.rbegin(); it != umb.rend();++it)

        {

            int t = it->first;

            //cout << t << ' ';

            if(uma[t] > it->second){

                flag = 0;

                break;

            }

            if(uma[t] != it->second && t == 1)

            {

                flag = 0;

                break;

            }

            if(uma[t] < it->second){

                umb[t / 2] += it->second - uma[t];

                umb[(t + 1) / 2] += it->second - uma[t];

                res -= it->second - uma[t];

                it->second = uma[t];

            }

        }

        if(flag && (res == 0))

            cout << "Yes" << endl;

        else

            cout << "No" << endl;

    }

    return 0;

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

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1000000007;
int main(){
ll t;
cin>>t;
while(t--){
    ll n;
    cin>>n;
    vector<ll>arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }

    ll sum=accumulate(arr.begin(),arr.end(),0LL);


    while(n>1){
        vector<ll>v;

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

        ll s=accumulate(v.begin(),v.end(),0LL);

        sum=max(sum,abs(s));

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

      n--;

    }


cout<<sum<<endl;


}
return 0;
}

Solution 2 (runtime: 46 ms):
///sadekalprince31
#include<bits/stdc++.h>
#define ll long long
#define en endl
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define op()                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define tc    \
    ll t;     \
    cin >> t; \
    while (t--)
#define yes cout << "YES\n";
#define no cout << "NO\n";
const ll MOD = 1e9 + 7;
const ll N = 1e10;
using namespace std;

signed main()
{
    op();
    tc
    {
    ll n, i, ans=0;
    cin >> n;
    vl v1(n);
    for (i = 0; i < n; i++)
    {
        cin >> v1[i];
        ans += v1[i];
    }
    while (n > 1)
    {
 
        ll res = 0;
        for (i = 0; i < (n - 1); i++)
        {
            v1[i] = v1[i + 1] - v1[i];
            res += v1[i];
        }
        v1.pop_back();
        ans = max(ans, abs(res));
        n--;
    }
    cout << ans << en;
    }

}

///THE__END///
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 328 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define forr(i,x,n) for(int i = x; i < n ; i ++ ) 

int32_t main() {
    int t;
    cin>>t;
    while(t--){
        int n ;
        cin >> n;  
        int a[n] ; 
        int s=0;
        int pe=0 , le = 0 ; 
        int po=0 , lo = 0 ; 
        forr(i,0, n){ 
            cin >> a[i] ;  
            s+=a[i];
        } 
        bool ok = false ; 
        if(s%n==0){ok = true ;}
        else { ok = false ;} 
        
        if(ok) {
        int x = s/n; 
        forr(i,0,n) { 
            
            if(i%2==0) { 
                if (a[i] > x) { 
                    pe+= a[i] - x; 
                } 
                else le+= x - a[i]; 
            } 
            else { 
                if(a[i]>x) po+=  a[i] - x; 
                else lo+=  x - a[i];  
            } 
                
        }  
        } 
        if(ok && po == lo && pe == le  ) cout << "YES" << endl ; 
        else cout<< "NO" << endl ;  
        
        
        
        
       // if(ok) cout<< "YES" << endl ; 
      //  else cout << "NO" << endl ; 
     
    } 

}


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

#include <bits/stdc++.h>

using namespace std;



int main()

{

    int t;

    cin>>t;

    while(t--)

    {

        long n;

        cin>>n;

        long long a[n],avg=0,even=0,odd=0;

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

        {

           cin>>a[i];

           avg+=a[i];

        }

        avg/=n;

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

        {

            a[i]=avg-a[i];

            if(i%2==0)

                even+=a[i];

            else

                odd+=a[i];

        }

        if(even==0&&odd==0)

            cout<<"YES"<<endl;

        else

            cout<<"NO"<<endl;

    }

    return 0;

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

Solution 1 (runtime: 92 ms):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vc = vector<char>;
using vb = vector<bool>;
#define ppi pair<int,pair<int,int>>
#define pi pair<int,int>
#define ss second
#define ff first
#define endl "\n"
#define pb push_back
#define sz(x) (int)(x).size()
#define ONPC
#define in(n) cin>>(n)
#define inf LONG_LONG_MAX;
const int mod = 1e9+7;

void solve(){
	int n;
	ll suml=0,sumr=0,l,r,ans=inf;
	cin>>n>>l>>r;
	vector<ll> a(n),left,right;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<r;i++)left.push_back(a[i]);
	sort(left.begin(),left.end());
	for(int i=0;i<r-l+1;i++) suml+=left[i];
	for(int i=l-1;i<n;i++) right.push_back(a[i]);
	sort(right.begin(),right.end());
	for(int i=0;i<r-l+1;i++)sumr+=right[i];
	ans=min(suml,sumr);
	cout<<ans<<"\n";
}


int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int t;cin>>t;
    while(t--){
        solve();
    }
    #ifdef ONPC
     cerr<< endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
    #endif
}




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

using namespace std;
#define LL long long 
 int  main()
{
     long long t;
     cin>>t;
    while(t--)
    {
         long long n,l,r;
        cin>>n>>l>>r;
        vector<long long >a(n);
        vector<long long >b;
        vector<long long >c;
        for( long long i=0;i<n;i++)
        {
            cin>>a[i];
        }
        l--,r--;
        for( long long i=0;i<=r;i++)
        {
            b.push_back(a[i]);
        }
        for( long long i=l;i<n;i++)
        {
            c.push_back(a[i]);
        }
        sort(b.begin(),b.end());
        sort(c.begin(),c.end());
         long long sum1 = accumulate(b.begin(),b.begin()+int(r-l+1),0LL);
         long long sum2 = accumulate(c.begin(),c.begin()+int(r-l+1),0LL);
        cout<<min(sum1,sum2)<<endl;

        

    }
}