ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 5):
#include<bits/stdc++.h>
using namespace std;
#define int long long int

signed main(){
    int tc;
    cin>>tc;
    while(tc--){
        int n;
        cin>>n;
        map<int,map<int,int>> map1;
        map<int,int> map2;
        for(int i=1;i<n;i++){
            int u,v;
            cin>>u>>v;
            map1[u][v]=1;
            map1[v][u]=1;
            map2[u]++;map2[v]++;
            
        }
        int res=0;
        for(int i=1;i<=n;i++){
            // delete this one
            int u=i;
            map<int,int> temp=map1[u];
            int ans=map2[u];
            map1[u].clear();
            map2.erase(u);
            for(auto x : temp){
                map1[x.first].erase(u);
                map2[x.first]--;
            }
            int maxi2=0;
            for(auto x : map2){
                maxi2=max(maxi2,x.second);
            }
            res=max(res,ans+(maxi2-1));
            map1[u]=temp;
            map2[u]=ans;
            for(auto x : temp){
                map1[x.first][u]=1;
                map2[x.first]++;
            }
        }
        cout<<res<<endl;
    }
    return 0;
}

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

signed main(){
    int tc;
    cin>>tc;
    while(tc--){
        int n;
        cin>>n;
        map<int,map<int,int>> map1;
        map<int,int> map2;
        int maxi=0;
        for(int i=1;i<n;i++){
            int u,v;
            cin>>u>>v;
            map1[u][v]=1;
            map1[v][u]=1;
            map2[u]++;map2[v]++;
        }
        map<int,int> freq;
        for(auto x : map2){
            freq[x.second]++;
        }
        int res=0;
        for(int i=1;i<=n;i++){
            // delete this one
            int u=i;
            int ans=map2[u];
            freq[ans]--;
            if(freq[ans]==0){
                freq.erase(ans);
            }
            for(auto x : map1[u]){
                freq[map2[x.first]]--;
                freq[map2[x.first]-1]++;
                if(freq[map2[x.first]]==0){
                    freq.erase(map2[x.first]);
                }
            }
            int maxi2=freq.rbegin()->first;
            res=max(res,ans+(maxi2-1));
            freq[ans]++;
            for(auto x : map1[u]){
                freq[map2[x.first]]++;
                freq[map2[x.first]-1]--;
                if(freq[map2[x.first]-1]==0){
                    freq.erase(map2[x.first]-1);
                }
            }
        }
        cout<<res<<endl;
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
# include <vector>
# include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int t;
    cin>>t;
    for (int i=0;i<t;i++){
        long long n;
        long long count1=0;
        long long sum=0;
        vector<long long>v;
        vector<long long>v1;
        cin>>n;
        while(n!=0){
            count1=count1+n%10;
            v.push_back(n%10);
            n=n/10;
        }
        if(count1%9==0){
            cout<<"YES"<<endl;
        }else{
            //cout<<count1<<endl;
            long long p=count1%9;
            long long req=9-p;
            long long a=count(v.begin(),v.end(),2);
            long long b=count(v.begin(),v.end(),3);
            if(req%2==0){
                if(req==2 && a>0){
                    cout<<"YES"<<endl;
                }else if(req==4 && a>1){
                    cout<<"YES"<<endl;
                }else if(req==6 && a>2){
                    cout<<"YES"<<endl;
                }else if(req==8 && a>3){
                    cout<<"YES"<<endl;
                }else if(req==6 && b>0){
                    cout<<"YES"<<endl;
                }else if (req==8){
                    if(b>0 && a>0){
                        cout<<"YES"<<endl;
                    }else{
                        cout<<"NO"<<endl;
                    }
                }else{
                    cout<<"NO"<<endl;
                }
            }else{
                req=req+9;
                if(req==10){
                    if(a>4 || (a>1 && b>0)){
                        cout<<"YES"<<endl;
                    }else{
                        cout<<"NO"<<endl;
                    }
                }else if(req==12){
                    if(a>5 || b>1){
                        cout<<"YES"<<endl;
                    }else if(a>2 && b>0){
                        cout<<"YES"<<endl;
                    }else{
                        cout<<"NO"<<endl;
                    }
                }else if(req==14){
                    if(a>6){
                        cout<<"YES"<<endl;
                    }else if(b>0 && a>3){
                        cout<<"YES"<<endl;
                    }else if(b>1 && a>0){
                        cout<<"YES"<<endl;
                    }else{
                        cout<<"NO"<<endl;
                    }
                }else if(req==16){
                    if(a>7){
                        cout<<"YES"<<endl;
                    }else if(a>4 && b>0){
                        cout<<"YES"<<endl;
                    }else if(b>1 && a>1){
                        cout<<"YES"<<endl;
                    }else{
                        cout<<"NO"<<endl;
                    }
                }
            }
            
            
        }
    }

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

Previous submission (verdict: Wrong answer on test 3):
# include <vector>
# include <algorithm>
#include <iostream>
using namespace std;
int main() {
    long long t;
    cin>>t;
    for (long long i=0;i<t;i++){
        long long n;
        long long count1=0;
        long long sum=0;
        long long a=0;
        long long b=0;
        vector<long long>v;
        
        cin>>n;
        while(n!=0){
            count1=count1+n%10;
            if(n%10==2){
                a++;
            }else if(n%10==3){
                b++;
            }
            n=n/10;
        }
        if(count1%9==0){
            cout<<"YES"<<endl;
        }else{
          for(int i=0;i<=a;i++){
              for(int j=0;j<=b;j++){
                  if((count1+2*i+6*j)%9==0){
                      sum++;
                      break;
                  }
              }
          
            }
            
            if(sum>0){
                cout<<"YES"<<endl;
            }else{
                cout<<"NO"<<endl;
            }
        }
    }

    return 0;
}

Submission (verdict: Wrong answer on test 3):
# include <vector>
# include <algorithm>
#include <iostream>
using namespace std;
int main() {
    long long t;
    cin>>t;
    for (long long i=0;i<t;i++){
        long long n;
        long long count1=0;
        long long sum=0;
        long long a=0;
        long long b=0;
        vector<long long>v;
        
        cin>>n;
        while(n!=0){
            count1=count1+n%10;
            if(n%10==2){
                a++;
            }else if(n%10==3){
                b++;
            }
            n=n/10;
        }
        
        
          for(int i=0;i<=a;i++){
              for(int j=0;j<=b;j++){
                  if((count1+2*i+6*j)%9==0){
                      sum++;
                      break;
                  }
              }
          
            }
            
            if(sum>0){
                cout<<"YES"<<endl;
            }else{
                cout<<"NO"<<endl;
            }
        
    }

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

Previous submission (verdict: Wrong answer on test 3):
# include <vector>
# include <algorithm>
#include <iostream>
using namespace std;
int main() {
    long long t;
    cin>>t;
    for (long long i=0;i<t;i++){
        long long n;
        long long count1=0;
        long long sum=0;
        long long a=0;
        long long b=0;
        vector<long long>v;
        
        cin>>n;
        while(n!=0){
            count1=count1+n%10;
            if(n%10==2){
                a++;
            }else if(n%10==3){
                b++;
            }
            n=n/10;
        }
        
        
          for(int i=0;i<=a;i++){
              for(int j=0;j<=b;j++){
                  if((count1+2*i+6*j)%9==0){
                      sum++;
                      break;
                  }
              }
          
            }
            
            if(sum>0){
                cout<<"YES"<<endl;
            }else{
                cout<<"NO"<<endl;
            }
        
    }

    return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <string>
using namespace std;

int main() {
    long long t;
    cin >> t;
    while (t--) {
        string n;
        cin >> n;

        long long count1 = 0, a = 0, b = 0;
        for (char digit : n) {
            count1 += digit - '0';
            if (digit == '2') a++;
            if (digit == '3') b++;
        }

        bool found = false;
        for (int i = 0; i <= a && !found; i++) {
            for (int j = 0; j <= b; j++) {
                if ((count1 + 2 * i + 6 * j) % 9 == 0) {
                    found = true;
                    break;
                }
            }
        }

        cout << (found ? "YES" : "NO") << endl;
    }

    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

using namespace std;



#define int long long int

#define F first

#define S second

#define pb push_back

#define si set<int>

#define vi vector<int>

#define pii pair<int, int>

#define vpi vector<pii>

#define vpp vector<pair<int, pii>>

#define mii map<int, int>

#define mpi map<pii, int>

#define spi set<pii>

#define endl "\n"

#define sz(x) ((int)x.size())

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

#define double long double

#define que_max priority_queue<int>

#define que_min priority_queue<int, vi, greater<int>>

#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)

#define print(a) for (auto x : a) cout << x << " "; cout << endl

#define print1(a) for (auto x : a) cout << x.F << " " << x.S << endl

#define print2(a, x, y) for (int i = x; i < y; i++) cout << a[i] << " "; cout << endl



inline int power(int a, int b) {

    int x = 1;

    while (b) {

        if (b & 1) x *= a;

        a *= a;

        b >>= 1;

    }

    return x;

}



template <typename Arg1>

void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; }

template <typename Arg1, typename... Args>

void __f(const char *names, Arg1 &&arg1, Args &&...args) {

    const char *comma = strchr(names + 1, ',');

    cout.write(names, comma - names) << " : " << arg1 << " | ";

    __f(comma + 1, args...);

}



const int N = 200005;



void solve() {

    int n,l,r;

    cin>>n>>l>>r;

    vi v(n);

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

        cin>>v[i];

    }



    vi v1, v2;

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

        v1.push_back(v[i]);

    }

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



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

        v2.push_back(v[i]);

    }



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

        v2.push_back(v[i]);

    }



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

    int sum = 0;

    if(v2.size() == 0){

        for(int i=0;i<v1.size();i++){

             sum+=v1[i];

        }



        cout<<sum<<endl;

        return;

    }else{

        int i=0, j=v1.size()-1;

         while(i<v2.size() && j >=0){

            if(v2[i] < v1[j]){

                swap(v1[j], v2[i]);

                i++, j--;

            }else{

                break;

            }

         }



         for(int i=0;i<v1.size();i++){

            sum+=v1[i];

         }



         cout<<sum<<endl;

         

    }



}



