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: 358 ms):
import java.util.*;
import java.io.*;

public class C_Trip_to_the_Olympiad {

    int mod = (int) 1e9 + 7;
    
    public static void main(String[] args) {
        int t = sc.nextInt();
        while (t-- > 0) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int x1 = r;
            int x2 = l;
            boolean f1 = false;
            boolean f2 = false;

            for(int i=30;i>=0;i--){
                int b1 = ((x1>>i)&1);
                int b2 = ((x2>>i)&1);
                if(b1==b2){
                    if(f1) x1 = x1 ^ (1<<i);
                    else if(f2) x2 = x2 ^ (1<<i);
                    else{
                        if(b1==0 && (x2^(1<<i))<=r){
                            // System.out.println((x2^(1<<i)));
                            x2 = x2 ^ (1<<i);
                            f2 = true;
                        }
                        else if(b1==1 && (x1^(1<<i))>=l){
                            x1 = x1 ^ (1<<i);
                            f1 = true;
                        }
                        
                    }
                }
                // System.out.println(x2);
            }
            int x3 = l;
            boolean f3 = false;

            for(int i=30;i>=0;i--){
                int b1 = ((x1>>i)&1);
                int b2 = ((x2>>i)&1);
                if(b1==b2 && b1==1 && f3) x3^=(1<<i);
                if(b1==b2 && b1==0 && (x3^(1<<i))<=r){
                    f3 = true;
                    x3^=(1<<i);
                }
            }
            if(x2==x3) x3++;
            if(x1==x3) x3++;
            System.out.println(x1 + " " + x2 + " " + x3);
        }
    }
    
    public static void input(Object array) {
        if (array instanceof int[])
            for (int i = 0; i < ((int[]) array).length; i++)
                ((int[]) array)[i] = sc.nextInt();
        else if (array instanceof long[])
            for (int i = 0; i < ((long[]) array).length; i++)
                ((long[]) array)[i] = sc.nextLong();
    }
    
    public static void printArr(Object array) {
        if (array instanceof int[])
            for (int x : (int[]) array)
                System.out.print(x + " ");
        else if (array instanceof long[])
            for (long x : (long[]) array)
                System.out.print(x + " ");
        System.out.println();
    }
    
    public static <T extends Number> long gcd(T a, T b) {
        return b.longValue() == 0 ? a.longValue() : gcd(b, a.longValue() % b.longValue());
    }
    
    static FastReader sc = new FastReader();
    
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
    
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
    
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
    
        int nextInt() {
            return Integer.parseInt(next());
        }
    
        long nextLong() {
            return Long.parseLong(next());
        }
    
        double nextDouble() {
            return Double.parseDouble(next());
        }
    
        String nextLine() {
            String str = "";
            try {
                str = br.readLine().trim();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}