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

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename R> using ordered_map = tree<T, R, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>
typedef long long ll;
#define lbv(v, x) (lower_bound((v).begin(), (v).end(), x) - (v).begin())
#define ubv(v, x) (upper_bound((v).begin(), (v).end(), x) - (v).begin())
#define pb push_back
#define loop(i,s,e) for(int i=s;i<e;i++)
#define all(var) (var).begin(), (var).end()


// calculate (a^b)%mod
 int binExp(int long long a,int long long b,int long long mod){
 int long long res=1;
 while(b>0){
 if(b&1){
 res=(res%mod*a%mod)%mod;
 }
 a=(a%mod*a%mod)%mod;
 b>>=1;
 }
 return res;
 }


 int inverse_modulu(int long long a,int long long mod){
 return binExp(a,mod-2,mod);
 }
//indexed_set s;
//s.insert(2);
//auto x = s.find_by_order(2);
//auto x= s.order_of_key(7);

// dfs on matrix
void dfs(vector<vector<char>>&arr,set<pair<int,int>>&s,vector<vector<int>>&vis,int x,int y,char c,int h,int w){
if(x<0 || y<0 || x>=h || y>=w) return;
if(arr[x][y]!=c || vis[x][y]==1) return;
else{
vis[x][y]=1;
s.erase({x,y});
}
dfs(arr,s,vis,x+1,y,c,h,w);
dfs(arr,s,vis,x,y+1,c,h,w);
dfs(arr,s,vis,x-1,y,c,h,w);
dfs(arr,s,vis,x,y-1,c,h,w);
return;
  }
#define int int long long

// DSU(disjoint set Union) declare parent and size vectors in main function
int findparent(int i,vector<int>&parent){
if(parent[i]==i) return i;
return parent[i]=findparent(parent[i],parent);
}


void Union(int u,int v,vector<int>&parent,vector<int>&size){
int pu=findparent(u,parent);
int pv=findparent(v,parent);
if(pu==pv) return;
if(size[pu]<size[pv]){
parent[pu]=pv;
size[pv]+=size[pu];
size[pu]=0;
}
else{
parent[pv]=pu;
size[pu]+=size[pv];
size[pv]=0;
}
}


