ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


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

using namespace std;

bool cmp(pair<int,int> &a, pair<int,int> &b) {
    return a.second > b.second;
}

void solution() {
    int n;
    cin >> n;
    vector<int>v;
    for(int i = 0; i < n; i++){int a; cin >> a; v.push_back(a);}
    long long int ans = accumulate(v.begin(), v.end(), 0) * 1LL;
    while(v.size() != 1) {
        vector<int>v2;
        int diff = v.back() - v[0];
        if(diff < 0) {
            reverse(v.begin(), v.end());
            for(int i = 1; i < v.size(); i++) {
                v2.push_back(v[i] - v[i - 1]);
            }
        }else {
            for(int i = 1; i < v.size(); i++) {
                v2.push_back(v[i] - v[i - 1]);
            }
        }
        v.pop_back();
        for(int i = 0; i < v.size(); i++)v[i] = v2[i];
        ans = max(ans, accumulate(v.begin(), v.end(), 0) * 1LL);
    }

    cout << ans << endl;



}


int main() {
    int t;
    cin >> t;
    while(t--) {
        solution();
    }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

using namespace std;

bool cmp(pair<int,int> &a, pair<int,int> &b) {
    return a.second > b.second;
}

void solution() {
    int n;
    cin >> n;
    vector<long long int>v;
    for(int i = 0; i < n; i++){int a; cin >> a; v.push_back(a);}
    long long int ans = accumulate(v.begin(), v.end(), 0) * 1LL;
    while(v.size() != 1) {
        vector<long long int>v2;
        int diff = v.back() - v[0];
        if(diff < 0) {
            reverse(v.begin(), v.end());
            for(int i = 1; i < v.size(); i++) {
                v2.push_back(v[i] - v[i - 1]);
            }
        }else {
            for(int i = 1; i < v.size(); i++) {
                v2.push_back(v[i] - v[i - 1]);
            }
        }
        v.pop_back();
        for(int i = 0; i < v.size(); i++)v[i] = v2[i];
        ans = max(ans, accumulate(v.begin(), v.end(), 0) * 1LL);
    }

    cout << ans << endl;



}


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

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

using namespace std;

bool cmp(pair<int,int> &a, pair<int,int> &b) {
    return a.second > b.second;
}

void solution() {
    int n;
    cin >> n;
    vector<long long int>v;
    for(int i = 0; i < n; i++){int a; cin >> a; v.push_back(a);}
    long long int ans = accumulate(v.begin(), v.end(), 0) * 1LL;
    while(v.size() != 1) {
        vector<long long int>v2;
        
        for(int i = 1; i < v.size(); i++) {
            v2.push_back(v[i] - v[i - 1]);
        }
        
        for(int i = 0; i < v2.size(); i++)v[i] = v2[i];
        v.pop_back();
        long long x = 0;
        for(auto it : v2)x += it;
        
        ans = max(ans, max(x, -x));
    }
    long long y = 0;
    for(auto it : v)y += it;
    ans = max(y, ans);

    cout << ans << endl;



}


int main() {
    int t;
    cin >> t;
    while(t--) {
        solution();
    }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

using namespace std;

bool cmp(pair<int,int> &a, pair<int,int> &b) {
    return a.second > b.second;
}

void solution() {
    int n;
    cin >> n;
    vector<int>v;
    for(int i = 0; i < n; i++){int a; cin >> a; v.push_back(a);}
    long long int ans = accumulate(v.begin(), v.end(), 0) * 1LL;
    while(v.size() != 1) {
        vector<int>v2;
        int diff = v.back() - v[0];
        if(diff < 0) {
            reverse(v.begin(), v.end());
            for(int i = 1; i < v.size(); i++) {
                v2.push_back(v[i] - v[i - 1]);
            }
        }else {
            for(int i = 1; i < v.size(); i++) {
                v2.push_back(v[i] - v[i - 1]);
            }
        }
        v.pop_back();
        for(int i = 0; i < v.size(); i++)v[i] = v2[i];
        ans = max(ans, accumulate(v.begin(), v.end(), 0) * 1LL);
    }

    cout << ans << endl;



}


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

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

using namespace std;

bool cmp(pair<int,int> &a, pair<int,int> &b) {
    return a.second > b.second;
}

void solution() {
    int n;
    cin >> n;
    vector<long long int>v;
    for(int i = 0; i < n; i++){int a; cin >> a; v.push_back(a);}
    long long int ans = accumulate(v.begin(), v.end(), 0) * 1LL;
    while(v.size() != 1) {
        vector<long long int>v2;
        int diff = v.back() - v[0];
        if(diff < 0) {
            reverse(v.begin(), v.end());
            for(int i = 1; i < v.size(); i++) {
                v2.push_back(v[i] - v[i - 1]);
            }
        }else {
            for(int i = 1; i < v.size(); i++) {
                v2.push_back(v[i] - v[i - 1]);
            }
        }
        v.pop_back();
        for(int i = 0; i < v.size(); i++)v[i] = v2[i];
        ans = max(ans, accumulate(v.begin(), v.end(), 0) * 1LL);
    }

    cout << ans << endl;



}


int main() {
    int t;
    cin >> t;
    while(t--) {
        solution();
    }
}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

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

typedef long long ll;
#define endl '\n'
#define No cout<<"NO"<<endl
#define Yes cout<<"YES"<<endl
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void omaer()
{
  int n;
  cin>>n;

  int o=0, e=0;
  for(int i=0;i<n;i++)
  {
    int a;
    cin>>a;

    if(i%2==0) e+=a;
    else o+=a;
  }

  int od=n/2, ev=n/2;
  if(n&1) ev+=1;

  if(o%od!=0 || e%ev!=0 || o/od != e/ev) No;
  else Yes;
}

int main()
{
    optimize();

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

	return 0;
}


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

typedef long long ll;
#define endl '\n'
#define No cout<<"NO"<<endl
#define Yes cout<<"YES"<<endl
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void omaer()
{
  int n;
  cin>>n;

  int o=0, e=0;
  for(int i=0;i<n;i++)
  {
    int a;
    cin>>a;

    if(i%2) o+=a;
    else e+=a;
  }

  int od=n/2, ev=n/2;
  if(n&1) ev+=1;

  if(o%od!=0 || e%ev!=0 || o/od != e/ev) No;
  else Yes;
}

int main()
{
    optimize();

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

	return 0;
}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

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

typedef long long ll;
#define endl '\n'
#define No cout<<"NO"<<endl
#define Yes cout<<"YES"<<endl
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void omaer()
{
  int n;
  cin>>n;

  int o=0, e=0;
  for(int i=0;i<n;i++)
  {
    int a;
    cin>>a;

    if(i%2) o+=a;
    else e+=a;
  }

  int od=n/2, ev=n/2;
  if(n&1) ev+=1;

  if(o%od!=0 || e%ev!=0 || o/od != e/ev) No;
  else Yes;
}

int main()
{
    optimize();

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

	return 0;
}


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

typedef long long ll;
#define endl '\n'
#define No cout<<"NO"<<endl
#define Yes cout<<"YES"<<endl
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void omaer()
{
  int n;
  cin>>n;

  ll o=0, e=0;
  for(int i=0;i<n;i++)
  {
    int a;
    cin>>a;

    if(i%2==0) e+=a;
    else o+=a;
  }

  ll od=n/2, ev=n/2;
  if(n&1) ev+=1;

  if(o%od!=0 || e%ev!=0 || o/od != e/ev) No;
  else Yes;
}

int main()
{
    optimize();

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

	return 0;
}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)


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

typedef long long ll;
#define endl '\n'
#define No cout<<"NO"<<endl
#define Yes cout<<"YES"<<endl
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void omaer()
{
  int n;
  cin>>n;

  int o=0, e=0;
  for(int i=0;i<n;i++)
  {
    int a;
    cin>>a;

    if(i%2==0) e+=a;
    else o+=a;
  }

  int od=n/2, ev=n/2;
  if(n&1) ev+=1;

  if(o%od!=0 || e%ev!=0 || o/od != e/ev) No;
  else Yes;
}

int main()
{
    optimize();

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

	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <algorithm> // Ensure __gcd is recognized
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <unordered_map>
#include <cstring>
#include <climits>
#include <iomanip>
#include <numeric>
#include <map>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
const int MODD = 32768;
const int MOD = 1e9 + 7;
ll poww(int x, int n, int m)
{
    if (n == 0) return 1;
    ll u = poww(x, n / 2, m);
    u = (u * u) % m;
    if (n & 1) u = (u * x) % m;
    return u;
}
int fact(int n)
{
      if(n==0)
      return 1;
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = (res * i) % MOD;
    return res;
}
long nCr(int n, int r)
{
    return (poww(fact(n) / (fact(r) * fact(n - r)), MOD -1 , MOD));
}



void solve() {
  
    int n; cin >> n;
    int k; cin >> k;
    
    map<int, int> freq;
    for (int i = 0; i < n;i++)
    {
        int temp; cin >> temp;
        freq[temp]++;
    }
    int max_freq = 0;
    int total_freq = freq.size();
    for (auto &it: freq)
    {
        if (it.second <= k)
        {
            total_freq--;
            k -= it.second;
        }
    }
    cout << max(total_freq, 1);
    label: cout << endl;
    
}
int main() {
    fast;
    int t = 1;
   cin >> t;

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


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <algorithm> // Ensure __gcd is recognized
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <unordered_map>
#include <cstring>
#include <climits>
#include <iomanip>
#include <numeric>
#include <map>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
const int MODD = 32768;
const int MOD = 1e9 + 7;
ll poww(int x, int n, int m)
{
    if (n == 0) return 1;
    ll u = poww(x, n / 2, m);
    u = (u * u) % m;
    if (n & 1) u = (u * x) % m;
    return u;
}
int fact(int n)
{
      if(n==0)
      return 1;
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = (res * i) % MOD;
    return res;
}
long nCr(int n, int r)
{
    return (poww(fact(n) / (fact(r) * fact(n - r)), MOD -1 , MOD));
}



void solve() {
  
    int n; cin >> n;
    int k; cin >> k;
    
    map<int, int> freq;
    for (int i = 0; i < n;i++)
    {
        int temp; cin >> temp;
        freq[temp]++;
    }
    int max_freq = 0;
    int total_freq = freq.size();
    for (auto &it: freq)
    {
        if (it.second <= k && k > 0)
        {
            total_freq--;
            k -= it.second;
        }
    }
    cout << max(total_freq, 1);
    label: cout << endl;
    
}
int main() {
    fast;
    int t = 1;
   cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <algorithm> // Ensure __gcd is recognized
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <unordered_map>
#include <cstring>
#include <climits>
#include <iomanip>
#include <numeric>
#include <map>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
const int MODD = 32768;
const int MOD = 1e9 + 7;
ll poww(int x, int n, int m)
{
    if (n == 0) return 1;
    ll u = poww(x, n / 2, m);
    u = (u * u) % m;
    if (n & 1) u = (u * x) % m;
    return u;
}
int fact(int n)
{
      if(n==0)
      return 1;
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = (res * i) % MOD;
    return res;
}
long nCr(int n, int r)
{
    return (poww(fact(n) / (fact(r) * fact(n - r)), MOD -1 , MOD));
}



void solve() {
  
    int n; cin >> n;
    int k; cin >> k;
    
    map<int, int> freq;
    for (int i = 0; i < n;i++)
    {
        int temp; cin >> temp;
        freq[temp]++;
    }
    int max_freq = 0;
    int total_freq = freq.size();
    for (auto &it: freq)
    {
        if (it.second <= k)
        {
            total_freq--;
            k -= it.second;
        }
    }
    cout << max(total_freq, 1);
    label: cout << endl;
    
}
int main() {
    fast;
    int t = 1;
   cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

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

using namespace std;



#define int long long



int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    int tt; 

    cin >> tt;

    while(tt--) {   

        int n, x, y; 

        cin >> n >> x >> y;

        x--, y--;

        

        vector<int> a(n);

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

            a[i] = (i & 1);

        }

        

        if(n & 1) {

            a[n - 1] = 2;

        }

        

        if (abs(x - y) != 1 && !(x == 0 && y == n - 1) && (a[x] == a[y])) {

            if (x == 0 || x == n - 2) {

                a[y] = 2;

            } else {

                a[x] = 2;

            }

        }

     

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

            cout << a[i] << " \n"[i == n - 1];

        }

    }

    return 0;

}

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

using namespace std;



#define int long long



int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    int tt; 

    cin >> tt;

    while(tt--) {   

        int n, x, y; 

        cin >> n >> x >> y;

        x--, y--;

        

        vector<int> a(n);

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

            a[i] = (i & 1);

        }

        

        if(n & 1) {

            a[n - 1] = 2;

        }

        

        if (abs(x - y) != 1 && !(x == 0 && y == n - 1) && (a[x] == a[y])) {

            if (x == 0 || x == n - 2) {

                a[y] = 2;

            } else {

                a[x] = 2;

            }

        }

        

        if (n & 1) {

            rotate(a.begin(), a.begin() + n - 1 - x, a.end());

        }

     

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

            cout << a[i] << " \n"[i == n - 1];

        }

    }

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)


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

