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

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <vector>
#include <stack>
#include <limits.h>
#include <set>
#include <string>
#include <math.h>
#include <deque>
#include <queue>
#include <string>
#include <iomanip>
using namespace std;

/********************************************************

// Important header files   
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
#include <iostream>  
using namespace __gnu_pbds;  
  
// Declaring ordered_set 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update>  
    ordered_set;  

// declaration syntax : ordered_set st;
// index syntax : st.order_of_key('element'); 

*******************************************************/

vector<long long> findprime(long long n)
{   
    n += 1LL;
    vector<int>prime(n, 0);

    for(long long i = 2; i < n; i++)
    {
        if(prime[i] == 0)
        {
            for(long long j = i; j < n; j+=i) prime[j] = (-1);
            //cout << "marking i : " << i << endl;
            prime[i] = 1;
        }
    }

    vector<long long>p;
    for(long long i = 2; i < n; i++)
    {   
        if(prime[i] == 1) p.push_back(i);
    }
    return p;
}


long long lcm(long long a, long long b) 
{ 
    long long greater = max(a, b); 
    long long smallest = min(a, b); 
    for (long long i = greater; ; i += greater) { 
        if (i % smallest  == 0) 
            return i; 
    } 
} 

void findRoots(long long a, long long b, long long c, long long &root1, long long &root2)
{
    // If a is 0, then equation is
    // not quadratic, but linear
    if (a == 0) {
        // cout << "Invalid";
        root1 = -1LL, root2 = -1LL;
        return;
    }

    long long d = b * b - 4 * a * c;
    double sqrt_val = sqrt(abs(d));

    if (d > 0) {
        // cout << "Roots are real and different ";
        // cout << (double)(-b + sqrt_val) / (2 * a) << " "
        //      << (double)(-b - sqrt_val) / (2 * a);
        root1 = (double)(-b + sqrt_val) / (2 * a);
        root2 = (double)(-b - sqrt_val) / (2 * a);
    }
    else if (d == 0) {
        // cout << "Roots are real and same ";
        // cout << -(double)b / (2 * a);
        root1 = -(double)b/(2*a);
        root2 = -(double)b/(2*a);
    }

    // d < 0
    else {
        // cout << "Roots are complex ";
        // cout << -(double)b / (2 * a) << " + i"
        //      << sqrt_val / (2 * a) << " "
        //      << -(double)b / (2 * a) << " - i"
        //      << sqrt_val / (2 * a);
        root1 = 1LL;
        root2 = 1LL;
    }
}

long long gcd(long long a, long long b) 
{ 
    // Find Minimum of a and b 
    long long result = min(a, b); 
    while (result > 0) { 
        if (a % result == 0 && b % result == 0) { 
            break; 
        } 
        result--; 
    } 
  
    // Return gcd of a and b 
    return result; 
}





/************************ Main code ************************/


void print(vector<long long>v, string s)
{
    cout << s << " : ";
    for(auto i : v) cout << i << " ";
    cout << endl; 
}
void print(vector<string>v, string s)
{
    cout << s << " :-" << endl;
    for(auto i : v) cout << i << endl;
    cout << endl; 
}

void print(vector<vector<int>>vv, string s)
{;
    cout << s << " :-" << endl;
    for(auto i : vv)
    {
        for(auto j : i) cout << j << " ";
        cout << endl;
    }
}



struct month{

    string name;
    int num;
};


int main() {


#ifndef ONLINE_JUDGE
//for getting input from input.txt
freopen("input.txt", "r", stdin);
//for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
    
int tt;
cin >> tt;
while(tt--){

    int l, r;
    cin >> l >> r;

    int toadd = 0;

    for(int shift = 30; shift >= 0; shift--) {
        int power = 1 << shift;

            // cout << "l : " << l << " power : " << power << " r : " << r << endl;

        if((power <= r)) {

            // cout << "[Hit] l : " << l << " power : " << power << " r : " << r << endl;

            if(l <= power-1){ 

                int third;
                if(l <= power-2) third = power-2;
                else third = power+1;

                cout << (power + toadd) << " " << (power-1 + toadd) << " " << (third + toadd) << endl;
                break;
            }
            else {
                l -= power;
                r -= power;

                toadd += power;
            }
        }
    }
    // cout << "tt : " << tt << endl;
}


return 0;
}











Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
int t;
int main(){
	scanf("%d",&t);
	while(t--){
		int l,r;
		scanf("%d%d",&l,&r);
		int p;
		for(int i = 30;i >= 0;--i)
			if((l & (1 << i)) != (r & (1 << i))){
				p = i;
				break;
			}
		int x = (l >> p) << p;
		int a = x + (1 << p),b = x + (1 << p) - 1;
		if(b == l)
			printf("%d %d %d\n",a,b,r);
		else
			printf("%d %d %d\n",l,a,b);
	}
}