int32_t main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



#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: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define ll              long long 
#define pb              push_back
#define all(v)          v.begin(),v.end()
#define sz(a)           (ll)a.size()
#define F               first
#define S               second
#define INF             2000000000000000000
#define popcount(x)     __builtin_popcountll(x)
#define pll             pair<ll,ll>
#define pii             pair<int,int>
#define ld              long double
#define fr(i, y, z)     for (ll i = y; i < z; i++)
#define yes             cout<<"YES"<<endl
#define no              cout<<"NO"<<endl

ll solve(string a,string b,string c,ll i,ll j,vector<vector<ll>>&dp){
  if(i==a.size() && j==b.size()) return 0;

  if(dp[i][j]!=-1)return dp[i][j];
  ll k=i+j;
  ll x=1e5;

  ll v=i<a.size()?solve(a,b,c,i+1,j,dp):1e5,w=j<b.size()?solve(a,b,c,i,j+1,dp):1e5;
  ll cv =min(v,w);
  if(a[i]==c[k] && b[j]==c[k]) x=cv;
  else if(a[i]==c[k]){
    x=min(v,1+w);
  } 
  else if(b[j]==c[k]){
    x=min(1+v,w);
  } 
  else {
   x=1+cv;
  }
  return dp[i][j]=x;
}

