Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define rep(i,a,b) for( long long i=a;i<( long long)b;i++)
#define F first
#define S second
#define pb push_back
#define yes() cout << "YES\n"
#define no() cout << "NO\n"
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<long long, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset; 

//bool comp(const pair<int,int>&a, const pair<int,int>&b){
//  return (a.f>b.f || (a.f==b.f && a.s<b.s));
//}

/*
//lowerbound
//imprime -1 si ningún valor cumple la condición
ll binsearchpos(ll mini, ll maxi){
    ll l=mini,r=maxi,ans=-1;
    
    while(l<=r){
        ll mid=l+(r-l)/2, target=0LL;
        ll f=gauss(mid-1)+(mid*k) - (gauss(n-1)+(n*k)-gauss(mid-1)-(mid*k));
        
        if(f>=target){
            //ans se actualiza si se cumple la condición
            ans=mid;
            r=mid-1;
        }else{
            l=mid+1;
        }
    }
    return ans;
}
*/  


void solve(){
    
    ll l,r;

    cin>>l>>r;

    ll c=0;

    ll con=0,num=0;
    rep(pot,0,32){
        ll mask=(1<<pot);
        num |= (mask&r);
        if(num==r){
            con=pot;
            break;
        }
    }
    //cout<<con<<"\n";
    bool found=false,firstone=false,pos=-1;
    for(int pot=con; pot>=0; pot--){
        ll mask=(1<<pot);

        if(!found){
            if((r&mask)==(l&mask)){
                c|=(r&mask);
                continue;
            }else{
                c|=(l&mask);
                pos=pot;
                found=true;
                continue;
            }
        }

        if((r&mask)!=(l&mask)){
            c|=(l&mask);
        }else{
            if((l&mask)==0){
                firstone=true;
                c|=mask;
                continue;
            }
            //==1
            if(!firstone){
                c|=(1<<pos);
                firstone=true;
                continue;
            }
            
        }


    }
    if(c==l)
        c++;
    cout<<l<<" "<<r<<" "<<c;
   
    return;
}


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int tt=1;
    cin>>tt;
    
    while(tt--){
        solve();
        cout<<"\n";
    }

    return 0;
}
        

Submission (verdict: Accepted):
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define rep(i,a,b) for( long long i=a;i<( long long)b;i++)
#define F first
#define S second
#define pb push_back
#define yes() cout << "YES\n"
#define no() cout << "NO\n"
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<long long, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset; 

//bool comp(const pair<int,int>&a, const pair<int,int>&b){
//  return (a.f>b.f || (a.f==b.f && a.s<b.s));
//}

/*
//lowerbound
//imprime -1 si ningún valor cumple la condición
ll binsearchpos(ll mini, ll maxi){
    ll l=mini,r=maxi,ans=-1;
    
    while(l<=r){
        ll mid=l+(r-l)/2, target=0LL;
        ll f=gauss(mid-1)+(mid*k) - (gauss(n-1)+(n*k)-gauss(mid-1)-(mid*k));
        
        if(f>=target){
            //ans se actualiza si se cumple la condición
            ans=mid;
            r=mid-1;
        }else{
            l=mid+1;
        }
    }
    return ans;
}
*/  

const ll MOD=998244353;
 
long long binpow(ll a, ll b) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

void solve(){
    /*
        1 1 -> 0
        1 0 >1
        0 1 >1
        0 0 -> 0
        
        11 010001
        11 001111
        10 110000
        
        111
        111           
        000  

        010
        001
        000 
        after first dif (posdif)
        first eq after fd (poseq)
        if r[i]!=l[i]
        assign l[i]    
    */
    ll l,r;
    cin>>l>>r;

    ll k=0,e=-1,ans=0;
    for(int pot=31;pot>=0;pot--){
        ll mask=(1<<pot);

        if(!k && ((l&mask) != (r&mask))){
            k=pot;
            continue;
        }else if(!k){
            ans+=(l&mask);
            continue;    
        }

        if((l&mask) == (r&mask)){
            e=(l&mask);
            break;
        }
    }
    //cout<<k<<" "<<e<<"\n";
    for(int pot=k;pot>=0;pot--){
        ll mask=(1<<pot);

        if(!e){
            if((l&mask) != (r&mask)) ans+=(l&mask);
            else if(!(l&mask)) ans+=mask;
        }else{
            if((l&mask) != (r&mask)) ans+=(r&mask);
            else if(!(l&mask)) ans+=mask;
        }
    }

    if(ans==r) ans--;
    cout<<l<<" "<<r<<" "<<ans<<"\n";
    return;
}


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int tt=1;
    cin>>tt;
    
    while(tt--){
        solve();
    }

    return 0;
}