Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#define ll long long
#include "bits/stdc++.h"
using namespace std;
 
int main()
{
   ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int tt ; cin >> tt ;
   while(tt --)
   {
      int l, r ; cin >> l >> r ;
      int a = r, b = l , c = 0 ;
      l ++ , r -- ;
      for(int i = 30 ; i >= 0 ; i --)
      {
        int bita = (a >> i) & 1 , bitb = (b >> i) & 1;
        if(bita == bitb)
        {
          int p = bita ^ 1 ;
          if((c | (p << i)) >= l && (c | (p << i)) <= r)
            c |= (p << i) ;
          else c |= ((p ^ 1) << i) ;
        }
        else
        {
          if((c | (1 << i)) >= l && (c | (1 << i)) <= r)
            c |= (1 << i) ;
        }
      }
      cout << a << ' ' << b << ' ' << c << '\n' ;
   }
   return 0 ;
 }

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

ll inf = 1e18, mod = 1e9 + 7;

ll gcd(ll a, ll b) {
    while (a != 0 && b != 0) {
        if (a > b) {
            a %= b;
        }
        else {
            b %= a;
        }
    }
    return a + b;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

ll binpow(ll base, ll p) {
    if (p == 0) return 1;
    else if (p % 2) return binpow(base, p - 1) * base;
    else return binpow(base, p / 2) * binpow(base, p / 2);
}

void solve() {
    ll l, r;
    cin >> l >> r;
    ll cnt = 1, sz = 1;
    while (cnt * 2 <= r) {
        sz++;
        cnt *= 2;
    }
    cnt = 1;
    ll sz1 = 0;
    while (cnt * 2 <= l) {
        cnt *= 2;
        sz1++;
    }
    vector <int> bit, bit1;
    for (int i = 0; i < sz; ++i) {
        if (r & (1 << i)) bit.pb(1);
        else bit.pb(0);
    }
    ll s = 0;
    for (int i = 0; i < bit.size(); ++i) {
        if (!bit[i]) {
            bit1.pb(1);
            s += (1 << i);
        }    
        else bit1.pb(0);
    }
    if (s >= l) {
        if (s & 1) {
            if (s - 1 < l) {
                cout << r << " " << s << " " << s + 1 << "\n";
            }
            else {
                cout << r << " " << s << " " << s - 1 << "\n";
            }
        }
        else {
            if (s + 1 >= r) {
                cout << r << " " << s << " " << s - 1 << "\n";
            }
            else {
                cout << r << " " << s << " " << s + 1 << "\n";
            }
        }
    }
    else {
        for (int i = sz1; i >= 0; --i) {
            if (!bit1[i] && s + (1 << i) <= r) {
                s += (1 << i);
                if (s >= l) break;
            }
        }
        if (s & 1) {
            if (s - 1 < l) {
                cout << r << " " << s << " " << s + 1 << "\n";
            }
            else {
                cout << r << " " << s << " " << s - 1 << "\n";
            }
        }
        else {
            if (s + 1 >= r) {
                cout << r << " " << s << " " << s - 1 << "\n";
            }
            else {
                cout << r << " " << s << " " << s + 1 << "\n";
            }
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}