Problem: 2057C - Trip to the Olympiad
Language: java

Solution 1 (runtime: 234 ms):
import java.util.*;

public class C{
    public static boolean powerOf2(int n){
        if(n==1) return false;
        int a = 1;
        while(a<n) a = a*2;
        if(a==n) return true;
        return false;
    }
    public static void main(String...args){
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        while(t>0){
            t--;

            int l = sc.nextInt();
            int r = sc.nextInt();

            int mid = 0;
            boolean smallerThanr = false, greaterThanl = false;

            int start = 30;
            int i = start;
            while(i>=0){
                int lbit = (((1<<i)&l)>>i);
                int rbit = (((1<<i)&r)>>i);
                if(lbit != rbit) break;
                mid += (lbit<<i);
                i--;
            }
            // System.out.println(mid);

            start = i;
            for(i=start; i>=0; i--){
                int lbit = (((1<<i)&l)>>i);
                int rbit = (((1<<i)&r)>>i);
                int mBit = 0;

                if(lbit==1 || rbit==1) mBit=0;
                else mBit = 1;
                mid += (mBit<<i);
            }
            // System.out.println(mid);

            
            i = start;
            while(i>=0 && mid <= l){
                int mBit = (((1<<i)&mid)>>i);
                // System.out.println(i + " " + mBit + " " + mid);
                if(mBit==0 && ((mid + (1<<i)) < r)){
                    mid += (1<<i);
                }
                i--;
            }
            System.out.println(l + " " + mid + " " + r);
        }
    }
}

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

#define int long long

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vbl = vector<bool>;
using vpii = vector<pii>;
template<class T> using vv = vector<vector<T>>;

#define pb emplace_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define siz(v) (int)(size(v))

#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (b); i--)
#define rept(a) rep(_, 1, a)

#define watch(x) cout << (#x) << ':' << (x) << '\n';
#define watch2(x, y) cout << (#x) << ':' << (x) << ',' << (#y) << ':' << (y) << '\n';

template<class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os << '{' << p.first << ',' << p.second << '}';
}
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	for (auto &x : v) os << x << ' ';
	return os;
}

const int inf = 1e9;
const ll llinf = 4e18;

void orz()
{
    int l, r; cin >> l >> r;
    rrep(i, 30, 0){
        if ((l>>i)^(r>>i)){
            cout << (1<<i) << ' ' << ((1<<i)-1) << ' ' << ((1<<i)-2 < l ? (1<<i)+1 : (1<<i)-2) << '\n';
            return;
        }
    }
}

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin.exceptions(cin.failbit);

    int t = 1; cin >> t;
    while (t--) orz();

    return 0;
}