ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
 
long long a[1010];
 
int main(){
	int t;
	cin >> t;
	while (t--){
		int n;
		cin >> n;
		for (int i = 1; i <= n; i++) cin >> a[i];
		int now = n;
		long long ans = -1e18;
		for (int i = 1; i <= n; i++){
			long long sum = 0;
			for (int i = 1; i <= now; i++) sum = (sum + a[i]) ;
			if (i == 1) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]) ;
			now--;
		}
		cout << ans << endl; 
	}
	return 0;
}

Solution 2 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define lep(i,l,r) for(ll i=l;i<=r;++i)
#define rep(i,l,r) for(ll i=l;i>=r;--i)
inline ll read()//如果用long long记得改
{
	ll s=0,w=1; char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') w=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') s=s*10+c-'0',c=getchar();
	return s*w;
}
void write(ll x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10); putchar(x%10+'0');
}
ll T,n,ans,a[100];
signed main()
{
	T=read();
	while(T--)
	{ans=0;
		n=read(); lep(i,1,n) a[i]=read(),ans+=a[i]; 
		if(n>1) 
		{
			lep(k,1,n)
			{
				ans=max(ans,abs(a[n-k+1]-a[1]));
				lep(i,1,n-k) a[i]=a[i+1]-a[i];
			}
		}
		write(ans),putchar(10);
	}
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

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

#define all(A) A.begin(),A.end()
#define fori(i, k, n) for (int i = k; i < n; i++)
#define ln "\n"


vector<unordered_set<int> > adj;
vector<pair<int, int> > deg;
vector<bool> visited;
int n, ans;

void dfs(int u) {
    visited[u] = true;
    for (const auto &v: adj[u])
        if (!visited[v]) {
            ans = max(ans, deg[u].first + deg[v].first - 2);
            dfs(v);
        }
}

bool vecinos(int u, int v) {
    return adj[u].find(v) != adj[u].end();
}


void solve() {
    cin >> n;
    adj.assign(n, unordered_set<int>());
    deg.assign(n, {0, 0});
    visited.assign(n, false);
    fori(i, 0, n)
        deg[i].second = i;
    fori(i, 0, n-1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].insert(b);
        adj[b].insert(a);
        deg[a].first++;
        deg[b].first++;
    }
    ans = 0;
    dfs(0);
    sort(all(deg), greater<pair<int, int> >());
    fori(i, 0, n) {
        fori(j, i+1, n) {
            if (vecinos(deg[i].second, deg[j].second))
                continue;
            ans = max(ans, deg[i].first + deg[j].first - 1);
            break;
        }
    }
    cout << ans << ln;
}

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


Solution 2 (runtime: 249 ms):
#include<bits/stdc++.h>
#define eb emplace_back
#define ll long long
#define w(t) while(t--)
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define iofast ios::sync_with_stdio(0);cin.tie(0);
using namespace std;
vector<int> v[200010],cnt[200010];
bool ch[200010];
void solve(){
	int n,a,b,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cnt[i].clear();
		v[i].clear();
		ch[i]=0;
	}
	for(int i=1;i<n;i++){
		cin>>a>>b;
		v[a].eb(b);
		v[b].eb(a);
	}
	if(n==2){
		cout<<ans<<'\n';
		return;
	}
	for(int i=1;i<=n;i++) cnt[v[i].size()].eb(i);
	int po=n;
	while(!cnt[po].size()) po--;
	if(cnt[po].size()==1){
		for(auto &i:v[cnt[po][0]]) ch[i]=1;
		ans+=po-1;
		po--;
		while(!cnt[po].size()) po--;
		bool cc=0;
		ans+=po-1;
		for(auto &i:cnt[po]){
			if(!ch[i]){
				ans++;
				break;
			}
		}
	}
	else{
		for(auto &i:cnt[po]){
			for(auto &j:v[i]) ch[j]=1;
			for(auto &j:cnt[po]){
				if(i!=j&&!ch[j]){
					ans=po*2-1;
					break;
				}
			}
			if(ans==po*2-1) break;
			for(auto &j:v[i]) ch[j]=0;
		}
		if(!ans) ans=po*2-2;
	}
	cout<<ans<<'\n';
	return;
}
int main(){
	iofast
	int t;
	cin>>t;
	w(t) solve();
	return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

using namespace std;

#define int long long
#define all(x) begin(x), end(x)
#define pb push_back

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

    int n;
    cin >> n;
    vector<int> aa(n);
    for (int &el : aa) {
        cin >> el;
        --el;
    }

    vector<int> a(n);
    iota(all(a), 0);

    vector<pair<int, int>> ans;

    // Bubble sort to reverse sort `a`
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n - 1 - i; ++j) { // Avoid redundant comparisons
            if (a[j] < a[j + 1]) {
                ans.emplace_back(a[j], a[j + 1]);
                swap(a[j], a[j + 1]);
            }
        }
    }

    vector<int> ord(n);
    for (int i = 0; i < n; ++i) {
        ord[aa[i]] = i;
    }

    // Adjust `a` according to `ord` using bubble sort again
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n - 1 - i; ++j) { // Avoid redundant comparisons
            if (ord[a[j]] > ord[a[j + 1]]) {
                ans.emplace_back(a[j], a[j + 1]);
                swap(a[j], a[j + 1]);
            }
        }
    }

    // Output the result
    cout << ans.size() << '\n';
    for (auto &[u, v] : ans) {
        cout << v + 1 << ' ' << u + 1 << '\n';
    }
}

