ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

using namespace std;

string fun(int n,vector<int>&v){

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

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

        return "NO";

    }

    else{

    int x = min(v[i],v[i+1]);

    v[i]=v[i]-x;

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

    }

 } 

 return "YES";  

}

int main(){

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        vector<int> v(n);

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

            cin>>v[i];

        }

        cout<<fun(n,v)<<endl;

    }

    return 0;

}

Solution 2 (runtime: 343 ms):
#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

 

typedef long long ll;

 

int main() {

    int t;

    cin>>t;

    

    

    while(t--){

        int n;

        cin>>n;

        vector<ll>a(n);

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

        

        bool ok=true;

        

        if(a[0]>a[1]){

            cout<<"NO"<<endl;

            continue;

        }

        

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

            ll minimo;

            

            if(a[i]<a[i-1]){

                ok=false;

                break;

            }

            

            if(a[i]>=a[i-1]){

                minimo=min(a[i-1],a[i]);

                a[i-1]-=minimo;

                a[i]-=minimo;

            }

            

            

            

        }    

        

        if(ok){

            cout<<"YES"<<endl;

        }else{

            cout<<"NO"<<endl;

        }

        

    }

    

    return 0;

}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=200001;

int main(){
    ll T;
    cin>>T;
    while(T--){
        ll n;
        cin>>n;
        ll a[n];
        vector<ll> v;
        ll maxi=0;
        ll sum=0;
        for(ll i=0;i<n;i++){
            cin>>a[i];
            v.push_back(a[i]);
            sum+=a[i];
        }
        maxi=sum;
        vector<ll> cur;
        for(ll i=0;i<(n-1);i++){
            ll sz=v.size();
            sum=0;
            for(ll i=1;i<sz;i++){
                ll x=v[i]-v[i-1];
                sum+=x;
                cur.push_back(x);
            }
            v.clear();
            sum=abs(sum);
            maxi=max(maxi,sum);
            for(auto z:cur) v.push_back(z);
            cur.clear();
        }
        cout<<maxi<<endl;
    }
    return 0;
}



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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int n; // Number of test cases
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a ; 
        vector<ll> k(a);
        
        for (int i = 0; i < a; i++) {
            cin >> k[i];
        }
        bool flag = true;
        int size = a;
        ll sum = accumulate(k.begin(),k.end(),0ll);
        // if(size == 2) sum = max(sum,max(k[0] - k[1],k[1] - k[0]));
        // else{
        while(size!=1){
                for(int i = 1;i<size;i++){
                    k[i-1] = k[i] - k[i-1];
                }
                k.pop_back();
                ll curr = accumulate(k.begin(),k.end(),0ll);
                sum = max(sum,abs(curr));
                size--;
            }
        // }
        cout << sum << endl;
    }

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

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

#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

// *****************************Solution*************************** //
int mod = 1e9 + 7;

void fun()
{
  int l,r;
  cin>>l>>r;
  
  if(r - l + 1 == 3){
    cout<<l<<" "<<l+1<<" "<<r<<endl;
    return; 
  }
  
  int a,b,c;
  int res = 0;

  for(int i=31;i>=0;i--){
   int b1 = 0,b2 = 0;
   
   if(r&(1<<i)){
       b1 = 1;
   }

   if(l&(1<<i)){
     b2 = 1;
   }

   if(b1 == b2){
     res += (b1<<i);
   }else{
     a = res + (1<<i);     
     b = a - 1;
     break;
   }
  }

  for(int i=l;i<=r;i++){
    if(i != a && i != b){
      c = i;
      break;
    }
  }
  
  cout<<a<<" "<<b<<" "<<c<<endl;
}

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

  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif

  int t = 1;
  cin >> t;
  while (t--)
  {
    fun();
  }

  return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        long long l, r;
        cin >> l >> r;
        long long a = r;
        long long b = r - 1;
        long long c;

        if ((a & (a - 1)) == 0) { // Check if a is a power of two
            c = l;
            while (c == a || c == b) {
                c++;
            }
        } else {
            int k = __builtin_ctzll(a); // Find the least significant set bit
            long long mask = ~((1LL << (k + 1)) - 1);
            c = (a ^ mask) | ((1LL << (k + 1)) - 1);
            if (c < l || c > r || c == a || c == b) {
                c = l;
                while (c == a || c == b) {
                    c++;
                }
            }
        }
        cout << a << " " << b << " " << c << "\n";
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 265 ms):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void solve(){
    int n;
    cin>>n;
    vector<int> a(n),x(n+1);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) x[a[i]]=i;
    vector<pair<int,int>> res;
    vector<int> now;
    for(int i=1;i<=n;i++){
        int k=now.size();
        now.push_back(i);
        for(int j=k-1;j>=0;j--){
            res.push_back({i,now[j]});
            swap(now[j],now[j+1]);
        }
        for(int j=0;j<k;j++){
            if(x[i]>x[now[j+1]]){
                res.push_back({now[j+1],i});
                swap(now[j+1],now[j]);
            }
            else break;
        }
    }
    cout<<res.size()<<'\n';
    for(auto [x,y]:res) cout<<x<<" "<<y<<'\n';
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T=1;
    // cin>>T;
    while(T--) solve();
    return 0;
}

