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

Previous submission (verdict: Wrong answer on test 2):
#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;
    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);
                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|=mask;
                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: 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;
}