int main()
{
    long long t;
    cin>>t;
   
    for(long long i=0;i<t;i++)
    {
      
   string a,b,c;
   cin>>a>>b>>c;
   ll n=a.size(),m=b.size();
   vector<vector<ll>>dp(n+1,vector<ll>(m+1,-1));
   cout<<solve(a,b,c,0,0,dp)<<endl;
    }
    return 0;
}


Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define ll              long long 
#define pb              push_back
#define all(v)          v.begin(),v.end()
#define sz(a)           (ll)a.size()
#define F               first
#define S               second
#define INF             2000000000000000000
#define popcount(x)     __builtin_popcountll(x)
#define pll             pair<ll,ll>
#define pii             pair<int,int>
#define ld              long double
#define fr(i, y, z)     for (ll i = y; i < z; i++)
#define yes             cout<<"YES"<<endl
#define no              cout<<"NO"<<endl

ll solve(string a,string b,string c,ll i,ll j,vector<vector<ll>>&dp){
  if(i==a.size() && j==b.size()) return 0;

  if(dp[i][j]!=-1)return dp[i][j];
  
  ll k=i+j;

  ll v=i<a.size()?solve(a,b,c,i+1,j,dp):1e5,w=j<b.size()?solve(a,b,c,i,j+1,dp):1e5;
  ll cv =min(v,w);
  
  if(a[i]==c[k] && b[j]==c[k]) return dp[i][j]=cv;
  else if(a[i]==c[k]){
    return dp[i][j]=min(v,1+w);
  } 
  else if(b[j]==c[k]){
    return dp[i][j]=min(1+v,w);
  } 
  else {
   return dp[i][j]=1+cv;
  }
}