Solution 2 (runtime: 265 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> ve;
typedef vector<long long> vl;
typedef vector<pair<int,int>> vp;
typedef vector<char> vc;
typedef vector<double> vd;
#define fi first
#define se second
#define pb push_back
#define con continue 
#define rep(i,a,b) for (int i=a;i<b;i++)
#define res(j,a,b) for (int j=a;j>=b;j--)
const double eps = 1e-6;
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define endl "\n"
signed main()
{
    fastio;
        int n;
        cin>>n;
        ve v(n);
        stack<int>a,b;
        rep(i,0,n){
        cin>>v[i];
        a.push(n-i);
        }
        if(n==1){
        cout<<"0"<<endl;
        }
        else{
        vp ans;
        res(j,n-1,0){
            while(a.top()!=v[j]){
               b.push(a.top());
               a.pop();
            }
            a.pop();
            while(!b.empty()){
                ans.pb({v[j],b.top()});
                a.push(b.top());
                b.pop();
            }
            a.push(v[j]);
        }
        cout<<ans.size()<<endl;
        for(auto k:ans)
        cout<<k.fi<<" "<<k.se<<endl;
    }
        return 0;
    }
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX (int)2e5+50
#define inf (int)2e9

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T;
	cin >> T;
	while (T--) {
		int n, m, i, j, k;
		ll l, r;
		cin >> l >> r;
		ll now = 1LL << 30;
		ll res = 0;
		while (now) {
			//ll tmp = (r & now);
			//cout << tmp << '\n';
			if ((l & now) == (r & now)) {
				res |= l & now;
				now >>= 1;
			}
			else
				break;
		}
		//cout << res << ' ' << now << '\n';
		ll res3;
		for (i = l; i <= r; i++) {
			if (i != res + now && i != res + now - 1) {
				res3 = i;
				break;
			}
		}
		cout << res + now << ' ' << res + now - 1 << ' ' << res3 << '\n';
	}
}

Solution 2 (runtime: 124 ms):
#include <bits/stdc++.h>
#ifdef DEBUG
constexpr bool debug = true;
#else
constexpr bool debug = false;
#endif
using namespace std;
using u64 = uint64_t;
using i64 = int64_t;
using u32 = uint32_t;

int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    u32 l,r; cin >> l >> r;
    int k = 31 - __builtin_clz(l^r);
    u32 x = l | ((1<<k) - 1);
    u32 y = x + 1;
    u32 z = (x == l ? r : l);
    if constexpr (debug) {
      u32 max = (1 << k+1) -1;
      max <<= 1;
      printf("%u %u | ", max, (x^y)+(y^z)+(x^z));
    }
    printf("%u %u %u\n", x, y, z);
  }
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

#define ll long long

using namespace std;









 

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>v1,v2,v3;

    l--;

    r--;

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

    {

        if(i<l) v1.push_back(a[i]);

        else if(i>r) v3.push_back(a[i]);

        else v2.push_back(a[i]);

    }

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

    sort(v2.begin(),v2.end(),greater<int>());

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

    int i=0,j=0;

    ll sum=0;

    while(i<v1.size() && j<v2.size())

    {

        sum+=min(v1[i],v2[j]);

        i++;

        j++;

    }

    while(j<v2.size())

    {

        sum+=v2[j];

        j++;

    }

    i=0,j=0;

    ll sum1=0;

    while(i<v3.size() && j<v2.size())

    {

        sum1+=min(v3[i],v2[j]);

        i++;

        j++;

    }

    while(j<v2.size())

    {

        sum1+=v2[j];

        j++;

    }

    if(sum==0) cout<<sum1<<endl;

    else if(sum1==0) cout<<sum<<endl;

    else cout<<min(sum,sum1)<<endl;

    // for(int i=0;i<v1.size();i++) cout<<v1[i]<<" ";

    // cout<<endl;

    // for(int i=0;i<v2.size();i++) cout<<v2[i]<<" ";

    // cout<<endl;

    // for(int i=0;i<v3.size();i++) cout<<v3[i]<<" ";

    // cout<<endl;

}

 