Solution 2 (runtime: 1281 ms):
// Problem: A. Adrenaline Rush
// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred)
// URL: https://codeforces.com/problemset/problem/2052/A
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, long long> pil;
typedef pair<long long, int> pli;

const int M = 1e9+7;
const int N = 2e6 + 10;
int a[N], b[N];
int l[N], r[N];
char g[110][110];
char mapp[110][110];
bool st[110][110];
int n, m;

void solve() {
	cin >> n;
	set<int> S;
	for(int i = 1;i <= n;i ++) {
		cin >> a[i];
		S.insert(i);
	}
	
	vector<pii> ans;
	
	for(int i = n;i >= 1;i --) {
		for(int j = a[i] - 1;j >= 1;j --) {
			if(S.count(j) == 0) continue;
			ans.push_back({a[i], j});
		}
		S.erase(a[i]);
		for(auto t : S) {
			ans.push_back({t, a[i]});
		}
	}
	
	cout << ans.size() << endl;
	for(auto t : ans) {
		cout << t.first << " " << t.second << endl;
	}
}

int main() {
    ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while(t --) {
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 92 ms):
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define ld long double
#define pii pair<int,int>
#define fast_io  ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define peek(v) for(auto x:v) cout<<x<<" ";cout<<"\n";
#define dpeek(v) for(auto i:v) {for(auto j:i){ cout<<j<<" ";} cout<<"\n";}
#define in_range(x, y, r, c) (x >= 0 && x < r && y >= 0 && y < c)
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
//ordered_set s;
//s.order_of_key(key) -> number of elements smaller than key in set
//*s.find_by_order(idx) -> element at index idx in set

int32_t main(){
	fast_io;
	int t;
	cin>>t;
	while(t--){
		string a;
		cin>>a;
		string b;
		cin>>b;
		string c;
		cin>>c;
		int n = a.length();
		int m = b.length();
		vector<vector<int>> dp(n+1, vector<int>(m+1, INT_MAX));
		dp[0][0] = 0;
		for(int j = 1; j<=m; j++){
			dp[0][j] = dp[0][j-1] + (b[j-1]==c[j-1]?0:1);
		}
		for(int i = 1; i<=n; i++){
			dp[i][0] = dp[i-1][0] + (a[i-1]==c[i-1]?0:1);
		}
		for(int i = 1; i<=n; i++){
			for(int j = 1; j<=m; j++){
				if(i>=2){
					dp[i][j] = min(dp[i][j], dp[i-2][j] + (a[i-1 -1]==c[i+j -2]?0:1) + (a[i -1]==c[i+j+1 -2]?0:1));	
				}
				dp[i][j] = min(dp[i][j], dp[i-1][j-1] + (a[i -1]==c[i+j -2]?0:1) + (b[j -1]==c[i+j+1 -2]?0:1));
				dp[i][j] = min(dp[i][j], dp[i-1][j-1] + (b[j -1]==c[i+j -2]?0:1) + (a[i -1]==c[i+j+1 -2]?0:1));
				if(j>=2){
					dp[i][j] = min(dp[i][j], dp[i][j-2] + (b[j-1 -1]==c[i+j -2]?0:1) + (b[j -1]==c[i+j+1 -2]?0:1));
				}
			}
		}
		cout<<dp[n][m]<<"\n";
	}
	return 0;
}

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

typedef long long ll;

int dp(string &a, string &b, string &c, int ia, int ib, vector<vector<int>> &arr)
{
    if (ia == a.size() && ib == b.size())
    {
        return 0;
    }

    if (arr[ia][ib] != -1)
    {
        return arr[ia][ib];
    }

    int left = INT_MAX, right = INT_MAX;

    if (ia < a.size())
    {
        if (arr[ia + 1][ib] != -1)
        {
            left = arr[ia + 1][ib] + (a[ia] != c[ia + ib]);
        }
        else
        {
            left = dp(a, b, c, ia + 1, ib, arr) + (a[ia] != c[ia + ib]);
        }
    }
    if (ib < b.size())
    {
        if (arr[ia][ib + 1] != -1)
        {
            right = arr[ia][ib + 1] + (b[ib] != c[ia + ib]);
        }
        else
        {
            right = dp(a, b, c, ia, ib + 1, arr) + (b[ib] != c[ia + ib]);
        }
    }

    arr[ia][ib] = min(left, right);
    return arr[ia][ib];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

        vector<vector<int>> arr(a.size() + 1, vector<int>(b.size() + 1, -1));

        cout << dp(a, b, c, 0, 0, arr) << endl;
    }

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

Solution 1 (runtime: 93 ms):

#include <bits/stdc++.h>


using namespace std;


int sumXor(int a, int b, int c)
{
    return (a^b) + (b^c) + (a^c);
}


void solve()
{
    int left, right;

    cin >> left >> right;

    int k = 31 - __builtin_clz(right^left);

    cout << (left|((1 << k) - 1)) << ' ' << (left | ((1 << k) - 1)) + 1 << ' ' << 
    (((left|((1 << k) - 1)) == left) ? right : left);
    //cout << "\n" << sumXor((left|((1 << k) - 1)), (left | ((1 << k) - 1)) + 1, ((left|((1 << k) - 1)) == left ? right : left));
}


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

    while (t--)
    {
        solve();
        cout << endl;
    }
}