vector<int> kmp(string s) { 
int n = (int)s.length();
vector<int> pi(n);
for (int i = 1; i < n; i++) { 
int j = pi[i-1];
while (j > 0 && s[i] != s[j])
j = pi[j-1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi;
}

// Improved Sieve 
vector<int> prime;
vector<int> spf;
void sieve(int n)
{
    prime.assign(1, 2);
    spf.assign(n + 1, 2);

    for (int x = 3; x <= n; x += 2)
    {
        if (spf[x] == 2) prime.push_back(spf[x] = x);
        for (int i = 0; i < prime.size() && prime[i] <= spf[x] && prime[i] * x <= n; ++i)
            spf[prime[i] * x] = prime[i];
    }
}


int PRIME = 9973;
int mod= 1e9 + 7;
// Intialise this in function for power array

// vector<int> p_pow(2e5+ 1);
// p_pow[0] = 1;
// for (int i = 1; i <= 2e5; ++i) {
//     p_pow[i] = (p_pow[i - 1]%mod * PRIME%mod) %mod;
// }

vector<int>f_hash(string st,vector<int>&p_pow){// forward hashing
    int n=st.size();
    vector<ll> hash(n + 3,0);
for(int i = 1; i <= n; i++){
    hash[i] = (hash[i - 1]*PRIME + st[i-1] - 'a')%mod;
}
return hash;
}
vector<int>r_hash(string st,vector<int>&p_pow){// Backward hashing
int n=st.size();
vector<int>invhash(n+3,0);
for(int i = n; i >= 1; i--){
    invhash[i] = (invhash[i + 1]*PRIME + st[i-1] - 'a')%mod;
}
return invhash;
}
int get_f_hash(int l, int r,vector<int>&p_pow,vector<int>&hash){
    return (hash[r] - hash[l - 1]*p_pow[r-l+1]%mod + mod)%mod;
}
int get_r_hash(int l, int r,vector<int>&p_pow,vector<int>&invhash){
return (invhash[l] - invhash[r + 1]*p_pow[r-l+1]%mod + mod)%mod;
}


int ncr(int n,int r,vector<int>&fac){
    if(r>n) return 0;
    int nm=(fac[n]%mod*inverse_modulu((fac[r]%mod*fac[n-r]%mod)%mod,mod)%mod)%mod;
    return nm;
}

// Segemnt tree
template<typename Node, typename Update>
struct SegTree {
    vector<Node> tree;
    vector<ll> arr; // type may change
    int n;
    int s;
    SegTree(int a_len, vector<ll> &a) { // change if type updated
        arr = a;
        n = a_len;
        s = 1;
        while(s < 2 * n){
            s = s << 1;
        }
        tree.resize(s); fill(all(tree), Node());
        build(0, n - 1, 1);
    }
    void build(int start, int end, int index)  // Never change this
    {
    if (start == end)	{
        tree[index] = Node(arr[start]);
        return;
    }
        int mid = (start + end) / 2;
        build(start, mid, 2 * index);
        build(mid + 1, end, 2 * index + 1);
    tree[index].merge(tree[2 * index], tree[2 * index + 1]);
    }
void update(int start, int end, int index, int query_index, Update &u)  // Never Change this
    {
        if (start == end) {
            u.apply(tree[index]);
        return;
        }
        int mid = (start + end) / 2;
        if (mid >= query_index)
            update(start, mid, 2 * index, query_index, u);
        else
            update(mid + 1, end, 2 * index + 1, query_index, u);
        tree[index].merge(tree[2 * index], tree[2 * index + 1]);
    }
    Node query(int start, int end, int index, int left, int right) { // Never change this
        if (start > right || end < left)
            return Node();
        if (start >= left && end <= right)
            return tree[index];
        int mid = (start + end) / 2;
        Node l, r, ans;
        l = query(start, mid, 2 * index, left, right);
        r = query(mid + 1, end, 2 * index + 1, left, right);
        ans.merge(l, r);
        return ans;
    }
    void make_update(int index, ll val) {  // pass in as many parameters as required
        Update new_update = Update(val); // may change
        update(0, n - 1, 1, index, new_update);
    }
    Node make_query(int left, int right) {
        return query(0, n - 1, 1, left, right);
    }
};

struct Node {
    ll ans; // may change
    ll mx,mn;
    Node() { // Identity element
        ans = 0;	// may change
        mx=-1e15,mn=1e15;
    }
    Node(ll p1) {  // Actual Node
        ans=0; // may change
        mx=p1,mn=p1;
    }
    void merge(Node &l, Node &r) { // Merge two child nodes
        ans=max({l.ans,r.ans,r.mx-l.mn});
        mx=max(l.mx,r.mx);
        mn=min(l.mn,r.mn);
    }
};
struct Update {
    ll ans; // may change
    ll mx,mn;
    Update(ll p1) { // Actual Update
        ans=0; // may change
        mx=p1,mn=p1;
    }
    void apply(Node &a) { // apply update to given node
        a.ans=ans; // may change
        a.mx=mx,a.mn=mn;
    }
};
vector<int>tin,tout,eul;
void euler_tour(int i,vector<vector<int>>&vv,vector<int>&a,int &tm,int p){
    tin[i]=tm++;
    eul.push_back(0);
    for(auto x:vv[i]){
        if(x!=p) euler_tour(x,vv,a,tm,i);
    }
    eul.push_back(0);
    tout[i]=tm++;
}

 int32_t main()
 {
ios::sync_with_stdio(0), cin.tie(0);
 int t;cin>>t;
 while(t--){
    int l,r;cin>>l>>r;
    vector<int>v(3);
    int fg=0,tr=0;
    for(int j=30;j>=0;j--){
        int lbt=((l>>j)&1);
        int rbt=((r>>j)&1);
        if(fg==0){
            if(lbt==rbt) v[tr%3]+=(1<<j)*lbt,v[(tr+1)%3]+=(1<<j)*lbt,v[(tr+2)%3]+=(1<<j)*lbt;
            else{
                v[2]+=(1<<j);
                fg=1;
            }
        }
        else{
            v[tr]+=(1<<j);
            tr^=1;
        }
    }
    cout<<v[0]<<" "<<v[1]<<" "<<v[2]<<endl;
 }
 return 0;
}


Submission (verdict: Accepted):
#include<iostream>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename R> using ordered_map = tree<T, R, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>
typedef long long ll;
#define lbv(v, x) (lower_bound((v).begin(), (v).end(), x) - (v).begin())
#define ubv(v, x) (upper_bound((v).begin(), (v).end(), x) - (v).begin())
#define pb push_back
#define loop(i,s,e) for(int i=s;i<e;i++)
#define all(var) (var).begin(), (var).end()


// calculate (a^b)%mod
 int binExp(int long long a,int long long b,int long long mod){
 int long long res=1;
 while(b>0){
 if(b&1){
 res=(res%mod*a%mod)%mod;
 }
 a=(a%mod*a%mod)%mod;
 b>>=1;
 }
 return res;
 }


 int inverse_modulu(int long long a,int long long mod){
 return binExp(a,mod-2,mod);
 }
//indexed_set s;
//s.insert(2);
//auto x = s.find_by_order(2);
//auto x= s.order_of_key(7);

// dfs on matrix
void dfs(vector<vector<char>>&arr,set<pair<int,int>>&s,vector<vector<int>>&vis,int x,int y,char c,int h,int w){
if(x<0 || y<0 || x>=h || y>=w) return;
if(arr[x][y]!=c || vis[x][y]==1) return;
else{
vis[x][y]=1;
s.erase({x,y});
}
dfs(arr,s,vis,x+1,y,c,h,w);
dfs(arr,s,vis,x,y+1,c,h,w);
dfs(arr,s,vis,x-1,y,c,h,w);
dfs(arr,s,vis,x,y-1,c,h,w);
return;
  }
#define int int long long

// DSU(disjoint set Union) declare parent and size vectors in main function
int findparent(int i,vector<int>&parent){
if(parent[i]==i) return i;
return parent[i]=findparent(parent[i],parent);
}


void Union(int u,int v,vector<int>&parent,vector<int>&size){
int pu=findparent(u,parent);
int pv=findparent(v,parent);
if(pu==pv) return;
if(size[pu]<size[pv]){
parent[pu]=pv;
size[pv]+=size[pu];
size[pu]=0;
}
else{
parent[pv]=pu;
size[pu]+=size[pv];
size[pv]=0;
}
}


vector<int> kmp(string s) { 
int n = (int)s.length();
vector<int> pi(n);
for (int i = 1; i < n; i++) { 
int j = pi[i-1];
while (j > 0 && s[i] != s[j])
j = pi[j-1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi;
}

// Improved Sieve 
vector<int> prime;
vector<int> spf;
void sieve(int n)
{
    prime.assign(1, 2);
    spf.assign(n + 1, 2);

    for (int x = 3; x <= n; x += 2)
    {
        if (spf[x] == 2) prime.push_back(spf[x] = x);
        for (int i = 0; i < prime.size() && prime[i] <= spf[x] && prime[i] * x <= n; ++i)
            spf[prime[i] * x] = prime[i];
    }
}


int PRIME = 9973;
int mod= 1e9 + 7;
// Intialise this in function for power array

// vector<int> p_pow(2e5+ 1);
// p_pow[0] = 1;
// for (int i = 1; i <= 2e5; ++i) {
//     p_pow[i] = (p_pow[i - 1]%mod * PRIME%mod) %mod;
// }

vector<int>f_hash(string st,vector<int>&p_pow){// forward hashing
    int n=st.size();
    vector<ll> hash(n + 3,0);
for(int i = 1; i <= n; i++){
    hash[i] = (hash[i - 1]*PRIME + st[i-1] - 'a')%mod;
}
return hash;
}
vector<int>r_hash(string st,vector<int>&p_pow){// Backward hashing
int n=st.size();
vector<int>invhash(n+3,0);
for(int i = n; i >= 1; i--){
    invhash[i] = (invhash[i + 1]*PRIME + st[i-1] - 'a')%mod;
}
return invhash;
}
int get_f_hash(int l, int r,vector<int>&p_pow,vector<int>&hash){
    return (hash[r] - hash[l - 1]*p_pow[r-l+1]%mod + mod)%mod;
}
int get_r_hash(int l, int r,vector<int>&p_pow,vector<int>&invhash){
return (invhash[l] - invhash[r + 1]*p_pow[r-l+1]%mod + mod)%mod;
}


int ncr(int n,int r,vector<int>&fac){
    if(r>n) return 0;
    int nm=(fac[n]%mod*inverse_modulu((fac[r]%mod*fac[n-r]%mod)%mod,mod)%mod)%mod;
    return nm;
}

// Segemnt tree
template<typename Node, typename Update>
struct SegTree {
    vector<Node> tree;
    vector<ll> arr; // type may change
    int n;
    int s;
    SegTree(int a_len, vector<ll> &a) { // change if type updated
        arr = a;
        n = a_len;
        s = 1;
        while(s < 2 * n){
            s = s << 1;
        }
        tree.resize(s); fill(all(tree), Node());
        build(0, n - 1, 1);
    }
    void build(int start, int end, int index)  // Never change this
    {
    if (start == end)	{
        tree[index] = Node(arr[start]);
        return;
    }
        int mid = (start + end) / 2;
        build(start, mid, 2 * index);
        build(mid + 1, end, 2 * index + 1);
    tree[index].merge(tree[2 * index], tree[2 * index + 1]);
    }
void update(int start, int end, int index, int query_index, Update &u)  // Never Change this
    {
        if (start == end) {
            u.apply(tree[index]);
        return;
        }
        int mid = (start + end) / 2;
        if (mid >= query_index)
            update(start, mid, 2 * index, query_index, u);
        else
            update(mid + 1, end, 2 * index + 1, query_index, u);
        tree[index].merge(tree[2 * index], tree[2 * index + 1]);
    }
    Node query(int start, int end, int index, int left, int right) { // Never change this
        if (start > right || end < left)
            return Node();
        if (start >= left && end <= right)
            return tree[index];
        int mid = (start + end) / 2;
        Node l, r, ans;
        l = query(start, mid, 2 * index, left, right);
        r = query(mid + 1, end, 2 * index + 1, left, right);
        ans.merge(l, r);
        return ans;
    }
    void make_update(int index, ll val) {  // pass in as many parameters as required
        Update new_update = Update(val); // may change
        update(0, n - 1, 1, index, new_update);
    }
    Node make_query(int left, int right) {
        return query(0, n - 1, 1, left, right);
    }
};

struct Node {
    ll ans; // may change
    ll mx,mn;
    Node() { // Identity element
        ans = 0;	// may change
        mx=-1e15,mn=1e15;
    }
    Node(ll p1) {  // Actual Node
        ans=0; // may change
        mx=p1,mn=p1;
    }
    void merge(Node &l, Node &r) { // Merge two child nodes
        ans=max({l.ans,r.ans,r.mx-l.mn});
        mx=max(l.mx,r.mx);
        mn=min(l.mn,r.mn);
    }
};
struct Update {
    ll ans; // may change
    ll mx,mn;
    Update(ll p1) { // Actual Update
        ans=0; // may change
        mx=p1,mn=p1;
    }
    void apply(Node &a) { // apply update to given node
        a.ans=ans; // may change
        a.mx=mx,a.mn=mn;
    }
};
vector<int>tin,tout,eul;
void euler_tour(int i,vector<vector<int>>&vv,vector<int>&a,int &tm,int p){
    tin[i]=tm++;
    eul.push_back(0);
    for(auto x:vv[i]){
        if(x!=p) euler_tour(x,vv,a,tm,i);
    }
    eul.push_back(0);
    tout[i]=tm++;
}

 int32_t main()
 {
ios::sync_with_stdio(0), cin.tie(0);
 int t;cin>>t;
 while(t--){
    int l,r;cin>>l>>r;
    vector<int>v(3);
    int fg=0,tr=0;
    for(int j=30;j>=0;j--){
        int lbt=((l>>j)&1);
        int rbt=((r>>j)&1);
        if(lbt==rbt) v[0]+=(1<<j)*lbt;
        else{
            v[0]+=(1<<j);
            break;
        }
    }
    v[1]=v[0]-1;
    if(l<=v[0]-2) v[2]=v[0]-2;
    else v[2]=v[0]+1;
    cout<<v[0]<<" "<<v[1]<<" "<<v[2]<<endl;
 }
 return 0;
}