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

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
#include<cstdio>
#include<time.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef long double Ld;
typedef pair<char,char> PII;
int dp[1010][1010];

void solve(){
	string a,b;
	cin>>a>>b;
	int n=a.size();
	int m=b.size();
	a=" "+a;
	b=" "+b;
	string c;
	cin>>c;
	c=" "+c;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			dp[i][j]=0;
		}
	}
	for(int i=1;i<=n;i++){
		dp[i][0]=max(dp[i][0],dp[i-1][0]+(a[i]==c[i]));
	}
	for(int i=1;i<=m;i++){
		dp[0][i]=max(dp[0][i],dp[0][i-1]+(b[i]==c[i]));
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i][j]=max(dp[i-1][j]+(a[i]==c[i+j]),dp[i][j-1]+(b[j]==c[i+j]));
		}
	}	
	cout<<n+m-dp[n][m]<<endl;
} 


int main(){
	srand((unsigned)time(NULL));
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout<<fixed<<setprecision(6)
    int t=1;
    cin>>t;
    while(t--){ 
    	solve();
    }
    return 0;
}

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

// Recursive function with a 2D DP table
int solve(int i, int j, const string &a, const string &b, const string &c, vector<vector<int>> &dp) {
    int k = i + j; // Index in c
    if (k == c.size()) return 0; // Base case: all characters of c are processed

    if (dp[i][j] != -1) return dp[i][j]; // Return already computed value

    int changes = 1e9;

    // Option 1: Take from string a
    if (i < a.size()) {
        int ch = (a[i] != c[k]) ? 1 : 0; // Increment change if character doesn't match
        changes = solve(i + 1, j, a, b, c, dp) + ch;
    }

    // Option 2: Take from string b
    if (j < b.size()) {
        int ch = (b[j] != c[k]) ? 1 : 0; // Increment change if character doesn't match
        changes = min(changes, solve(i, j + 1, a, b, c, dp) + ch);
    }

    return dp[i][j] = changes; // Memoize the result
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;

        int n = a.size(), m = b.size();
        // Initialize a 2D memoization table
        vector<vector<int>> dp(n + 1, vector<int>(m + 1, -1));

        // Start recursive calculation from the beginning of all strings
        cout << solve(0, 0, a, b, c, dp) << endl;
    }
    return 0;
}
Problem: 2050B - Transfusion
Language: c++17 

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


void solv() {
    int n;
    cin>>n;
    vector<int>v(n);
    for(auto &i:v) cin>>i;
    int odd=0, even=0, sum = 0;
    for(int i=0;i<n; i++) {
        if(i%2) odd+=v[i];
        else even+=v[i];
        sum+=v[i];
    }
    if(sum % n != 0) {
        cout << "NO\n";
        return;
    }
    int avg = sum / n;
    if(n%2) {
        if(even / ((n+1)/2) == avg && odd / (n/2) == avg) {
            cout<<"YES\n";
        }else cout<< "NO\n";
    }else {
        if(even / (n/2) == avg && odd / (n/2) == avg) {
            cout<<"YES\n";
        }else cout<< "NO\n";
    }
}


int32_t main() {
    int t=1;
    cin >> t;
    while (t--) {
        solv();
    }
    return 0;
}


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



using namespace std;



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t;

    cin>>t;

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

        long long n,k1=0,k2=0,s1=0,s2=0;

        cin>>n;

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

            int a;

            cin>>a;

            if(i%2==1){k1++;s1+=a;}

            else{k2++;s2+=a;}

        }

        if(s1%k1!=0 || s2%k2!=0){cout<<"NO"<<'\n';}

        else if(s1/k1==s2/k2){cout<<"YES"<<'\n';}

        else{cout<<"NO"<<'\n';}

    }

    return 0;

}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 1203 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int main(){
    fast
    ll n;cin>>n;
    vector<ll>v;
    set<ll>s;
    for (int i = 0; i < n; i++)
    {
        ll a;cin>>a;
        v.push_back(a);
        s.insert(a);
    }
    vector<pair<ll,ll>>v1;

    for (int i = n-1; i >=1; i--)
    {
        for (int j = v[i]-1; j >=1; j--)
        {
            auto it = s.find(j);
            if (it != s.end())
            {
                v1.push_back({v[i], j});
            }
            
        }
        for (int j = 1; j <=v[i]-1; j++)
        {
             auto it = s.find(j);
            if (it != s.end())
            {
                v1.push_back({j , v[i]});
            }
            
        }
        for (int j = v[i]+1; j <= n; j++)
        {
            auto it = s.find(j);
            if (it != s.end())
            {
                v1.push_back({j, v[i]});
            }
            
        }
        s.erase(v[i]);
        
    }
    
    cout<<v1.size()<<endl;
    for(auto value:v1){
        cout<<value.first<<" "<<value.second<<endl;
    }
}

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