Solution 2 (runtime: 77 ms):
#warning Check FastIO
#ifdef ONLINE_JUDGE
    #pragma GCC optimize("Ofast")
    #pragma GCC target("avx,avx2,fma")
#endif
#include <iostream>
#include <algorithm>
#include <climits>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <random>
#include <chrono>
#include <iomanip>
#include <vector>
#include <fstream>
using namespace std;
#define vll vector<ll>
#define sll set<ll>
#define vstr vector<string>
#define ll long long
#define ld long double
#define supra main
#define pb push_back
#define add insert
#define rall(x) rbegin(x),rend(x)
#define all(x) (x).begin(),(x).end()
#define I ios_base::sync_with_stdio(false);
#define Hear cin.tie(NULL);
#define Shots cout.tie(NULL);
#define Ratatatata
#define bits_on(a) (__builtin_popcountll(a))
#define mx_pw2(a) (__builtin_ctzll(a))
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());  
#define SHUFFLE(v) shuffle(all(v), RNG); 
const ll inf=LLONG_MAX;
void input(vll& a)
{
    for(auto& i:a)
        cin>>i;
}
void pyn(bool a)
{
    cout<<(a?"YES":"NO")<<endl;
}
ll powmod(ll a,ll b,ll modulo)
{
  if(b==0){
    return 1;
  }
  ll temp=powmod(a,b/2,modulo);
  if(b%2==0){
    return (temp*temp)%modulo;
  }
  else{
    return (a*((temp*temp)%modulo))%modulo;
  }
}