using namespace std;



#define int long long



int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    int tt; 

    cin >> tt;

    while(tt--) {   

        int n, x, y; 

        cin >> n >> x >> y;

        x--, y--;

        

        vector<int> a(n);

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

            a[i] = (i & 1);

        }

        

        if(n & 1) {

            a[n - 1] = 2;

        }

        

        if (abs(x - y) != 1 && !(x == 0 && y == n - 1) && (a[x] == a[y])) {

            if (x == 0 || x == n - 2) {

                a[y] = 2;

            } else {

                a[x] = 2;

            }

        }

     

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

            cout << a[i] << " \n"[i == n - 1];

        }

    }

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

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

using namespace std;



#define int long long



int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    int tt; 

    cin >> tt;

    while(tt--) {   

        int n, x, y; 

        cin >> n >> x >> y;

        x--, y--;

        

        vector<int> a(n);

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

            a[i] = (i & 1);

        }

        

        if(n & 1) {

            a[n - 1] = 2;

        }

        

        if ((n % 2 == 0) && (abs(x - y) != 1) && !(x == 0 && y == n - 1) && (a[x] == a[y])) {

            if (x == 0 || x == n - 2) {

                a[y] = 2;

            } else {

                a[x] = 2;

            }

        }

     

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

            cout << a[i] << " \n"[i == n - 1];

        }

    }

    return 0;

}

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

