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

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100050;
ll gcd(ll x,ll y){
	if(y==0) return x;
	else return gcd(y,x%y);
}
ll a[50]={0};
void solve(){
	ll l,r;
	stack<ll>st;
	scanf("%lld %lld",&l,&r);
	ll x=0;
	ll rr=r;
	while(rr>1){
		st.push(rr%2);
		rr/=2;
		x++;
	}
	ll xx=x;
	st.push(1);
	int a1=0;
	while(!st.empty()){a[++a1]=st.top();st.pop();}
	int p=1;
	ll ans=0;
	ll sum1=0;
	while(x>=0){
		if(a[p]==1){
			ans+=(1<<x);
		}
		p++;
		if(ans<=r&&ans-2>=l){
			sum1=(ans ^ (ans-1))+((ans-1) ^ (ans-2))+(ans ^(ans-2));
//			printf("%lld %lld %lld",ans,ans-1,ans-2);
			break;
		}else{
			x--;
		}
	}
//	cout<<"\n"<<(ans ^ (ans-1))+((ans-1) ^ (ans-2))+(ans ^(ans-2))<<"\n";
	ll ans2=0;
	ll sum2=0;
	x=xx;
	p=1;
	while(x>=0){
		if(a[p]==1){
			ans2+=(1<<x);
		}
		p++;
		if(ans2+1<=r&&ans2-1>=l){
//			printf("%lld %lld %lld",ans+1,ans-1,ans-1);
			sum2=(ans2 ^ (ans2-1))+((ans2-1) ^ (ans2+1))+(ans2 ^(ans2+1));
			break;
		}else{
			x--;
		}
	}
	ll ans3=0;
	ll sum3=0;
	x=xx;
	p=1;
	while(x>=0){
		if(a[p]==1){
			ans3+=(1<<x);
		}
		p++;
		if(ans3+2<=r&&ans3>=l){
//			printf("%lld %lld %lld",ans+1,ans-1,ans-1);
			sum3=(ans3 ^ (ans3+1))+((ans3+1) ^ (ans3+2))+(ans3 ^(ans3+2));
			break;
		}else{
			x--;
		}
	}
	if(sum3>=sum1&&sum3>=sum2){
		printf("%lld %lld %lld",ans3+1,ans3,ans3+2);
	}else if(sum2>=sum1&&sum2>=sum3){
		printf("%lld %lld %lld",ans2+1,ans2-1,ans2);
	}else{
		printf("%lld %lld %lld",ans,ans-1,ans-2);
	}
//	printf("\n%lld\n",max(max(sum1,sum2),sum3));
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--){
		solve();
		printf("\n");
	}
	return 0;
}
/*

*/


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

void solve(int tc) {
    int l, r;
    cin >> l >> r;

    int res = 0;
    auto f = [](int x, int y) -> int {
        if (x != y) {
            return 1;
        }
        return 1 - x;
    };
    auto g = [](int x, int y) -> int {
        if (x != y) {
            return 0;
        }
        return 1 - x;
    };

    for (int i = 30; i >= 0; --i) {
        int x = r >> i & 1;
        int y = l >> i & 1;
        if (x == y) {
            res |= x << i;
            continue;
        }
        int s = r >> i - 1 & 1;
        int t = l >> i - 1 & 1;
        if (s == t) {
            if (s == 1) {
                res |= 1 << i;
            }
            else {
                res |= 1 << i - 1;
            }
            for (int j = i - 2; j >= 0; --j) {
                res |= f(r >> j & 1, l >> j & 1) << j;
            }
            // cout << "debug" << '\n';
            break;
        }
        if (s == 1) {
            res |= 1 << i;
            for (int j = i - 2; j >= 0; --j) {
                res |= f(r >> j & 1, l >> j & 1) << j;
            }
        }
        else {
            assert(x == 1);
            assert(y == 0);
            assert(s == 0);
            assert(t == 1);

            bool ok = true;
            for (int j = i - 2; j >= 0; --j) {
                int a = r >> j & 1;
                int b = l >> j & 1;
                if (a == 0 && b == 1) {
                    continue;
                }
                if (b == 0) {
                    ok = true;
                }
                else {
                    ok = false;
                }
                break;
            }
            if (ok) {
                res |= 1 << i - 1;
            }
            else {
                res |= 1 << i;
            }
            for (int j = i - 2; j >= 0; --j) {
                if (ok) {
                    res |= f(r >> j & 1, l >> j & 1) << j;
                }
                else {
                    res |= g(r >> j & 1, l >> j & 1) << j;
                }
            }
        }
        break;
    }
    assert(l < res);
    assert(res < r);

    cout << l << ' ' << res << ' ' << r << '\n';

    // cout << (l ^ res) + (res ^ r) + (r ^ l) << '\n';
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve(i);
    }
}