bool _t(const char &cc) {return cc=='-' || (cc<='9' && cc>='0');}

template <typename Tp> 
void read(Tp &a) {
    a=0;char c;bool flg=false;
    while(!_t(c=getchar())) ;
    if(c=='-') flg=true,c=getchar();
    while(_t(c) && c!='-') {a=a*10+(c-'0');c=getchar();}
    if(flg) a=-a;
}

int wstk[45]={},wtp;
template <typename Tp>
void write(Tp a) {
    if(!a) {putchar('0');return ;}
    if(a<0) {putchar('-');a=-a;}
    while(a) {wstk[++wtp]=a%10;a/=10;} 
    while(wtp) {putchar(wstk[wtp]+'0');--wtp;}
}

template <typename Tp> 
void writeln(const Tp a) {write(a);putchar(10);}

int n;
int a[1005];
typedef pair<int,int> pii;
vector<pii> ans;
bool used[1005][1005];

void wk() {
    read(n);
    for(int i=1;i<=n;++i) read(a[i]);
    int cc=0;
    for(int i=1;i<=n;++i) {
        for(int j=i+1;j<=n;++j) {
            if(a[i]>a[j]) used[a[j]][a[i]]=true;
        }
    }
    for(int i=1;i<=n;++i) a[i]=i;
    for(int p=1;p<=n;++p) {
        for(int i=1;i<n;++i) {
            if(!used[a[i+1]][a[i]]) {
                ans.push_back((pii){a[i+1],a[i]});
                used[a[i+1]][a[i]]=true;
                swap(a[i],a[i+1]);
            }
        }
    }
    writeln((int)ans.size());
    for(auto [x,y]:ans) write(x),putchar(32),writeln(y);
}

signed main() {
    wk();

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

Solution 1 (runtime: 46 ms):
/* In the Name of ALLAH */
/** Minhaz Uddin
   Dept of CSE,Comilla University*/

#include<bits/stdc++.h>
#define ll long long
#define yes cout<<"YES"<<'\n';
#define no cout<<"NO"<<'\n';
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define tst int t;cin>>t;while(t--)
#define pb push_back
#define rvs reverse(v.begin(),v.end())
#define srt sort(v.begin(),v.end())

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const ll  N = 1e7+9;

void solve()
{
string s;
cin>>s;
ll n,i,j, sum = 0, c2 = 0, c3 = 0;
for(i = 0;i<s.size();i++)
{
    sum+=s[i]-'0';
    if(s[i]=='2')c2++;
    else if(s[i]=='3')c3++;
}
if(sum%9==0)yes
else
{
    ll mod =9- (sum%9);
    if(mod%2==1)mod+=9;
    while(mod-6>=0 && c3>0)
    {
        mod-=6;
        c3--;
    }
    while(mod-2>=0 && c2>0)
    {
        mod-=2;
        c2--;
    }
    if(mod==0)yes
    else no
}
}



int main()
{
optimize();
tst{
solve();
}
return 0;
}


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

void solve() {
    string s;
    cin >> s;
    long long sum = 0;
    long long twos = 0;
    long long threes = 0;
    for(char c : s) {
        sum += c - '0';
        if((c - '0') == 2)
            twos++;
        if((c - '0') == 3)
            threes++;
    }
    for(int i = 0; i <= (twos < 9 ? twos : 9); i++) {
        for(int j = 0; j <= (threes < 9 ? threes : 9); j++) {
            if((sum + (2 * i) + (6 * j)) % 9 == 0) {
                cout << "YES" << '\n';
                return;
            }
        }
    }
    cout << "NO" << '\n';
}

int main() {
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

using namespace std;

typedef long long ll;

int n, m;



void solve()

{

    int n;

    cin >> n;

    vector<int> v(n);

    for (auto &x : v)

        cin >> x;



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

    {

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

        {

            cout << "NO\n";

            return;

        }

        else if (v[i] <= v[i + 1])

        {

            v[i + 1] = v[i + 1] - v[i];

        }

    }

    cout << "YES\n";

}

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        solve();

    }



    return 0;

}

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

using namespace std;

//#define int long long

#define ll long long