using namespace std;



#define int long long



int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    int tt; 

    cin >> tt;

    while(tt--) {   

        int n, x, y; 

        cin >> n >> x >> y;

        x--, y--;

        

        vector<int> a(n);

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

            a[i] = (i & 1);

        }

        

        if(n & 1) {

            a[n - 1] = 2;

        }

        

        if ((n % 2 == 0) && (abs(x - y) != 1) && !(x == 0 && y == n - 1) && (a[x] == a[y])) {

            if (x == 0 || x == n - 2) {

                a[y] = 2;

            } else {

                a[x] = 2;

            }

        }

        

        if (n & 1) {

            rotate(a.begin(), a.begin() + n - 1 - x, a.end());

        }

     

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

            cout << a[i] << " \n"[i == n - 1];

        }

    }

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

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

using namespace std;



#define int long long



int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    int tt; 

    cin >> tt;

    while(tt--) {   

        int n, x, y; 

        cin >> n >> x >> y;

        x--, y--;

        

        vector<int> a(n);

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

            a[i] = (i & 1);

        }

        

        if(n & 1) {

            a[n - 1] = 2;

        }

        

        if (abs(x - y) != 1 && !(x == 0 && y == n - 1) && (a[x] == a[y])) {

            if (x == 0 || x == n - 2) {

                a[y] = 2;

            } else {

                a[x] = 2;

            }

        }

        

        if (n & 1) {

            rotate(a.begin(), a.begin() + n - 1 - x, a.end());

        }

     

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

            cout << a[i] << " \n"[i == n - 1];

        }

    }

    return 0;

}

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