int main()
{
    long long t;
    cin>>t;
   
    for(long long i=0;i<t;i++)
    {
      
   string a,b,c;
   cin>>a>>b>>c;
   ll n=a.size(),m=b.size();
   vector<vector<ll>>dp(n+1,vector<ll>(m+1,-1));
   cout<<solve(a,b,c,0,0,dp)<<endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define ll              long long 
#define pb              push_back
#define all(v)          v.begin(),v.end()
#define sz(a)           (ll)a.size()
#define F               first
#define S               second
#define INF             2000000000000000000
#define popcount(x)     __builtin_popcountll(x)
#define pll             pair<ll,ll>
#define pii             pair<int,int>
#define ld              long double
#define fr(i, y, z)     for (ll i = y; i < z; i++)
#define yes             cout<<"YES"<<endl
#define no              cout<<"NO"<<endl

ll solve(string a,string b,string c,ll i,ll j,vector<vector<ll>>&dp){
  if(i==a.size() && j==b.size()) return 0;

  if(dp[i][j]!=-1)return dp[i][j];
  ll k=i+j;
  ll x=1e5;

  ll v=i<a.size()?solve(a,b,c,i+1,j,dp):1e5,w=j<b.size()?solve(a,b,c,i,j+1,dp):1e5;
  ll cv =min(v,w);
  if(a[i]==c[k] && b[j]==c[k]) x=cv;
  else if(a[i]==c[k]){
    x=min(v,1+w);
  } 
  else if(b[j]==c[k]){
    x=min(1+v,w);
  } 
  else {
   x=1+cv;
  }
  return dp[i][j]=x;
}

int main()
{
    long long t;
    cin>>t;
   
    for(long long i=0;i<t;i++)
    {
      
   string a,b,c;
   cin>>a>>b>>c;
   ll n=a.size(),m=b.size();
   vector<vector<ll>>dp(n+1,vector<ll>(m+1,-1));
   cout<<solve(a,b,c,0,0,dp)<<endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define ll              long long 
#define pb              push_back
#define all(v)          v.begin(),v.end()
#define sz(a)           (ll)a.size()
#define F               first
#define S               second
#define INF             2000000000000000000
#define popcount(x)     __builtin_popcountll(x)
#define pll             pair<ll,ll>
#define pii             pair<int,int>
#define ld              long double
#define fr(i, y, z)     for (ll i = y; i < z; i++)
#define yes             cout<<"YES"<<endl
#define no              cout<<"NO"<<endl

ll solve(string a,string b,string c,ll i,ll j,vector<vector<ll>>&dp){
  if(i==a.size() && j==b.size()) return 0;

  if(dp[i][j]!=-1)return dp[i][j];
  
  ll k=i+j;

  ll v=i<a.size()?solve(a,b,c,i+1,j,dp):1e5,w=j<b.size()?solve(a,b,c,i,j+1,dp):1e5;
  char ch1=i<a.size()?a[i]:'#',ch2=j<b.size()?b[j]:'#';
  ll cv =min(v,w);

  if(ch1==c[k] && ch2==c[k]) return dp[i][j]=cv;
  else if(ch1==c[k]){
    return dp[i][j]=min(v,1+w);
  } 
  else if(ch2==c[k]){
    return dp[i][j]=min(1+v,w);
  } 
  else {
   return dp[i][j]=1+cv;
  }
}

int main()
{
    long long t;
    cin>>t;
   
    for(long long i=0;i<t;i++)
    {
      
   string a,b,c;
   cin>>a>>b>>c;
   ll n=a.size(),m=b.size();
   vector<vector<ll>>dp(n+1,vector<ll>(m+1,-1));
   cout<<solve(a,b,c,0,0,dp)<<endl;
    }
    return 0;
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define ll              long long 
#define pb              push_back
#define all(v)          v.begin(),v.end()
#define sz(a)           (ll)a.size()
#define F               first
#define S               second
#define INF             2000000000000000000
#define popcount(x)     __builtin_popcountll(x)
#define pll             pair<ll,ll>
#define pii             pair<int,int>
#define ld              long double
#define fr(i, y, z)     for (ll i = y; i < z; i++)
#define yes             cout<<"YES"<<endl
#define no              cout<<"NO"<<endl



ll solve(string &a,string &b,string &c,ll i,ll j,vector<vector<ll>>&dp){
  if(i==a.size() && j==b.size()) return 0;

  if(dp[i][j]!=-1)return dp[i][j];
  
  ll k=i+j;
  ll x=2010,y=2010;
  
  if(i<a.size()){
    x=(a[i]!=c[k])+solve(a,b,c,i+1,j,dp);
  }
  if(j<b.size()){
    y=(b[j]!=c[k])+solve(a,b,c,i,j+1,dp);
  }
  return dp[i][j]=min(x,y);
}

int main()
{
    long long t;
    cin>>t;
   
    for(long long i=0;i<t;i++)
    {
      
   string a,b,c;
   cin>>a>>b>>c;
   vector<vector<ll>>dp(a.size()+1,vector<ll>(b.size()+1,-1));
   cout<<solve(a,b,c,0,0,dp)<<endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define ll              long long 
#define pb              push_back
#define all(v)          v.begin(),v.end()
#define sz(a)           (ll)a.size()
#define F               first
#define S               second
#define INF             2000000000000000000
#define popcount(x)     __builtin_popcountll(x)
#define pll             pair<ll,ll>
#define pii             pair<int,int>
#define ld              long double
#define fr(i, y, z)     for (ll i = y; i < z; i++)
#define yes             cout<<"YES"<<endl
#define no              cout<<"NO"<<endl

ll solve(string a,string b,string c,ll i,ll j,vector<vector<ll>>&dp){
  if(i==a.size() && j==b.size()) return 0;

  if(dp[i][j]!=-1)return dp[i][j];
  
  ll k=i+j;

  ll v=i<a.size()?solve(a,b,c,i+1,j,dp):1e5,w=j<b.size()?solve(a,b,c,i,j+1,dp):1e5;
  ll cv =min(v,w);
  
  if(a[i]==c[k] && b[j]==c[k]) return dp[i][j]=cv;
  else if(a[i]==c[k]){
    return dp[i][j]=min(v,1+w);
  } 
  else if(b[j]==c[k]){
    return dp[i][j]=min(1+v,w);
  } 
  else {
   return dp[i][j]=1+cv;
  }
}

int main()
{
    long long t;
    cin>>t;
   
    for(long long i=0;i<t;i++)
    {
      
   string a,b,c;
   cin>>a>>b>>c;
   ll n=a.size(),m=b.size();
   vector<vector<ll>>dp(n+1,vector<ll>(m+1,-1));
   cout<<solve(a,b,c,0,0,dp)<<endl;
    }
    return 0;
}


Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define ll              long long 
#define pb              push_back
#define all(v)          v.begin(),v.end()
#define sz(a)           (ll)a.size()
#define F               first
#define S               second
#define INF             2000000000000000000
#define popcount(x)     __builtin_popcountll(x)
#define pll             pair<ll,ll>
#define pii             pair<int,int>
#define ld              long double
#define fr(i, y, z)     for (ll i = y; i < z; i++)
#define yes             cout<<"YES"<<endl
#define no              cout<<"NO"<<endl

ll solve(string a,string b,string c,ll i,ll j,vector<vector<ll>>&dp){
  if(i==a.size() && j==b.size()) return 0;

  if(dp[i][j]!=-1)return dp[i][j];
  
  ll k=i+j;

  ll v=i<a.size()?solve(a,b,c,i+1,j,dp):1e5,w=j<b.size()?solve(a,b,c,i,j+1,dp):1e5;
  char ch1=i<a.size()?a[i]:'#',ch2=j<b.size()?b[j]:'#';
  ll cv =min(v,w);

  if(ch1==c[k] && ch2==c[k]) return dp[i][j]=cv;
  else if(ch1==c[k]){
    return dp[i][j]=min(v,1+w);
  } 
  else if(ch2==c[k]){
    return dp[i][j]=min(1+v,w);
  } 
  else {
   return dp[i][j]=1+cv;
  }
}

int main()
{
    long long t;
    cin>>t;
   
    for(long long i=0;i<t;i++)
    {
      
   string a,b,c;
   cin>>a>>b>>c;
   ll n=a.size(),m=b.size();
   vector<vector<ll>>dp(n+1,vector<ll>(m+1,-1));
   cout<<solve(a,b,c,0,0,dp)<<endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ll t;
cin>>t;
while(t--){
    ll n,l,r;
    cin>>n>>l>>r;
     ll cnt=r-l+1;
    ll a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    ll sum=0;
    if(l==1 or r==n){
        for(int i=0;i<cnt;i++){
            sum+=b[i];
        }
        cout<<sum<<endl;
    }
    else{
            ll mn=b[cnt-1],cnt1=0,cnt2=0;
            ll lf[r];
        for(int i=0;i<r;i++){
            lf[i]=a[i];
        }
    ll rf[n-l+1];
    for(int i=l-1;i<n;i++){
        rf[i-l]=a[i];
    }
    sort(lf,lf+r);
    sort(rf,rf+n-l+1);
    for(int i=0;i<r;i++){
        if(lf[i]<=mn) cnt1++;
        else break;
    }
    for(int i=0;i<n-l+1;i++){
        if(rf[i]<=mn) cnt2++;
        else break;
    }
    if(cnt1>=cnt2){
        for(int i=0;i<cnt;i++){
            sum+=lf[i];
        }
        cout<<sum<<endl;
    }
    else{
        for(int i=0;i<cnt;i++){
            sum+=rf[i];
        }
        cout<<sum<<endl;
    }
    }
}
}


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

#define ll long long

using namespace std;

int main(){

ll t;

cin>>t;

while(t--){

    ll n,l,r;

    cin>>n>>l>>r;

     ll cnt=r-l+1;

    ll a[n],b[n];

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

        cin>>a[i];

        b[i]=a[i];

    }

    sort(b,b+n);

    ll sum=0;

    if(l==1 or r==n){

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

            sum+=b[i];

        }

        cout<<sum<<endl;

    }

    else{

            ll mn=b[cnt-1],cnt1=0,cnt2=0;

            ll lf[r];

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

            lf[i]=a[i];

        }

        ll p=n-l+1,o=0;

    ll rf[p];

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

        rf[o]=a[i];

        o++;

    }

    sort(lf,lf+r);

    sort(rf,rf+n-l+1);

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

        if(lf[i]<=mn) cnt1++;

        else break;

    }

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

        if(rf[i]<=mn) cnt2++;

        else break;

    }

    if(cnt1>=cnt2){

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

            sum+=lf[i];

        }

        cout<<sum<<endl;

    }

    else{

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

            sum+=rf[i];

        }

        cout<<sum<<endl;

    }

    }

}

}