ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define endl '\n'
typedef pair <int,int> PII;
const int dx[] = {1,0,-1,0},dy[] = {0,-1,0,1};
template <typename T1,typename T2> bool tomax (T1 &x,T2 y) {
    if (y > x) return x = y,true;
    return false;
}
template <typename T1,typename T2> bool tomin (T1 &x,T2 y) {
    if (y < x) return x = y,true;
    return false;
}
inline int qmi(int a,int b,int p){
    int ans=1%p;
    for(;b;b>>=1){
        if(b&1) ans=(long long)ans*a%p;
        a=(long long)a*a%p;
    }
    return ans;
}
const int N=2e5+10;
#define int long long
inline int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
int n,m;
int a[N],b[N];
map<int,int> mpa;
bool get(int s){
	if(!s) return false;
	int x,y;
	if(s%2==0){
		x=y=s/2;
	}else{
		x=s/2;
		y=x+1;
	}
	if(mpa[x]) mpa[x]--;
	else return get(x);
	if(mpa[y]) mpa[y]--;
	else return get(y);
	return true;
}
void solve(){
	mpa.clear();
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mpa[a[i]]++;
	}
	for(int i=1;i<=m;i++){
		cin>>b[i];
	}
	sort(b+1,b+m+1,less<int>());
	bool res=true;
	for(int i=1;i<=m;i++){
		int x,y;
		if(b[i]%2==0){
			x=y=b[i]/2;
		}else{
			x=b[i]/2;
			y=x+1;
		}
		if(mpa[b[i]]) mpa[b[i]]--;
		else{
			if(mpa[x]) mpa[x]--;
			else{
				res=get(x);
				if(!res) break;
			}
			if(mpa[y]) mpa[y]--;
			else{
				res=get(y);
				if(!res) break;
			}
		}
	}
	for(auto v:mpa){
		if(v.second){
			res=false;
			break;
		}
	}
	if(res) cout<<"YES\n";
	else cout<<"NO\n";
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t=1;
    cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define el "\n"
#define OrganicBot ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define MOD 998244353
#define int long long
#define vi vector<int>
#define all(x) (x).begin(), (x).end()

using namespace std;

vector<int> applyDifference(const vector<int>& seq) {
    vector<int> diffSeq;
    for (int i = 1; i < seq.size(); ++i) {
        diffSeq.push_back(seq[i] - seq[i-1]);
    }
    return diffSeq;
}

void solve() {
    int n;
    cin >> n;
    
    vi seq(n);
    for(int i=0;i<n;i++){
        cin >> seq[i];
    }
    int og = accumulate(all(seq),0ll);

    while (seq.size() > 1) {
        // Step 1: Apply difference operation
        seq = applyDifference(seq);
        
        // Step 2: Reverse the sequence
        reverse(seq.begin(), seq.end());
    }

    // The final result, which is the only remaining element
    if(n!=1)
    cout<< max(og,abs(seq[0])) << endl;
    else
        cout << og << el;
}