int main()

{

    ll T;

    cin>>T;

    while(T--)

    {

        solve();

    }

    // solve();

 

    return 0;

}









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

int main(){
    int t{};
    std::cin>>t;
    for(int x=0;x<t;++x){
        int a,b,c;
        std::cin>>a>>b>>c;
        int dif {c-b +1};
        std::vector<int> arr(a);
        for(int& y:arr){
            std::cin>>y;
        }
        std::vector<int> l(arr.begin(), arr.begin()+c), r(arr.begin()+b-1, arr.end());
        std::sort(l.begin(), l.end());
        std::sort(r.begin(), r.end());
        long long sml{}, smr{};
        for(int y=0;y<dif;y++){
            sml+=l[y];
            smr+=r[y];
        }
        if(sml>smr){
            std::cout<<smr<<'\n';
        }else{
            std::cout<<sml<<'\n';
        }
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

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

int main () {

    int t;
    cin>>t;

    while(t--) {
        string s;
        cin>>s;

        int i=s.length()-1;

        while(i!=0) {
            if (s[i]== 0) {
                i--;
                continue;
            }
            int temp=s[i]-1;
            if (temp > s[i-1]) {
                s[i]=s[i-1];
                s[i-1]=temp;
              if (i!=s.length()-1)  i=i+1;
            } else {
                i--;
            }
        }

        cout<<s<<endl;



    }




    return 0;
}

Solution 2 (runtime: 78 ms):
#include <iostream>

#include <algorithm>

#include <cstring>



using namespace std;

const int N = 2e5 + 10;

char s[N];

int n;



void solve(){

scanf("%s", s + 1);

n = strlen(s + 1);

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

int v = s[i] - '0';

if(v >= 8)continue;  // 9 or 8

else{

for(int tar = 8; tar > v; tar -- ){

// printf("%d %d\n", i, tar);

int flag = 0;

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

int need = tar + j;

if(need == 10)break;

if(need == s[i + j] - '0'){

flag = 1;



for(int k = j; k >= 1; k -- ){

s[i + k] = s[i + k - 1];

}



s[i] = tar + '0';

break;

}

}

if(flag)break;

}

}

// printf("%s\n", s + 1);

}

printf("%s\n", s + 1);

}



int main()

{

int T;

scanf("%d", &T);

while(T -- ){

solve();

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 328 ms):
#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n;
        cin >>n;
        int a[n];
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        for(int i=0; i<n-1; i++){
            if(a[i]>a[i+1]){
                cout << "NO\n";
                return;
            }else{
                a[i+1]-=min(a[i],a[i+1]);
                a[i]-=min(a[i],a[i+1]);
            }
        }
        cout << "YES\n";
}
int main(){
    int t;
    cin >> t;
    while(t--){
        solve();}
        return 0;
}

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

using namespace std;



int main() {

    int t;

    cin >> t; 

    while (t--) {

        int n;

        cin>>n;

        int a[n];

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

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

        {

            int x=min(a[i],a[i+1]);

            a[i]=a[i]-x;

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

        }

        int b=1;

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

        {

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

            {

                b=0;

                break;

            }

        }

        if(b==1) cout<<"YES"<<endl;

        else cout<<"NO"<<endl;

    }

    return 0;

}
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 421 ms):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ordered_set tree< ll , null_type,less_equal< ll >, rb_tree_tag,tree_order_statistics_node_update>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long