#define mp make_pair

#define push_b push_back

#define push_f push_front

#define pop_f pop_front

#define pop_b pop_back

#define sec second

#define fir first

#pragma GCC 03



const int inf = 1e9 + 7;



signed main() {



ios::sync_with_stdio(0);

cout.tie(0);

cin.tie(0);



int t; cin >> t;

while (t--) {



int n; cin >> n;

vector<int> a(n, inf);

bool ans = true;



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



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

if (a[i] <= a[i + 1]) {

a[i + 1] = a[i + 1] - a[i];

a[i] = 0;

}

}



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

if (a[i] > a[i + 1]) ans = false;

}



cout << (ans ? "YES" : "NO") << endl;



}



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

Solution 1 (runtime: 202 ms):
#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;

    }

    ll sum1=0,sum2=0;



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

            sum1+=lf[i];

        }







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

            sum2+=rf[i];

        }



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



    }

}

}



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

using namespace std;



void solve() {

    int n, l, r;

    cin >> n >> l >> r;

    vector<int> arr(n);

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

        cin >> arr[i];

    }

    

    vector<int> prefix(arr.begin(), arr.begin() + r);

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

    long long sum1 = 0;

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

        sum1 += prefix[i];

    }

    

    vector<int> suffix(arr.begin() + l - 1, arr.end());

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

    long long sum2 = 0;

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

        sum2 += suffix[i];

    }

    

    cout << min(sum1, sum2) << "\n";

}



int main() {

ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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

int main(){
    int tc;
    cin >> tc;
    while(tc--){
        int a, b;
        cin >> a>> b;
        
        int f, X = a^b, ff, Y = a|b;
        for(int i=0; i<30; ++i){
            if(X&(1<<i)) f = i;
        }
        
        int x = 1<<f, y = x-1, z = 0;
        for(int i=30; i>f; --i){
            if(a&(1<<i)){
                x += 1<<i;
                y += 1<<i;
            }
        }
        if(b != x && b!=y) z = b;
        else z = a;
        
        cout << x<< " "<< y<< " "<< z<< endl;
    }

    return 0;
}

Solution 2 (runtime: 46 ms):
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)(x).size()
#define LSB(x) (x) & (-x)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int l,r;

void solve() {
	cin>>l>>r;
	int x=l^r,
	    y=31-__builtin_clz(x),
	    a=l|((1<<y)-1),
	    b=a+1,
	    c=(a==l?r:l);

	cout<<a<<' '<<b<<' '<<c<<'\n';
}

int main() {
//	freopen("pails.in", "r", stdin);
//	freopen("pails.out", "w", stdout);
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int t;
	cin>>t;
	while(t--) solve();
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

int sum(vector<int> &a, int n)
{
    int x = 0;
    for (int i = 0; i < n; i++)
    {
        x += abs(a[i]);
    }
    return x;
}

void solve()
{
   int n; cin>>n;
   vector<int>a(n);
   for(int &x : a) cin>>x;
   int g = 0, f = 0;
   for(int i=1;i<n;i++){
        int x = min(a[i],a[i-1]);
        a[i] -= x;
        a[i-1] -= x;
        if(0 == a[i] && a[i-1] != 0) {f = 1; break;}
   }
   if(f==0) cout<<"YES\n";
   else cout<<"NO\n";
}

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


Solution 2 (runtime: 109 ms):
#include<iostream>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define fastread() ios::sync_with_stdio(false); cin.tie(0);
#define ll long long

void solve(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    for (ll c = 0; c < n; c++) {
        cin >> v[c];
    }

    for (ll i = 1; i < n; i++) {
        ll x = min(v[i - 1], v[i]);
        v[i - 1] -= x;
        v[i] -= x;
    }

    bool res = true;
    for (int m = 1; m < n; m++) {
        if (v[m - 1] > v[m]) {
            res = false;
            break;
        }
    }

    cout << (res ? "YES\n" : "NO\n");
}
int main(){
    fastread();
    ll t;
    cin >> t;
    while(t--){
        solve();
    } 
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 46 ms):
# include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int f[N][N];
char a[N], b[N], c[N];
void solve()
{
	cin >> a + 1 >> b + 1 >> c + 1;
	int n = strlen(a + 1), m = strlen(b + 1);
	for(int i = 0; i <= n; i++)
	{
		for(int j = 0; j <= m; j++)
		{
			f[i][j] = N;
		}
	}
	
	for(int i = 0; i <= n; i++)
	{
		for(int j = 0; j <= m; j++)
		{
			if(i + j == 0)
			{
				f[i][j] = 0;
				continue;
			}
			if(i > 0) f[i][j] = min(f[i][j], (c[i + j] != a[i]) + f[i - 1][j]);
			if(j > 0) f[i][j] = min(f[i][j], (c[i + j] != b[j]) + f[i][j - 1]);
		}
	}
	cout << f[n][m] << endl;
}
int main()
{
	int T;
	cin >> T;
	while(T--) solve();
	return 0;
}

Solution 2 (runtime: 62 ms):
/* Truong Nhat Nguyen */



#include <bits/stdc++.h>



#define endl '\n'

#define f0(i, n) for (int i = 0; i < n; ++i)

#define f1(i, n) for (int i = 1; i <= n; ++i)

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

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

#define setpr(x) cout << setprecision(x) << fixed

#define MOD 1000000007

#define ll long long

// #define int long long

const long long INF = 0x3f3f3f3f;

const int MAXN = 1e5 + 5;



using namespace std;

/*

    dp[i][j] là trạng thái chọn vị trí thứ i của chuỗi a

    và thứ j của chuỗi b để ghép thành chuỗi c[i+j]

*/

void solve()

{

    string a,b,c; cin >> a >> b >> c;

    int len1 = sz(a) , len2 = sz(b) , len3 = sz(c);

    vector<vector<int>> dp(len1 + 2,vector<int>(len2 + 2,INF));

    dp[0][0] = 0;

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

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

            if(i < len1) dp[i+1][j] = min(dp[i+1][j],dp[i][j]+(a[i]!=c[i+j]));

            if(j < len2) dp[i][j+1] = min(dp[i][j+1],dp[i][j]+(b[j]!=c[i+j]));

        }

    }

    cout << dp[len1][len2] << endl;

}