using namespace std;



#define int long long



int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    int tt; 

    cin >> tt;

    while(tt--) {   

        int n, x, y; 

        cin >> n >> x >> y;

        x--, y--;

        

        vector<int> a(n);

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

            a[i] = (i & 1);

        }

        

        if(n & 1) {

            a[n - 1] = 2;

        }

        

        if ((n % 2 == 0) && (abs(x - y) != 1) && !(x == 0 && y == n - 1) && (a[x] == a[y])) {

            if (x == 0 || x == n - 2) {

                a[y] = 2;

            } else {

                a[x] = 2;

            }

        }

     

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

            cout << a[i] << " \n"[i == n - 1];

        }

    }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


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

using namespace std;

 

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}


//---------------------------------------------------------------------------------------------------------------------------------\


void solve(){
     int n,l,r;
     cin>>n>>l>>r;
     vector<ll>a ;
       vector<ll>b;
     for(int i=1;i<=n;i++){
        int x;
        cin>>x;  
        if(i<l || i>r){
            b.push_back(x);
        }
        else{
            a.push_back(x);
        }
     }
     sort(all (a),greater<int>());
     sort(all(b));
     b.push_back(INF);
     debug(a);
     debug(b);
     ll m=sz(a);
     ll low=0;
     ll sum=0;
     for(int i=0;i<m;i++){
         if(a[i]>b[low]){
           sum+=b[low];
           low++;
         }
         else{
            sum+=a[i];
         }
     }
     cout<<sum<<endl;

}


//=====================================================================================================================================//
int main() {
#ifndef ONLINE_JUDGE
    freopen("error.txt", "w", stderr);
#endif
    fastio();
    int t;
  cin >> t;
  while (t--) {
     solve();
 }


}