void solve()
{
    int n, m;
    cin>>n>>m;
    multiset<ll>from,to;
    for(int i = 0 ; i < n ; i++)
    {
        ll a;
        cin>>a;
        from.insert(a);
    }
    for(int i = 0 ; i < m ; i++)
    {
        ll a;
        cin>>a;
        to.insert(a);
    }
    while(to.size())
    {
        if(from.empty() || *to.begin() < *from.begin())
        {
            cout<<"NO"<<endl;
            return;
        }
        ll item = *to.begin();
        to.erase(to.begin());

        auto it = from.find(item);

        if(it != from.end())
        {
            from.erase(it);
        }
         else{
            to.insert(item / 2);
            to.insert((item / 2) + item % 2 );

         }

    }
    if(from.size())cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}
int main()
{
    fast
    int t;
    t = 1;
    cin>>t;
    while(t--)
    {

        solve();
    }
}

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

using namespace std;

using i64 = long long;

using u64 = unsigned long long;

void solve() {

    int n, m;

    cin >> n >> m;

    vector<i64> a(n + 1);

    vector<i64> b(m + 1);

    map<i64, i64> mp;

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

        cin >> a[i];

        mp[a[i]]++;

    }

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

        cin >> b[i];

    }

    function<bool(i64)> check = [&](i64 x) -> bool {

        if (mp.count(x)) {

            mp[x]--;

            if (mp[x] == 0) {

                mp.erase(x);

            }

            return 1;

        }

        if (x == 1) {

            return 0;

        }

        return check(x >> 1) && check((x + 1) >> 1);

    };

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

        if (!check(b[i])) {

            cout << "NO\n";

            return;

        }

    }

    if (mp.empty()) {

        cout << "YES\n";

    } else {

        cout << "NO\n";

    }

    return;

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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


#define md : 1000000007;



void solve(){
    int n,k;
    cin >> n >> k;

    vector<int> vec(n);
    vector<int>count = {1};

    for(int i=0; i<n; i++){
        cin >> vec[i];
    }

    sort(vec.begin(),vec.end());
    for(int i=1; i<vec.size(); i++){
        if(vec[i] == vec[i-1]){
            count.back()++;
        }else{
            count.push_back(1);
        }
    }

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

    int i;
    int m = count.size();
    for( i=0; i<m-1; ){
        if(count[i] > k) break;
        k-=count[i++];
    }

    cout << m-i <<  endl;
    // priority_queue<pair<int,int>, vector<pair<int,int>>, greater<> > st;

    // for(auto x: mp){
    //     st.push({x.second, x.first});
    // }

    // int count = 0;

    // while(!st.empty() && k){
    //     int temp = (st.top()).first;
    //     if(temp > k) k = 0;
    //     else{
    //         k-=temp;
    //         st.pop();
    //     }
    // }

    // st.size() > 0 ? cout <<  st.size() : cout << 1 ;
    // cout << endl;


}




int main(){

    int t;
    cin>>t;


    while(t--)
        solve();

    return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--){
	   int n,k;
	   cin>>n>>k;
	   map<int,int> m;
	   for(int i=0;i<n;++i){
	       int temp ;
	       cin>>temp;
	       m[temp]++;
	   }
	   vector<int> ans;
	   for(auto pr: m){
	       ans.push_back(pr.second);
	   }
	   sort(ans.begin(),ans.end());
	   int s = ans.size();
	   for(int i=0;i<ans.size();++i){
	       k-= ans[i];
	       if(k <0 ) break;
	       s--;
	   }
	   if(!s) cout<<"1\n";
	   else cout<<s<<endl;
	}
	return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 109 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fl(i, m, n) for (int i = m; i < n; i++)
#define flr(i, m, n) for (int i = m; i > n; i--)
#define in(p,n) fl(i,0,n)cin>>p[i]
#define all(arr) arr.begin(), arr.end()
#define pl(s) cout<<s<<"\n"
#define pv(s) for(int it:s)cout<<it<<" ";cout<<"\n"
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define si set<int>
#define pr pair<int,int>
#define mi map<int,int>
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define sz(s) s.size()
#define rsz(s,n) if(!sz(s))s.clear();s.resize(n)
#define srt(s) sort(all(s))
#define rsrt(s) sort(s.rbegin(),s.rend())
#define ub upper_bound
#define lb lower_bound
int mod=998244353;
inline int mul(int a, int b) { return ((a % mod) * (b % mod)) % mod; }
inline int binpow(int a, int b) { a %= mod; int res = 1; while (b > 0) { if (b & 1) res = mul(res, a); a = mul(a, a); b /= 2; } return res; }
inline int gcd(int a,int b){return __gcd(a,b);}
inline int ceil(int a, int b) { return (a + b - 1) / b;}




