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

Solution 1 (runtime: 374 ms):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int t = sc.nextInt();
        while(t-- != 0){
            int l = sc.nextInt(), r = sc.nextInt();
            int a = 0, b = 0, c = 0;
            int n1 = countBits(l), n2 = countBits(r);
            if(r - l == 2){
                a = l; b = a + 1; c = b + 1;
            }
            else{
                int count = 0;
                for(int i = Math.max(n1, n2) - 1; i >= 0; i--){
                    int bit1 = ((l & (int)(1 << i)) == 0) ? 0 : 1;
                    int bit2 = ((r & (int)(1 << i)) == 0) ? 0 : 1;
                    count = i;
                    if(bit1 != bit2){
                        break;
                    }
                    int val = bit1 << i;
                    a += val; b += val;
                }
                a += (int)(1 << count);
                for(int i = count - 1; i >= 0; i--){
                    b += (int)(1 << i);
                }
                for(int i = l; i <= r; i++){
                    if(a != i && b != i){
                        c = i;
                        break;
                    }
                }
            }
            out.println(a + " " + b + " " + c);
        }
        out.close();
        }
    
    static int countBits(int n){
        int count = 0;
        while(n != 0){
            n /= 2;
            count++;
        }
        return count;
    }

        static class FastScanner {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            StringTokenizer st = new StringTokenizer("");
     
            String next() {
                while (!st.hasMoreTokens())
                    try {
                        st = new StringTokenizer(br.readLine());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                return st.nextToken();
            }
     
            int nextInt() {
                return Integer.parseInt(next());
            }
     
            int[] readArray(int n) {
                int[] a = new int[n];
                for (int i = 0; i < n; i++)
                    a[i] = nextInt();
                return a;
            }
     
            long nextLong() {
                return Long.parseLong(next());
            }
        }

    }

Solution 2 (runtime: 374 ms):
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int tt = sc.nextInt();
        while(tt-->0){
            int l = sc.nextInt(); int r = sc.nextInt();
            int a = pick(l,r);
            System.out.println(a);
            int b = a-1; System.out.println(b);
            int c = l; while (c==a || c==b) c++;
            System.out.println(c); 
        }
        sc.close();
    }

    public static int pick(int l, int r){
        int a = 1;
        while (a<<1 <= r) a=a<<1;

        if ((a&r) == (a&l)) return a+pick(l-a, r-a);
        return a;
    }
}