signed main() {
    OrganicBot;
    int t;
    cin >> t;  // Number of test cases

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

    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define el "\n"
#define OrganicBot ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define MOD 998244353
#define int long long
#define vi vector<int>
#define all(x) (x).begin(), (x).end()

using namespace std;

vector<int> applyDifference(const vector<int>& seq) {
    vector<int> diffSeq;
    for (int i = 1; i < seq.size(); ++i) {
        diffSeq.push_back(seq[i] - seq[i-1]);
    }
    return diffSeq;
}

void solve() {
    int n;
    cin >> n;
    
    vi seq(n);
    for(int i=0;i<n;i++){
        cin >> seq[i];
    }
    int og = accumulate(all(seq),0ll);
    int ans = og;
    while (seq.size() > 1) {
        // Step 1: Apply difference operation
        seq = applyDifference(seq);
        
        // Step 2: Reverse the sequence
        reverse(seq.begin(), seq.end());
        ans = max(og,abs(accumulate(all(seq),0ll)));
    }

    // The final result, which is the only remaining element
        cout << ans << el;
}

signed main() {
    OrganicBot;
    int t;
    cin >> t;  // Number of test cases

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

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define el "\n"
#define OrganicBot ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define MOD 998244353
#define int long long
#define vi vector<int>
#define all(x) (x).begin(), (x).end()

using namespace std;

vector<int> applyDifference(const vector<int>& seq) {
    vector<int> diffSeq;
    for (int i = 1; i < seq.size(); ++i) {
        diffSeq.push_back(seq[i] - seq[i-1]);
    }
    return diffSeq;
}

void solve() {
    int n;
    cin >> n;
    
    vi seq(n);
    for(int i=0;i<n;i++){
        cin >> seq[i];
    }
    int og = accumulate(all(seq),0ll);
    int ans = og;
    while (seq.size() > 1) {
        // Step 1: Apply difference operation
        seq = applyDifference(seq);
        
        // Step 2: Reverse the sequence
        reverse(seq.begin(), seq.end());
        ans = max(og,abs(accumulate(all(seq),0ll)));
    }

    // The final result, which is the only remaining element
        cout << ans << el;
}

signed main() {
    OrganicBot;
    int t;
    cin >> t;  // Number of test cases

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

    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
#define el "\n"
#define OrganicBot ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define MOD 998244353
#define int long long
#define vi vector<int>
#define all(x) (x).begin(), (x).end()

using namespace std;

vector<int> applyDifference(const vector<int>& seq) {
    vector<int> diffSeq;
    for (int i = 1; i < seq.size(); ++i) {
        diffSeq.push_back(seq[i] - seq[i-1]);
    }
    return diffSeq;
}

void solve() {
    int n;
    cin >> n;
    
    vi seq(n);
    for(int i=0;i<n;i++){
        cin >> seq[i];
    }
    int og = accumulate(all(seq),0ll);
    int ans = og;
    while (seq.size() > 1) {
        // Step 1: Apply difference operation
        seq = applyDifference(seq);
        ans = max(ans,abs(accumulate(all(seq),0ll)));
    }

    // The final result, which is the only remaining element
        cout << max(og,ans) << el;
}

signed main() {
    OrganicBot;
    int t;
    cin >> t;  // Number of test cases

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

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define el "\n"
#define OrganicBot ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define MOD 998244353
#define int long long
#define vi vector<int>
#define all(x) (x).begin(), (x).end()

using namespace std;

vector<int> applyDifference(const vector<int>& seq) {
    vector<int> diffSeq;
    for (int i = 1; i < seq.size(); ++i) {
        diffSeq.push_back(seq[i] - seq[i-1]);
    }
    return diffSeq;
}

void solve() {
    int n;
    cin >> n;
    
    vi seq(n);
    for(int i=0;i<n;i++){
        cin >> seq[i];
    }
    int og = accumulate(all(seq),0ll);

    while (seq.size() > 1) {
        // Step 1: Apply difference operation
        seq = applyDifference(seq);
        
        // Step 2: Reverse the sequence
        reverse(seq.begin(), seq.end());
    }

    // The final result, which is the only remaining element
    if(n!=1)
    cout<< max(og,abs(seq[0])) << endl;
    else
        cout << og << el;
}

signed main() {
    OrganicBot;
    int t;
    cin >> t;  // Number of test cases

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

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test,n,s;
    int a[100];
    cin >> test;
    while(test--){
        cin >> n;
        int s=0;
        for(int i=1;i<=51;i++){
            a[i]=0;
        }
        for(int i=1; i<=n;i++){
            cin >> a[i];
            s+=a[i];
        }
        int tsum,temp;
        while(n>1){
            tsum=0;
            if(a[1]>=a[n]){
                for(int i=1;i<=n/2;i++){
                    temp=a[i];
                    a[i]=a[n+1-i];
                    a[n+1-i]=temp;
                }
            }
            tsum=a[n]-a[1];
            if(tsum>=s){
                s=tsum;
            }
            for(int i=1;i<n;i++){
                a[i]=a[i+1]-a[i];
            }
            --n;
        }
        cout << s << "\n";
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long test,n,s;
    long long a[100];
    cin >> test;
    while(test--){
        cin >> n;
        long long s=0;
        for(int i=1;i<=51;i++){
            a[i]=0;
        }
        for(int i=1; i<=n;i++){
            cin >> a[i];
            s+=a[i];
        }
        long long tsum,temp;
        while(n>1){
            tsum=0;
            if(a[1]>=a[n]){
                for(int i=1;i<=n/2;i++){
                    temp=a[i];
                    a[i]=a[n+1-i];
                    a[n+1-i]=temp;
                }
            }
            tsum=a[n]-a[1];
            if(tsum>=s){
                s=tsum;
            }
            for(int i=1;i<n;i++){
                a[i]=a[i+1]-a[i];
            }
            --n;
        }
        cout << s << "\n";
    }
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test,n,s;
    int a[100];
    cin >> test;
    while(test--){
        cin >> n;
        int s=0;
        for(int i=1; i<=n;i++){
            cin >> a[i];
            s+=a[i];
        }
        int tsum,temp;
        while(n>=1){
            tsum=0;
            if(a[1]>=a[n]){
                for(int i=1;i<=n/2;i++){
                    temp=a[i];
                    a[i]=a[n+1-i];
                    a[n+1-i]=temp;
                }
            }
            tsum=a[n]-a[1];
            if(tsum>=s){
                s=tsum;
            }
            for(int i=1;i<n;i++){
                a[i]=a[i+1]-a[i];
            }
            --n;
        }
        cout << s << "\n";
    }
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test,n,s;
    int a[100];
    cin >> test;
    while(test--){
        cin >> n;
        int s=0;
        for(int i=1; i<=n;i++){
            cin >> a[i];
            s+=a[i];
        }
        int tsum,temp;
        while(n>1){
            tsum=0;
            if(a[1]>=a[n]){
                for(int i=1;i<=n/2;i++){
                    temp=a[i];
                    a[i]=a[n+1-i];
                    a[n+1-i]=temp;
                }
            }
            tsum=a[n]-a[1];
            if(tsum>=s){
                s=tsum;
            }
            for(int i=1;i<n;i++){
                a[i]=a[i+1]-a[i];
            }
            --n;
        }
        cout << s << "\n";
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test,n,s;
    int a[100];
    cin >> test;
    while(test--){
        cin >> n;
        int s=0;
        for(int i=1;i<=51;i++){
            a[i]=0;
        }
        for(int i=1; i<=n;i++){
            cin >> a[i];
            s+=a[i];
        }
        int tsum,temp;
        while(n>1){
            tsum=0;
            if(a[1]>=a[n]){
                for(int i=1;i<=n/2;i++){
                    temp=a[i];
                    a[i]=a[n+1-i];
                    a[n+1-i]=temp;
                }
            }
            tsum=a[n]-a[1];
            if(tsum>=s){
                s=tsum;
            }
            for(int i=1;i<n;i++){
                a[i]=a[i+1]-a[i];
            }
            --n;
        }
        cout << s << "\n";
    }
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test,n,s;
    int a[100];
    cin >> test;
    while(test--){
        cin >> n;
        int s=0;
        for(int i=1; i<=n;i++){
            cin >> a[i];
            s+=a[i];
        }
        int tsum,temp;
        while(n>=1){
            tsum=0;
            if(a[1]>=a[n]){
                for(int i=1;i<=n/2;i++){
                    temp=a[i];
                    a[i]=a[n+1-i];
                    a[n+1-i]=temp;
                }
            }
            tsum=a[n]-a[1];
            if(tsum>=s){
                s=tsum;
            }
            for(int i=1;i<n;i++){
                a[i]=a[i+1]-a[i];
            }
            --n;
        }
        cout << s << "\n";
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test,n,s;
    int a[100];
    cin >> test;
    while(test--){
        cin >> n;
        int s=0;
        for(int i=1; i<=n;i++){
            cin >> a[i];
            s+=a[i];
        }
        int tsum,temp;
        while(n>1){
            tsum=0;
            if(a[1]>=a[n]){
                for(int i=1;i<=n/2;i++){
                    temp=a[i];
                    a[i]=a[n+1-i];
                    a[n+1-i]=temp;
                }
            }
            tsum=a[n]-a[1];
            if(tsum>=s){
                s=tsum;
            }
            for(int i=1;i<n;i++){
                a[i]=a[i+1]-a[i];
            }
            --n;
        }
        cout << s << "\n";
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
 
using i64 = long long;
 
void solve() {
    int l, r;
    std::cin >> l >> r;
    int k = 31 - __builtin_clz(l ^ r);
    int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
    std::cout << a << " " << b << " " << c << "\n";
}
 
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
 
    int t = 1;
    std::cin >> t;
 
    while (t--) {
        solve();
    }
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
void solve() {
    int l,r;
    cin >> l >> r;
    int a=l;
    int b=r;
    int msb=31-__builtin_clz(r);
    bool first=false;
    bool second=false;
    for (int i=msb;i>=0;i--) {
        int big=b&(1<<i);
        int smol=a&(1<<i);
        if (smol==0&&first||first&&second) {
            second=true;
            a^=(1<<i);
        }
        if (big>0&&smol==0)
            first=true;
    }
    int c=0;
    for (int i=msb;i>=0;i--) {
        int big=b&(1<<i);
        int smol=a&(1<<i);
        if (big&&smol) {
            c^=(1<<i);
        }else if (big) {
            c^=(1<<i);
            break;
        }
    }
    if (c==b) {
        for (int i=l;i<r;i++) {
            if (i!=a&&i!=b) {
                c=i;
                break;
            }
        }
    }
    cout << a << " " << b << " " << c << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
void solve() {
    int l,r;
    cin >> l >> r;
    int a=l;
    int b=r;
    int msb=31-__builtin_clz(r);
    bool first=false;
    bool second=false;
    for (int i=msb;i>=0;i--) {
        int big=b&(1<<i);
        int smol=a&(1<<i);
        if (smol==0&&first||first&&second) {
            second=true;
            a^=(1<<i);
        }
        if (big>0&&smol==0)
            first=true;
    }
    int c=0;
    for (int i=msb;i>=0;i--) {
        int big=b&(1<<i);
        int smol=a&(1<<i);
        if (big&&smol) {
            c^=(1<<i);
        }else if (big) {
            c^=(1<<i);
            break;
        }
    }
    if (c==b) {
        for (int i=l;i<r;i++) {
            if (i!=a&&i!=b) {
                c=i;
                break;
            }
        }
    }
    cout << a << " " << b << " " << c << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

Submission (verdict: Wrong answer on test 1):
// Online C++ compiler to run C++ program online
using namespace std;
#include <bits/stdc++.h>

int main() {
    /*
    b1, b1, b2
    b1, b1
    b1, b1
    11, 10, 01: 01, 11, 10: 1 + 3 + 2 = 6
    
    01, 10, 00: 11, 10, 01: 6
    1000:
    1111, 0, 1
    100000, 1111111, 1111110
    n, n-1, n-2: where n is the largest set bit smaller than r
    101101:
    odd: 101101, 101100, 
    111001
    even: 101100, 101111, 
    
    1000, 0111, 0110
    1<<i: 2^0, 2^1, 2^2
    (1<<i)&r != 0
    
    
    */
    int t;
    cin>>t;
    while(t--){
        int l, r;
        cin>>l>>r;
        if(r-l == 2){
            cout<<r<<" "<<r-1<<" "<<l<<endl;
            return;
        }
        
        int maxVal = 0;
        for(int i=0;i<31;i++){
            if((1<<i) & r){
                maxVal = (1<<i);
            }
        }
        if(maxVal-2 >= l){
            cout<<maxVal<<" "<<maxVal-1<<" "<<maxVal-2<<endl;
            return;
        }
        cout<<r<<" "<<r-1<<" "<<r-2<<endl;
        
        
        
        
    }
    
    
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
 
using i64 = long long;
 
void solve() {
    int l, r;
    std::cin >> l >> r;
    int k = 31 - __builtin_clz(l ^ r);
    int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
    std::cout << a << " " << b << " " << c << "\n";
}
 
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
 
    int t = 1;
    std::cin >> t;
 
    while (t--) {
        solve();
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
// Online C++ compiler to run C++ program online
using namespace std;
#include <bits/stdc++.h>

int main() {
    /*
    b1, b1, b2
    b1, b1
    b1, b1
    11, 10, 01: 01, 11, 10: 1 + 3 + 2 = 6
    
    01, 10, 00: 11, 10, 01: 6
    1000:
    1111, 0, 1
    100000, 1111111, 1111110
    n, n-1, n-2: where n is the largest set bit smaller than r
    101101:
    odd: 101101, 101100, 
    111001
    even: 101100, 101111, 
    
    1000, 0111, 0110
    1<<i: 2^0, 2^1, 2^2
    (1<<i)&r != 0
    
    
    */
    int t;
    cin>>t;
    while(t--){
        int l, r;
        cin>>l>>r;
        if(r-l == 2){
            cout<<r<<" "<<r-1<<" "<<l<<endl;
            return;
        }
        
        int maxVal = 0;
        for(int i=0;i<31;i++){
            if((1<<i) & r){
                maxVal = (1<<i);
            }
        }
        if(maxVal-2 >= l){
            cout<<maxVal<<" "<<maxVal-1<<" "<<maxVal-2<<endl;
            return;
        }
        cout<<r<<" "<<r-1<<" "<<r-2<<endl;
        
        
        
        
    }
    
    
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
void solve() {
    int l,r;
    cin >> l >> r;
    int a=l;
    int b=r;
    int msb=31-__builtin_clz(r);
    bool first=false;
    bool second=false;
    for (int i=msb;i>=0;i--) {
        int big=b&(1<<i);
        int smol=a&(1<<i);
        if (smol==0&&first||first&&second) {
            int temp=(1<<i)&b;
            if (temp==0&&smol==0) {
                a^=(1<<i);
                second=true;
            }else if (temp&&smol) {
                a^=(1<<i);
            }
        }
        if (big>0&&smol==0)
            first=true;
    }
    int c=0;
    for (int i=msb;i>=0;i--) {
        int big=b&(1<<i);
        int smol=a&(1<<i);
        if (big&&smol) {
            c^=(1<<i);
        }else if (big) {
            c^=(1<<i);
            break;
        }
    }
    if (c==b) {
        for (int i=l;i<r;i++) {
            if (i!=a&&i!=b) {
                c=i;
                break;
            }
        }
    }
    cout << a << " " << b << " " << c << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>

using namespace std;



#define int long long

#define endl '\n'

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

#define pb push_back

#define vi vector<int>

#define mii map<int, int>

#define pii pair<int, int>



void solve(){

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

    vi a(n);

    for(int &x: a)  cin >> x;

    vi b = a;

    sort(a.begin(), a.begin() + r);

    reverse(a.begin(), a.begin() + r);

    sort(b.begin() + l - 1, b.end());

    cout << min(accumulate(a.begin() + l - 1, a.begin() + r, 0), accumulate(b.begin() + l - 1, b.begin() + r, 0)) << endl;

}



signed main(){

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin >> t;

    while(t--){

        solve();

    }

    return 0;

}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;



#define int long long

#define endl '\n'

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

#define pb push_back

#define vi vector<int>

#define mii map<int, int>

#define pii pair<int, int>



void solve(){

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

    vi a(n);

    for(int &x: a)  cin >> x;

    vi b = a;

    sort(a.begin(), a.begin() + r);

    reverse(a.begin(), a.begin() + r);

    sort(b.begin() + l - 1, b.end());

    cout << min(accumulate(a.begin() + l - 1, a.begin() + r, 0ll), accumulate(b.begin() + l - 1, b.begin() + r, 0ll)) << endl;

}



signed main(){

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin >> t;

    while(t--){

        solve();

    }

    return 0;

}