void solve(){
	int n,k;
	cin>>n>>k;
	vi a(n);
	in(a,n);
	mi val;
	fl(i,0,n)val[a[i]]++;
	vi num;
	for(pr it:val)if(it.second)num.pb(it.second);
	srt(num);
	int cur=0,sum=0;
	for(int it:num){
		sum+=it;
		if(sum<=k)cur++;
		else break;
	}
	//pl(max(1LL,sz(num)-cur));
	int x=sz(num)-cur>1?sz(num)-cur:1;
	pl(x);
}



signed main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#endif

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




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

signed main () {
  ios_base::sync_with_stdio(0); cin.tie(0);
  
   int tt; cin >> tt;
   while(tt--){
      int n , k; cin >> n >> k;
      map<int ,int> mp;
      for(int i = 0; i < n; i++){
          int a; cin >> a;
          mp[a]++;
      }
      
      if(!k){
          cout << mp.size() << "\n";
          continue;
      }
      
      int mx = 0 , ele = -1;
      
      for(auto [x , y] : mp){
          if(y > mx){
              ele = x;
              mx = y;
          }
      }
      
      mp.erase(ele);
      
      vector<int> freq;
      for(auto [x , y] : mp) freq.push_back(y);
      
      int val = 0 , ans = 1;
      sort(freq.begin() ,freq.end());
      for(int i = 0; i < freq.size(); i++){
          val += freq[i];
          if(val > k){
             ans = freq.size() - i + 1;
             break;
          }
      }
      
      cout << ans << "\n";
   }
   
   return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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

#define int long long
#define ll long long

#define mem(a, x) memset(a, x, sizeof(a))
#define sum(a) (accumulate((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define all(x) x.begin(), x.end()

#define nl cout << "\n";
#define op(x) cout << x << "\n";
#define opp(x, y) cout << x << " " << y << "\n";
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
/*--------------------------------------------------------------------------------------------------------------------------*/
void solve()
{
    int l, r;
    cin >> l >> r;
    int i = 30;
    while ((r & (1 << i)) == 0)
    {
        i--;
    }

    int a = 0;
    while (i >= 0)
    {
        if(!(r & (1<<i)) && !(l & (1<<i))){
            a += (1 << i);
        }
        i--;
    }

    i = 0;
    while((a + (1<<i)) <= l){
        i++;
    }
    a += (1 << i);
    
    cout << l << " " << a << " " << r << endl;
}

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

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

Solution 2 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ppb pop_back
void solve(){
    ll l,r;
    cin>>l>>r;
    ll a=0,b=0,c=0;
    for(ll i=29;i>=0;i--){
      if((l^r)>>i & 1){
        b|=(1<<i);
        a|=(1<<i)-1;
        break;
      }
      else{
        a|=l&(1<<i);
        b|=l&(1<<i);
      }
    }
    c=l;
    while(c==a || c==b){
      c++;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}

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

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

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

const int N=1e5+10;
int a[N],b[N],c[N];
signed main()
{
	int t;
	cin>>t;
	
	while(t--)
	{
		int n,l,r;
		cin>>n>>l>>r;
		
		for(int i = 1; i <= n ; i++)
			cin>>a[i];
		
		int mi;
		int s1=0,s2=0;
		int cnt1=0,cnt2=0;
		
		for(int i = 1; i <= r; i++)
			b[++cnt1]=a[i];
		
		for(int i = l; i <= n; i++)
			c[++cnt2]=a[i];
		
		sort(b+1,b+1+cnt1);
		sort(c+1,c+1+cnt2);
		
		for(int i = 1; i <= r-l+1; i++)
		{
			s1+=b[i];
			s2+=c[i];
		}
		
		
		mi=min(s1,s2);
		
		//cout<<"->";
		cout<<mi<<endl;
		
	}
	return 0;
}

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

using namespace std;

#define int long long

void solve() {

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

    vector<int>a(n+1,0),b(n+1,0);

    for(int i=1;i<=n;i++){cin>>a[i];b[i]=a[i];}

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

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

    int sum1=0,sum2=0;

    for(int i=1;i<=r-l+1;i++)sum1+=a[i];

    for(int i=l;i<=r;i++)sum2+=b[i];

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

}

signed main() {

    int t;cin>>t;

    while(t--)solve();

}