int32_t main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int TC;

    cin >> TC;

    while (TC--)

    {

        solve();

    }

}
Problem: 2050E - Three Strings
Language: c++17 

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

#define int long long

const int MAX_N = 2e3+5, INF = 1e9+5;
int dp[MAX_N][MAX_N];

void solve() {
    string a,b,c;
    cin >> a >> b >> c;
    a = " "+a;
    b = " "+b;
    c = " "+c;
    for(int i=0;i<=a.size();i++) {
        for(int j=0;j<=b.size();j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for(int i=0;i<a.size();i++) {
        for(int j=0;j<b.size();j++) {
            if(i) dp[i][j] = min(dp[i][j], dp[i-1][j] + (a[i] != c[i+j]));
            if(j) dp[i][j] = min(dp[i][j], dp[i][j-1] + (b[j] != c[i+j]));
        }
    }
    cout << dp[a.size()-1][b.size()-1] << "\n";
}

signed main() {
    ios::sync_with_stdio(0),cin.tie(0);
    int t=1;
    cin >> t;
    while(t--) solve();
}

Solution 2 (runtime: 62 ms):
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int minChanges(const string& a, const string& b, const string& c) {
    int n = a.size();
    int m = b.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    dp[0][0] = 0;

    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = dp[i][0] + (a[i] != c[i]);
    }

    for (int j = 0; j < m; j++) {
        dp[0][j + 1] = dp[0][j] + (b[j] != c[j]);
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != c[i + j - 1]),
                           dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));
        }
    }

    return dp[n][m];
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        cout << minChanges(a, b, c) << endl;
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
 
ll t;
 
void printArr(vector<int> &a){
    for(int i=0; i<a.size(); i++){
        cout<<a[i]<<" ";
    }
    cout<<'\n';
}