bool Prime(ll n){
    for (ll i = 2; i*i <= n; i++)
        if (n % i == 0)
            return false;
    return (n>1);
}
void solve()
{
    ll l,r;
    cin>>l>>r;
    ll aa=l,bb=l+1,cc=l+2;
    ll mx=(aa^bb)+(bb^cc)+(aa^cc);
    for(ll pw=1;pw<=r;pw*=2)
    {
        ll a=(r/pw)*pw,b=a-1;
        if(l<=a and a<=r and l<=b and b<=r)
        {
            ll c;
            if(l!=a and l!=b)
            {
                c=l;
            }
            else
            {
                c=r;
            }
            ll cur=(a^b)+(a^c)+(b^c);
            if(cur>mx)
            {
                mx=cur;
                aa=a,bb=b,cc=c;
            }
        }
    }
    cout<<aa<<' '<<bb<<' '<<cc<<endl;
}
int supra(){
    I Hear Shots Ratatatata
    ll tqwertyuiop=1;
    cin>>tqwertyuiop;
    for(int tp=1;tp<=tqwertyuiop;tp++)
    {
        // cout<<"Case #"<<tp<<": ";
        solve();
    }
    return 0;
}
/*
Bro use only in a emergency 
this is kind of hacking
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
*/
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;cin>>t;
    while(t--)
    {
        int n;
        cin >> n;
        int mx = -1e18;
        vector<int> a(n);
        for(int i =0;i < n; i++) cin >> a[i];
        while(1)
        {
            int p = 0;for(auto it : a) p += it;
            mx = max(mx, p);
            if(a.size()== 1) break;
            if(a[0] > a.back()) reverse(a.begin(), a.end());
            vector<int> b;
            for(int i = 0; i <a.size()-1;i++) b.push_back(a[i+1]-a[i]);
            a = b;

        }
        cout << mx << "\n";
    }
}


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

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

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<long long> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        vector<long long> maxsum;
        while (a.size() >= 1) {
            long long sum = accumulate(a.begin(), a.end(), 0LL);
            maxsum.push_back(sum);

            vector<long long> b, c;
            for (size_t i = 0; i < a.size() - 1; i++) {
                b.push_back(a[i + 1] - a[i]);
            }
            for (size_t i = a.size() - 1; i > 0; i--) {
                c.push_back(a[i - 1] - a[i]);
            }

            long long d = accumulate(b.begin(), b.end(), 0LL);
            long long e = accumulate(c.begin(), c.end(), 0LL);

            if (d > e) {
                a = b;
            } else {
                a = c;
            }
        }
        cout << *max_element(maxsum.begin(), maxsum.end()) << endl;
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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

using namespace std;

void solve() {
    int l, r;
    cin >> l >> r;
    int k = 31 - __builtin_clz(l ^ r);
    int a = l | ((1 << k) - 1), b = a + 1;
    int c = l;
    // 确保 c 不等于 a 和 b，否则递增
    while (c == a || c == b) {
        c++;
    }
    cout << a << " " << b << " " << c << "\n";
}

// void test() {
//     int l=6, r=22;
//     int c=l^r;
//     cout << c << "\n"; 
//     bitset<32> bin(c);
//     cout << bin << "\n"; 
// }
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    // test();

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

    return 0;
}

Solution 2 (runtime: 61 ms):
#include <bits/stdc++.h>
 
using namespace std;
#define debug(x) cout << #x << " " << x << endl;

void solve() {
    int l ,r ;
    cin >> l >> r ;
    int val = l^r ;
    int bit = 0 ;
    for (int i = 30 ; i >= 0 ; i --) {
        if ((1 << i) & val) {
            bit = i ;
            break ;
        }
    }
    int a = l | ((1 << bit)-1) ;
    int b = a + 1 ;
    int c = (a != l ? l : r) ;
    cout << a << " " << b << " " << c << '\n' ;
 }
int main(){
    
    #ifndef ONLINE_JUDGE
 
    // freopen("radio.in", "r", stdin);   // file input.txt is opened in reading mode i.e "r"
 
    // freopen("radio.out", "w", stdout); // file output.txt is opened in writing mode i.e "w"
 
    freopen("input.txt","r",stdin);
 
    freopen("output.txt","w",stdout);
 
     #endif
 
    ios_base::sync_with_stdio(0);
 
    cin.tie(0); 
 
    cout.tie(0);
 
    int t ;
 
    t = 1 ;
 
    cin >> t;
 
    while(t--) {
      
      solve();
    }
 
 
    return 0;
 
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 77 ms):
/**
 * SUGERIDO:
 */

#include <bits/stdc++.h>
#define BOOST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

using namespace std;

int main(){
    BOOST
    
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<ll> arr(n);
        for (int i = 0; i < n; i++){
            cin >> arr[i];
        }
        
        // Se n = 1, nao precisa processar
        if(n == 1){
            cout << arr[0] << "\n";
            continue;
        }
        
        // Se k = 0: nao calcula subtracoes
        ll sum0 = 0;
        for (ll x : arr)
            sum0 += x;
        ll best = sum0; // Nota, nao inverter para k=0
        
        vector<ll> current = arr;
        
        // Para cada k de 1 ate n-1, aplicar operacao 2 ("Replace the sequence with its difference sequence")
        for (int k = 1; k < n; k++){
            vector<ll> next;
            for (int i = 0; i < (int)current.size() - 1; i++){
                next.push_back(current[i+1] - current[i]);
            }
            // Soma da diferenca
            ll s = 0;
            for (ll x : next)
                s += x;
            
            // Para k >= 1 ver com o sinal trocado (se s negativo, inversao da positivo - llabs)
            best = max(best, llabs(s));
            
            // Proxima iteracao
            current = next;
        }
        
        cout << best << "\n";
    }
    return 0;
}


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

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
         int n;
         cin >> n;
         vector<long long int>arr(n);
         for (int i=0; i<n; i++)
         {
            cin >> arr[i];
         }
         long long int sum = accumulate(arr.begin(), arr.end(), 0);
         while(n!=1)
         {
             
            sum = max(sum, abs(arr[0] - arr[n-1]));
            for (int i =0; i<n-1; i++)
            {
                arr[i] = arr[i] - arr[i+1];
            }
            n--;
         }
         cout << sum << endl;
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