void solve(){

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

    bool flag = false;

    int a=0, b=0, c=0;

    vector<int> av, bv, cv;
    if(r-l+1 == 3){
        cout<<l<<" "<<l+1<<" "<<r<<"\n";
        return;
    }

    int bits = (r > 0) ? (int)(log2(r)) : -1;

    int currB  = 0;
    // cout<<bits<<endl;

    while(bits >= 0 && l!=0) {

        int lbit = ((1 << bits) & l) && 1;
        int rbit = ((1 << bits) & r) && 1;

        if(!(rbit ^ lbit)){
            if(rbit==1){
                a |= (1 << bits);
                b |= (1 << bits);
                c |= (1 << bits);
            }
        }else{
            currB = b;
            break;
        }
        bits--;
    }

    // cout<<bits<<'\n';
    // cout<<a<<endl;
    a |= (1 << bits);
    bits--;

    while(bits >= 0 && ((( 1 << bits ) & l) == 0)){
        b |= (1 << bits);
        bits--;
    }

    while(bits >= 0){
        c |= (1 << bits);
        bits--;
    }

    if(b == currB){
        if(r == a){
            b = l;
        }else{
            b = r;
        }
    }


    cout<< a <<" "<< b << " "<< c <<endl;

    // R  1 0 1 1 1 0 0 => 
    // L  1 0 1 0 0 1 1

    // 1 0 1 1 0
    // 0 0 1 1 0

    // 1 0
    // 0 0

    // 0 1 1 1 1 1 1 1
    // 0 1 1 1 0 0 1 1

    // 0 1 1 1 1 0 0 0
    // 0 1 1 1 0 1 0 0
    // 0 1 1 1 0 0 1 1

    // 0 1 0 0 1 0 0 1
    // 0 1 0 0 0 0 0 0

    // 1 0 0
    // 0 1 1

    // 1 0 1
    // 0 1 0

    // 1 1 0 1
    // 1 0 1 0




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

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

#define ll long long


int main(){
ll t;
cin>>t;
while(t--){
  ll l,r;
  cin>>l>>r;

  ll e;
  ll x=0;
  ll y=0;

  for(ll i=31;i>=0;i--){
    if(((1<<i)&r)!=0 && ((1<<i)&l)==0 ){
        e=i;
        break;
    }
  }

  for(ll i=31; i>e;i--){
    if( ((1<<i) & r)!=0){
        x+= 1<<i;
        y+= 1<<i;
    }
  }

  x+= 1<<e;

  for(int i=e-1;i>=0;i--){
    y+=1<<i;
  }




  ll z;
  for(int i=l;i<=r;i++){
    if(i!=x && i!=y){
        z=i;
        break;
    }
  }

  cout<<z<<" "<<x<<" "<<y<<endl;





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

Solution 1 (runtime: 77 ms):
/// Author : TCK



#include <bits/stdc++.h>



#define fi first

#define se second

#define pb push_back

#define FOR(i, a, b) for (ll i = a; i <= b; i++)

#define FORD(i, a, b) for (ll i = a; i >= b; i--)

#define endl '\n'

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



using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef vector<ll> vi;

typedef pair<ll, ll> pii;

typedef vector<pair<ll, ll>> vpii;

typedef vector<vector<ll>> vvi;

typedef vector<vector<pair<ll, ll>>> vvpii;

typedef pair<char, char> pcc;

typedef vector<vector<vector<ll>>> vvvi;

typedef pair<ll, pii> pip;

typedef vector<char> vc;

typedef vector<bool> vb;

typedef vector<vb> vvb;



const ll INF = 1e18 + 18;

const ll mxn = 1e5 + 5;

const ll mod = 1e9 + 7;

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

const char dir[] = {'D', 'L', 'U', 'R'};



void solve() 

{

    int n; cin >> n;

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

    vi vl, vr, mid;



    ll s = 0;

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

        ll v; cin >> v;

        if (i < l) vl.pb(v);

        else if (i > r) vr.pb(v);

        else {

            mid.pb(v);

            s += v;

        }

    }



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

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

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



    ll ans = s;

    int i = mid.size() - 1;

    int j = 0;

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

        if (vl[j] < mid[i]) {

            ans = ans - mid[i] + vl[j];

        }

        else break;

        j++;

        i--;

    }



    ll ans2 = s;



    i = mid.size() - 1;

    j = 0;

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

        if (vr[j] < mid[i]) {

            ans2 = ans2 - mid[i] + vr[j];

        }

        else break;

        j++;

        i--;

    }



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

}



int main()

{

    faster;



    ll t = 1;

    cin >> t;



    while (t--) {

        solve();

    }



    return 0;

}

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

using namespace std;

#define ll long long

const int mod = 998244353;

typedef pair<ll, ll> Interval;



void solve() {

    int n,l,r;

    cin >> n >> l >> r;

    vector<int> a(n);

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

    vector<int> b,c;

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

        b.push_back(a[i]);

    }

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

        c.push_back(a[i]);

    }

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

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

    ll sum1 = accumulate(b.begin(),b.begin() +(int)(r-l+1) ,0ll);

    ll sum2 = accumulate(c.begin(),c.begin() +(int)(r-l+1) ,0ll);

    cout << min(sum1,sum2) <<"\n";

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int t = 1;

    cin >> t;

    

    while (t--) {

        solve();

    }

    

    return 0;

}