ll n, l, r;
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int t; cin >> t;

    while(t--) {
        cin >> n >> l >> r;

        priority_queue<ll> mid_l, mid_r;
        priority_queue<ll, vector<ll>, greater<ll>> lqu, rqu;
        ll ans = 0, la = 0, ra = 0;

        for (int i = 1; i < l; i++) {
            ll e; cin >> e;
            lqu.push(e);
        }

        for (int i = l; i <= r; i++) {
            ll e; cin >> e;
            mid_l.push(e); mid_r.push(e);

            ans += e;
        }

        for (int i = r + 1; i <= n; i++) {
            ll e; cin >> e;
            rqu.push(e);
        }


        while(!lqu.empty() && !mid_l.empty()) {
            if (lqu.top() <= mid_l.top()) la += lqu.top() - mid_l.top();
            else break;

            lqu.pop(); mid_l.pop();
        }

        while(!rqu.empty() && !mid_r.empty()) {
            if (rqu.top() <= mid_r.top()) ra += rqu.top() - mid_r.top();
            else break;

            rqu.pop(); mid_r.pop();
        }

        cout << ans + min(min(ra, la), 0LL) << endl;
    }

    return 0;
}

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



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

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

#define rep(i, a, b) for (int i = a; i < (b); i++)

#define rev(i, a, b) for (int i = a; i >= (b); i--)

#define fr first

#define sc second

#define pb push_back

#define endl "\n"



using namespace std;



template<class T, class U> inline void chmin(T& a, U b) { if (a > b) a = b; }

template<class T, class U> inline void chmax(T& a, U b) { if (a < b) a = b; }



typedef long long ll;

typedef pair<int,int> pii;

typedef pair<ll,ll> pll;



void solve_task() {

 

    ll n, l, r;

    cin >> n >> l >> r;

 

    vector<ll> L, R, B;

    ll sum = 0;

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

        ll x;

        cin >> x;

        if(l <= i && i <= r) B.push_back(x), sum += x;

        if(i < l) L.push_back(x);

        if(i > r) R.push_back(x);

    }

    auto solve = [&](vector<ll> A, vector<ll> B) -> ll{

        ll s = sum;

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

        reverse(A.begin(), A.end());

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

        while(!A.empty() && !B.empty()){

            if(B.back() <= A.back()) break;

            s -= B.back() - A.back();

            A.pop_back();

            B.pop_back();

        }

        return s;

    };

    cout << min(solve(L, B), solve(R, B)) << endl;

}



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    int tc = 1;cin >> tc;

    while (tc--) solve_task();



    return 0;

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

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
#define F first
#define S second
#define MP std::make_pair

typedef long long LL;

void solve()
{
    int l, r, a = 0, b = 0, c = 0;
    std::cin >> l >> r;
    for (int i = 29; i >= 0; i--)
        if ((l ^ r) >> i)
        {
            a += 1 << i;
            b += (1 << i) - 1;
            int k = l;
            while (k == a || k == b) k++;
            c = k;
            break;
        }
        else
            a += (1 << i) & l, b += (1 << i) & l;
    std::cout << a << ' ' << b << ' ' << c << '\n';
}

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

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
#define int long long
using namespace std;
int T,l,r;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>T;
	while(T--){
		cin>>l>>r;
		int a=0,b=0;
		for(int i=30;i>=0;i--){
			int li=((l>>i)&1),ri=((r>>i)&1);
			if(li==ri){
				a+=li*(1<<i),b+=li*(1<<i);
				continue;
			}
			a+=(1<<i);
			b+=(1<<i)-1;
			break;
		}
		if(b!=l) cout<<a<<' '<<(b^1)<<' '<<b<<'\n';
		else if(a!=r) cout<<a<<' '<<r<<' '<<b<<'\n';
		else cout<<a<<' '<<l+1<<' '<<b<<'\n';
	}
	return 0;
}