#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define vi vector<int>
#define inp for(int i=0;i<n;i++) cin>>arr[i]
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vpii vector<pii >
#define mp make_pair
#define f first
#define s second

const int MOD = 1e9 + 7;
const int INF = 1e9;

// Function to print a vector
template <typename T>
void printVector(const vector<T>& v) {
    for (const auto& element : v) {
        cout << element << ' ';
    }
    cout << endl;
}

// Function to print a set
template <typename T>
void printSet(const set<T>& s) {
    for (const auto& element : s) {
        cout << element << ' ';
    }
    cout << endl;
}

// Function to print a map
template <typename K, typename V>
void printMap(const map<K, V>& m) {
    for (const auto& [key, value] : m) {
        cout << key << " -> " << value << endl;
    }
}
void func(int a,int b,int c){
    cout<<(a^b)+(b^c)+(c^a)<<endl;
}
void solve() {
    // Write your code here
    int l,r;
    cin>>l>>r;
    int msd = log2(r);
    vector<int> a1,a2;
    for(int i=msd ;i>=0;i--){
        if(l & (1LL << i)){
            a1.pb(1);
        }
        else a1.pb(0);
        if(r & (1LL << i)){
            a2.pb(1);
        }
        else a2.pb(0);
    }
    int num = 0;
    reverse(all(a1));
    reverse(all(a2));
    bool flag = true,flag2 = true;
    for(int i=msd;i>=0;i--){
        if(a1[i] == a2[i] && flag){
            num += (1LL << i)*a1[i];
        }
        else{
            if(flag){
                // num += (1LL << i);
                flag = false;
            }
            else{
                if(a1[i] == 0 && flag2){
                    num += (1LL << i);
                    flag2 = false;
                    continue;
                }
                if(a1[i] != a2[i] || a1[i] == 0 && a2[i] == 0)
                num += (1LL << i);
            }
        }
        // if(i == msd && a1[i] == a2[i] && a1[i] == 1){
        //     num = l;
        //     break;
        // }
        // else if(a1[i] == a2[i] && a1[i] == 0) num += (1LL << i);
        // else if(a1[i] != a2[i]) num += (1LL << i);
        // cout<<i<<" - "<<num<<" ";
    }
    // cout<<endl;
    // printVector(a1);
    // printVector(a2);
    // cout<<msd<<"->";
    cout<<l<<" "<<r<<" "<<num<<endl;
    // func(134, 132, 137);
    // func(128, 137, 135);
}

signed main() {
    fastio;
    int t = 1;
    cin >> t; // Uncomment if multiple test cases
    while (t--) {
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

void solution() {
    int l, r;
    cin >> l >> r;
    int x = (l ^ r);
    int ind = 0;
    while(pow(2, ind) <= x)ind++; // 16 8 4 2 0
    // cout << ind << endl;
    --ind;
    int y = pow(2, ind);
    int a = (l | (y - 1) );
    int b = a + 1;
    int c = l;
    if(a == l)c = r;
    cout << a << " " << b << " " << c << endl;

}

int main() {

    int t;
    cin >> t;
    while(t--) {
        solution();
    }
}

Answer: 1


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace chrono;

using namespace __gnu_pbds;

template<typename T>
using orderedSet = tree<T , null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using orderedMultiset = tree<T , null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) -> iterator at k
// order_of_key(k) -> number of items that are strictly smaller than k

#define FASTIO() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD1 1000000007
#define MOD9 998244353
#define INF 1e9
#define INF1 1e18
#define endl "\n"
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define ub upper_bound
#define fcout cout<<fixed<<setprecision(10)
#define YES  cout<<"YES"<<endl
#define NO cout<<"NO"<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

// ---------------------------------- DEFINES ---------------------------------------
typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vector <int> > vvi;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using QP = priority_queue<T, vector<T>, greater<T>>;
// ----------------------------------------------------------------------------------

// ---------------------------------- OPERATOR OVERLOADING ---------------------------------------
template<typename T>
istream& operator>>(istream &istream, vector<T> &v) {for (auto &x : v)cin >> x; return istream;}
template<typename T>
ostream& operator<<(ostream &ostream, const vector<T> &v) { for (auto &x : v) cout << x << " "; return ostream; }
template<typename T1, typename T2>
istream& operator>>(istream &istream, pair<T1, T2> &p) { return (istream >> p.ff >> p.ss); }
template<typename T1, typename T2>
ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) { return (ostream << p.ff << " " << p.ss); }
template<typename T1, typename T2>
istream& operator>>(istream &istream, vector<pair<T1, T2>> &v) {for (auto &x : v)cin >> x; return istream;}
template<typename T1, typename T2>
ostream& operator<<(ostream &ostream, const vector<pair<T1, T2>> &v) { for (auto &x : v) cout << x << endl; return ostream; }
template<typename T>
istream& operator>>(istream &istream, vector<vector<T>> &v) {for (auto &x : v)cin >> x; return istream;}
template<typename T>
ostream& operator<<(ostream &ostream, const vector<vector<T>> &v) { for (auto &x : v) cout << x << endl; return ostream; }
// ------------------------------------------------------------------------------------------------

// ------------------------------------------ DEBUG ------------------------------------------------
#ifndef ONLINE_JUDGE
#define debug(x...) cerr <<__func__<<":"<<__LINE__<<" [" << #x << "] = "; _print(x); cerr << endl;
#define HERE cerr <<__func__<<":"<<__LINE__<<" [ here ] "; cerr << endl;
#else
#define debug(x...)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(vector <vector <T> > v) {cerr << "{ "; for (vector<T> i : v) {cerr << "[ "; for (T j : i) {_print(j); cerr << " ";}; cerr << "] ";} cerr << "}";}
template <class T, class V> void _print(vector < pair <T , V> > vp) {cerr << "{ "; for (pair<T, V> i : vp) {cerr << "[ "; "{"; _print(i.ff); cerr << ","; _print(i.ss); cerr << " ] ";} cerr << "}";}
template <class T> void _print(stack <T> st) {cerr << "[ "; while (!st.empty()) {_print(st.top()); st.pop(); cerr << " ";} cerr << "]";}
template <class T> void _print(queue <T> q) {cerr << "[ "; while (!q.empty()) {_print(q.front()); q.pop(); cerr << " ";} cerr << "]";}
template <class T> void _print(deque <T> dq) {cerr << "[ "; while (!dq.empty()) {_print(dq.front()); dq.pop_front(); cerr << " ";} cerr << "]";}
template <class T> void _print(PQ <T> pq) {cerr << "[ "; while (!pq.empty()) {_print(pq.top()); pq.pop(); cerr << " ";} cerr << "]";}
template <class T> void _print(QP <T> pq) {cerr << "[ "; while (!pq.empty()) {_print(pq.top()); pq.pop(); cerr << " ";} cerr << "]";}
//---------------------------------------------------------------------------------------------------

void solve() {

    //solution starts from here
    ll l, r;
    cin >> l >> r;
    int mx = 0;
    for (int i = 0; i < 32; i++) {
            if ((r & (1LL << i)) && (l & (1LL << i)) == 0) mx = i;
    }
    int a = 0;
    for (int i = mx; i < 32; i++) {
            a |= ((1LL << i) & r);
    }
    debug(2*(a^(a-1)))
    cout << a << " " << a - 1 << " " << a<< endl;
}

int main() {

#ifndef ONLINE_JUDGE
    freopen("error.txt", "w", stderr);
#endif

    FASTIO();
    auto start1 = high_resolution_clock::now();
    int t = 1;
    cin >> t;
    int T = t;
    while (t--)
    {
       #ifndef ONLINE_JUDGE
        cerr<<"Test "<<(T-t)<<" :"<<endl;
       #endif
       solve();
       #ifndef ONLINE_JUDGE
        cerr<<"--------------------------"<<endl<<endl;
       #endif
    }
    auto stop1 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop1 - start1);
#ifndef ONLINE_JUDGE
    cerr << "Time elapsed : " << (duration . count() / 1000000) << '.' << (duration . count() % 1000000) << endl;
#endif

}

#include<bits/stdc++.h>
#define int long long
using namespace std;

void Solve()
{

    int a, b;
    cin >> a >> b;
if(a > b) swap(a,b);
bitset<52> bitsA(a);
bitset<52> bitsB(b);
string sA;
string sB;
int index = -1;
for(int i = 51 ; i >= 0 ; i--){
    if(bitsA[i] != bitsB[i]){
        index = i;
        break;
    }
}
string ans;

for(int i = index - 1 ; i >= 0 ; i--){
    if(bitsA[i] == bitsB[i] && bitsA[i] == '0'){
        index = i;
        ans += '1';
        break;
    }
    else{
        if (bitsA[i] != bitsB[i]) ans += '1';
        else ans += '0';
    }
}

for(int i = index ; i >= 0 ; i--){
    sA += bitsA[i] + '0';
    sB += bitsB[i] + '0';
    ans += !(bitsA[i] & bitsB[i]) + '0';
}

ans[0] = '0';
if(ans > sA){

}
else{
    ans[0] = '1';
}

bitset<52> bitsC(a);

for(int i = 0 ; i <= index ; i++){
    bitsC[i] = ans[index - i] -'0';
}
cout<<a<<" "<<bitsC.to_ullong()<< " " <<b<<endl;

}

int32_t main(){

   int t;
   cin >> t;
   for(int i = 0 ; i <t ; i++){
    Solve();
   }
}

Answer: 1


Answer: 1


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> //ÓÃtree
using namespace std;
namespace pbds = __gnu_pbds;
template<typename T>
using pbdstree = pbds::tree<T,pbds::null_type,less<T>,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
#define int long long
using ll = long long;
template <typename T>
using Qmin = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using Qmax = priority_queue<T>;
#define rep(i, a, b) for(int i = a; i <= (b); ++i)
#define frep(i, a, b) for(int i = a; i < (b); ++i)
#define drep(i, a, b) for(int i = a; i >= (b); --i)
// #define ls (p << 1)
// #define rs (p << 1 | 1)
// #define mid ((l + r) >> 1)
const int MAXN = 200010;
const int MOD = 998244353;
// const int INF = 0x3f3f3f3f;
const int INF = 1e15;
int get(int x, int k){
    return (x >> k) & 1;
}
void solve(){
    int l, r;
    cin >> l >> r;
    int ans = 0;
    int i = 30;
    while(i >= 0){
        if(get(l, i) != get(r, i)) break;
        --i;
    }
    int x = (r >> i) << i;
    int y = x - 1;
    int z = x == r ? y - 1 : x + 1;
    cout << x << " " << y << " " << z << endl;
    return;
}
signed main(){
    // cout << (965321865 ^ 375544086) + (965321865 ^ 12551794) + (375544086 ^ 12551794) << endl;
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int _t = 1;
    cin >> _t;
    while(_t--){
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> //ÓÃtree
using namespace std;
namespace pbds = __gnu_pbds;
template<typename T>
using pbdstree = pbds::tree<T,pbds::null_type,less<T>,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
#define int long long
using ll = long long;
template <typename T>
using Qmin = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using Qmax = priority_queue<T>;
#define rep(i, a, b) for(int i = a; i <= (b); ++i)
#define frep(i, a, b) for(int i = a; i < (b); ++i)
#define drep(i, a, b) for(int i = a; i >= (b); --i)
// #define ls (p << 1)
// #define rs (p << 1 | 1)
// #define mid ((l + r) >> 1)
const int MAXN = 200010;
const int MOD = 998244353;
// const int INF = 0x3f3f3f3f;
const int INF = 1e15;
int get(int x, int k){
    return (x >> k) & 1;
}
void solve(){
    int l, r;
    cin >> l >> r;
    int ans = 0;
    int i = 30;
    while(i >= 0){
        if(get(l, i) != get(r, i)) break;
        --i;
    }
    r = (r >> i) << i;
    l = l + (1 << i) - 1;
    cout << r << " " << r << " " << l << endl;
    return;
}
signed main(){
    // cout << (965321865 ^ 375544086) + (965321865 ^ 12551794) + (375544086 ^ 12551794) << endl;
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int _t = 1;
    cin >> _t;
    while(_t--){
        solve();
    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;

#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef unordered_map<ll, ll> umpl;
typedef unordered_map<int, int> umpi;
typedef map<ll, ll> mpl;
typedef map<int, int> mpi;
typedef priority_queue<ll> pql;
typedef priority_queue<int> pqi;
typedef priority_queue<ll, vector<ll>, greater<ll>> minpql;
typedef priority_queue<int, vector<int>, greater<int>> minpqi;
typedef stack<ll> stl;
typedef stack<int> sti;
const ll mod = 1'000'000'007;
const ll N = 3e5, M = N;
vpii dir = {{1,0},{-1,0},{0,1},{0,-1}};
vpii dir1 = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,-1},{1,-1},{-1,1}};
//=======================

vi g[N];

ll logB2(ll n)
{
    ll count=0;
    while (n>0)
    {
        n/=2;
        count++;
    }
    return count;
}

ll XNOR(ll a, ll b)
{
	ll numOfBits = logB2(max(a, b));
	ll mask = (1 << numOfBits) - 1;
	ll xnor = ~(a ^ b);
	return xnor & mask;
}
void solve()
{
    ll n, i, j, k, m;
    ll l,r;
    cin>>l>>r;
    ll a=l;
    ll b=r;
    ll count=0;
    while (a!=b)
    {
        a/=2;
        b/=2;
        count++;
    }
    ll num=a;
    num=num<<count;
    num=num|(1<<(count-1));
    if(num-2<l)
    {
        cout<<num<<" "<<num-1<<" "<<num+1<<endl;
    }
    else
    {
        cout<<num<<" "<<num-1<<" "<<num-2<<endl;
    }

}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    ll t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    // solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef unordered_map<ll, ll> umpl;
typedef unordered_map<int, int> umpi;
typedef map<ll, ll> mpl;
typedef map<int, int> mpi;
typedef priority_queue<ll> pql;
typedef priority_queue<int> pqi;
typedef priority_queue<ll, vector<ll>, greater<ll>> minpql;
typedef priority_queue<int, vector<int>, greater<int>> minpqi;
typedef stack<ll> stl;
typedef stack<int> sti;
const ll mod = 1'000'000'007;
const ll N = 3e5, M = N;
vpii dir = {{1,0},{-1,0},{0,1},{0,-1}};
vpii dir1 = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,-1},{1,-1},{-1,1}};
//=======================

vi g[N];

ll logB2(ll n)
{
    ll count=0;
    while (n>0)
    {
        n/=2;
        count++;
    }
    return count;
}

ll XNOR(ll a, ll b)
{
	ll numOfBits = logB2(max(a, b));
	ll mask = (1 << numOfBits) - 1;
	ll xnor = ~(a ^ b);
	return xnor & mask;
}
void solve()
{
    ll n, i, j, k, m;
    ll l,r;
    cin>>l>>r;
    // if(temp+1 <=r)
    // {
    //     if(temp-1>=l)
    //     {
    //         // cout<<temp<<" "<<r<<" "<<temp-1<<endl;
    //         // cout<<temp<<" "<<temp+1<<" "<<temp-1<<endl;
    //         // cout<<(temp^(temp+1)+((temp-1)^(temp+1))+(temp^(temp-1)))<<endl;
    //         ll a=temp;
    //         ll b=temp-1;
    //         // ll c=temp+1;
    //         ll c=r;
    //         cout<<(a^b) + (b^c) + (c^a)<<endl;
    //     }
    //     else
    //     {
    //         cout<<temp<<" "<<temp+1<<" "<<temp+2<<endl;
    //         // cout<<(temp^(temp+1)+((temp-1)^(temp+1))+(temp^(temp-1)))<<endl;
    //         ll a=temp;
    //         ll b=temp+2;
    //         ll c=temp+1;
    //         cout<<(a^b) + (b^c) + (c^a)<<endl;

    //     }

    // }

    // else
    // {
    //     cout<<temp<<" "<<temp-2<<" "<<temp-1<<endl;
    //     cout<<(temp^(temp-2)+((temp-1)^(temp-2))+(temp^(temp-1)))<<endl;
    // }
    // ll a=134;
    // ll b=132;
    // ll c=137;
    // 98 85 76
    // ll a=7;
    // ll b=16;
    // ll c=11;
    // cout<<(a^b) + (b^c) + (c^a)<<endl;
    // a=22;
    // b=6;
    // c=9;
    // cout<<(a^b) + (b^c) + (c^a)<<endl;
    // ll num=l^r;
    // if(num>=r)
    // {
    //     num/=2;
    // }
    // if(num<=l)
    // {
    //     num*=2;
    // }
    // // ll temp=logB2(l);
    // // temp=pow(2, (temp-1));
    // // num=temp;
    // // if(num==r)
    // // {
    // //     num/=2;
    // // }
    // ll f=l;
    // ll s=r;
    // // // cout<<num<<endl;
    // // ll count=0;
    // // while (l>0 || r>0)
    // // {
    // //     ll bit1=l&1;
    // //     ll bit2=r&1;
    // //     l=l/2;
    // //     r=r/2;
    // //     if(r==0 && l==0 )
    // //     {
    // //         break;
    // //     }
    // //     if(bit1==bit2)
    // //     {
    // //         if(bit1==0)
    // //         {
    // //             num=num|(1<<count);
    // //         }
    // //     }
    // //     count++;
    // // }
    // cout<<f<<" "<<s<<" "<<num<<endl;

    // ll a=7;
    // ll b=16;
    // ll c=11;
    // // cout<<(a^b) + (b^c) + (c^a)<<endl;
    // ll num=XNOR(l,r);
    // if(num>=r)
    // {
    //     num/=2;
    // }
    // if(num<=l)
    // {
    //     num*=2;
    // }
    // cout<<num<<" "<<l<<" "<<r<<endl;
    // ll a=2;
    // ll b=8;
    // ll c=7;
    // cout<<(a^b) + (b^c) + (c^a)<<endl;
    ll temp=logB2(r);
    ll temp1=temp;
    temp1--;
    temp=pow(2, (temp-1));
    ll num=temp;
    // cout<<num<<endl;
    if(num<=r-1 && num>=l+1)
    {
        cout<<num-1<<" "<<num<<" "<<num+1<<endl;
        return;
    }
    if(num==r)
    {
        cout<<num<<" "<<num-1<<" "<<num-2<<endl;
        return;
    }
    if(num<=l)
    {
        while (1)
        {
            ll newNum=num;
            newNum=newNum|(1<<temp1);
            if(newNum<=r-1 && newNum>=l+1)
            {
                cout<<newNum-1<<" "<<newNum<<" "<<newNum+1<<endl;
                return;
            }
            if(newNum==r)
            {
                cout<<newNum<<" "<<newNum-1<<" "<<newNum-2<<endl;
                return;
            }
            num=newNum;
            // cout<<num<<endl;
            temp1--;
            if(temp1<0)
            {
                break;
            }
        }

    }

}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    ll t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    // solve();
    return 0;
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int l,r;
cin>>l>>r;
int temp=l^r;
int cnt=0;
while(temp!=0){temp>>=1;cnt++;}
cnt--;
//most significant differing in l,r bit is off
int a=((1ll<<cnt)-1)|l; // xor with l to make it atleast l to keep "a" within range
// most significant differing bit in l,r is on
int b=a+1; // since r-l>1 b is always valid
int c=(a==l?r:l); // if a is l then b=l+1 so c can be from l+2 as r-l>1
cout<<a<<" "<<b<<" "<<c<<endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while (t--) {
        solve();
    }
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int l,r;
cin>>l>>r;
int temp=r;
int cnt=0;
while(temp!=0){temp>>=1;cnt++;}
cnt--;
int a=1ll<<cnt;
int b=a-1;
int c=(a==r?l:r); //since l-r>1
cout<<a<<" "<<b<<" "<<c<<endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while (t--) {
        solve();
    }
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

#define int long long

int msb(int n) {

    // calculate the  number
    // of leading zeroes
    int k = __builtin_clz(n);

    // To return the value
    // of the number with set
    // bit at (31 - k)-th position
    // assuming 32 bits are used
    return 1 << (31 - k);
}

void solve() {
    int l, r, r1;
    cin >> l >> r, r1 = r;
    while (true) {
        if (msb(l) != msb(r)) {
            int a, b, c;
            for (int i = 0; i < 35; ++i) {
                if ((msb(r) <= (1ll << i)) && (r1 & (1ll << i))) {
                    int x = r1 & ((1ll << (i + 1)) - 1);
                    a = (r1 - x + msb(r)), b = a - 1, c = (a == r1 ? a - 2 : r1);
                    break;
                }
            }
            cout << a << ' ' << b << ' ' << c;
            return;
        }
        r ^= msb(r);
        l ^= msb(l);
    }

}

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

#include <bits/stdc++.h>

using namespace std;

#define int long long

int msb(int n) {

    // calculate the  number
    // of leading zeroes
    int k = __builtin_clz(n);

    // To return the value
    // of the number with set
    // bit at (31 - k)-th position
    // assuming 32 bits are used
    return 1 << (31 - k);
}

void solve() {
    int l, r, r1;
    cin >> l >> r, r1 = r;
    while (true) {
        if (msb(l) != msb(r)) {
            int a, b, c;
            for (int i = 0; i < 35; ++i) {
                if ((msb(r) <= (1ll << i)) && (r1 & (1ll << i))) {
                    a = (r1 - (1ll << i) + msb(r)), b = a - 1, c = (a == r1 ? a - 2 : r1);
                    break;
                }
            }
            cout << a << ' ' << b << ' ' << c;
            return;
        }
        r ^= msb(r);
        l ^= msb(l);
    }

}

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

Answer: 1


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <chrono>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define fin cin
#define fout cout
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
#define all(x) x.begin(), x.end()
#define left esquerda
#define lb lower_bound
#define right direita
using namespace std;
void setIO(string s) {
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str( ),"w",stdout);
}
typedef pair<ll, ll> pii;
typedef vector<vector<char>> mat;
typedef pair<int, string> pis;
const ll mod = 1e9 + 7, MAXN = 2e5 + 5;
typedef vector<int> vi;
typedef pair<int, pair<int, int>> piii;

void solve() {
    ll l, r;
    cin >> l >> r;

    ll last = 1;
    while(last * 2 <= r)
        last *= 2;

    int aux = last;
    while(true) {
        if( (last & r) && !(last & l)) {
            aux += last;
            break;
        }
        last /= 2;
    }

    cout << aux-1 << " " << aux << " " << aux + 2 << endl;

}

int32_t main() {
    int ct;
    cin >> ct;
    while(ct--)
        solve();
}

#include<bits/stdc++.h>
using namespace std;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

ll gcd(ll a, ll b){
    return (b==0)?a:gcd(b, a%b);
}

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

void solve(){
    ll l, r;
    cin >> l >> r;

    ll a=0, b=0, c=l;
    for( ll i=29; i>=0; i-- ){
        if( (l & (1<<i)) == (r & (1<<i)) ){
            a ^= (l & (1<<i));
            b ^= (l & (1<<i));
        }
        else{
            a ^= (1<<i);
            b ^= (1<<i)-1;
            break;
        }
    }

    for( ll i=l; i<=r; i++ ){
        if( (i != a) && (i != b) ){
            c = i;
            break;
        }
    }
    cout << a << " " << b << " " << c << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("error.txt" , "w" , stderr );
    freopen("input.txt", "r" , stdin );
    freopen("output.txt", "w" , stdout );
#endif

    int t = 1;
    cin >> t;
    for ( int i = 0; i < t; i++ )
        solve();
    return 0;
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t; cin >> t;
    while(t--) {
        int l, r; cin >> l >> r;

        int a=0, b=0, c=0, k=0;
        for(int i=30;i>=0;i--) {
            if((l&(1LL<<i))!=(r&(1LL<<i))) {
                // cout << (l&(1LL<<i)) << " " << (r&(1LL<<i)) << endl;
                a=k+(1LL<<i);
                b=a-1;
                break;
            } else {
                k+=(l&(1<<i)&&1)*(1LL<<i);
            }
        }

        for(c=l;c<=r&&(c==a||c==b);c++);
        cout << a << " " << b << " " << c << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t; cin >> t;
    while(t--) {
        int l, r; cin >> l >> r;

        int a=0, b=0, c=0, k=0;
        for(int i=30;i>=0;i--) {
            if((l&(1LL<<i))!=(r&(1LL<<i))) {
                a=k+(1LL<<i);
                b=a-1;
                break;
            } else {
                k=(l&(1<<i)&&1)*(1LL<<i);
            }
        }

        for(c=l;c<=r&&(c==a||c==b);c++);
        cout << a << " " << b << " " << c << endl;
    }
}

Answer: 1


#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    int l, r;
    std::cin >> l >> r;

    int a = l, c = r, b = 0;
    int pos;
    for (int i = 31; i >= 0; i --) {
        int x = a >> i & 1;
        int y = c >> i & 1;
        if (x ^ y) {
            pos = i;
            break;
        }
    }

    for (int i = 31; i > pos; i --) {
        int x = a >> i & 1;
        b += x * 1 << i;
    }

    for (int i = pos; i >= 0; i --) {
        int x = a >> i & 1;
        int y = c >> i & 1;
        if (x ^ y == 0) {
            b += (!x) << i;
        }
    }

    for (int i = pos; i >= 0; i --) {
        int x = a >> i & 1;
        int y = c >> i & 1;
        if (x ^ y) {
            if (b + (1 << i) < c) {
                b += 1 << i;
            }
        }
    }

    std::cout << a << " " << b << " " << c << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(20);

    int T = 1;
    std::cin >> T;

    while (T --) {
        solve();
    }

    return 0;
}

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    i64 l, r;
    std::cin >> l >> r;

    i64 a = l, c = r, b = 0;
    int pos;
    for (int i = 32; i >= 0; i --) {
        int x = a >> i & 1;
        int y = c >> i & 1;
        if (x ^ y) {
            pos = i;
            break;
        }
    }

    for (int i = 32; i > pos; i --) {
        int x = a >> i & 1;
        b += x << i;
    }

    for (int i = pos; i >= 0; i --) {
        int x = a >> i & 1;
        int y = c >> i & 1;
        if (x ^ y) {
            if (b + (1 << i) < c) {
                b += 1ll << i;
            }
        } else {
            b += (!x) * 1ll << i;
        }
    }

    std::cout << a << " " << b << " " << c << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(20);

    int T = 1;
    std::cin >> T;

    while (T --) {
        solve();
    }

    return 0;
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define pb push_back

const int maxn = 2e5 + 10;
int l, r;

void solve(){
    cin>>l>>r;
    int a = 0;
    int b = 0;
    int c = 0;
    for(int i = 29; i >= 0; i--){
        if((1 << i) > r) continue;
        int x = ((r >> i) & 1);
        int y = ((l >> i) & 1);
        if(x == y && x == 1){
            a += (1 << i);
            b += (1 << i);
        }
        else if(x != y){
            a += (1 << i);
            b += ((1 << i) - 1);
            break;
        }
    }
    c = l;
    while(c == b || c == a) c++;
    cout<<a<<" "<<b<<" "<<c<<"\n";

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T = 1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define pb push_back

const int maxn = 2e5 + 10;
int l, r;

void solve(){
    cin>>l>>r;
    int a = 0;
    int b = 0;
    int c = 0;
    for(int i = 29; i >= 0; i--){
        if((1 << i) > r) continue;
        int x = ((r >> i) & 1);
        int y = ((l >> i) & 1);
        if(x == y){
            a += (1 << i);
            b += (1 << i);
        }
        else{
            a += (1 << i);
            b += ((1 << i) - 1);
            break;
        }
    }
    c = l;
    while(c == b || c == a) c++;
    cout<<a<<" "<<b<<" "<<c<<"\n";

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T = 1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Answer: 1


//******************************************************************
//						Author: Ritik Arora
#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

#define ll long long int

#include <ext/pb_ds/assoc_container.hpp> // Common file
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key

#define nline '\n'
#define inf LLONG_MAX
ll mod1 = 1e9 + 7;
ll mod2 = 998244353;

ll expo(ll a, ll b, ll mod)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        b = b >> 1;
    }
    return res;
}

vector<ll> sieve(int n)
{
    int *arr = new int[n + 1]();
    vector<ll> vect;
    for (int i = 2; i <= n; i++)
        if (arr[i] == 0)
        {
            vect.push_back(i);
            for (int j = 2 * i; j <= n; j += i)
                arr[j] = 1;
        }
    return vect;
}

ll inverseMod(ll n, ll mod) { return expo(n, mod - 2, mod); }
ll mod_mul(ll a, ll b, ll m)
{
    a = a % m;
    b = b % m;
    return (((a * b) % m) + m) % m;
}
ll mod_div(ll a, ll b, ll m)
{
    a = a % m;
    b = b % m;
    return (mod_mul(a, inverseMod(b, m), m) + m) % m;
} // only for prime m

#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define alice cout<<"ALICE"<<endl
#define bob cout<<"BOB"<<endl
#define draw cout<<"DRAW"<<endl

void solve()
{
    ll l,r;
    cin >> l >> r;
    ll fix = 0;
    ll start = int(log2(r));

    for (int i = start; i >= 0;i--)
    {
        ll a = (r >> i) & 1;
        ll b = (l >> i) & 1;
        if(a)
        {
            ll wt = (1 << i);

            if(b){
                fix += wt;
                r -= wt;
                l -= wt;
            }
            else{
                ll a = fix + wt;
                ll b = fix + wt - 1;
                if(a+1<=r)
                {
                    cout << a << " " << b << " " << a + 1 << endl;
                }
                else{
                    cout << a << " " << b << " " << b - 1 << endl;
                }
                return;
            }
        }
    }

}
int main()
{
    // unordered_map<long long int,int,custom_hash> mp;
    // StringHash hash(word);
    // hash.substrHash(idx1,idx2)==hash.substrHash(idx3,idx4);
    // Trie* T = new Trie();
    // string ritik="ritik";
    // T->insertNode(ritik);
    // #ifndef ONLINE_JUDGE
    // freopen("Error.txt", "w", stderr);
    // #endif
    fastio();
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

//******************************************************************
//						Author: Ritik Arora
#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

#define ll long long int

#include <ext/pb_ds/assoc_container.hpp> // Common file
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key

#define nline '\n'
#define inf LLONG_MAX
ll mod1 = 1e9 + 7;
ll mod2 = 998244353;

ll expo(ll a, ll b, ll mod)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        b = b >> 1;
    }
    return res;
}

vector<ll> sieve(int n)
{
    int *arr = new int[n + 1]();
    vector<ll> vect;
    for (int i = 2; i <= n; i++)
        if (arr[i] == 0)
        {
            vect.push_back(i);
            for (int j = 2 * i; j <= n; j += i)
                arr[j] = 1;
        }
    return vect;
}

ll inverseMod(ll n, ll mod) { return expo(n, mod - 2, mod); }
ll mod_mul(ll a, ll b, ll m)
{
    a = a % m;
    b = b % m;
    return (((a * b) % m) + m) % m;
}
ll mod_div(ll a, ll b, ll m)
{
    a = a % m;
    b = b % m;
    return (mod_mul(a, inverseMod(b, m), m) + m) % m;
} // only for prime m

#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define alice cout<<"ALICE"<<endl
#define bob cout<<"BOB"<<endl
#define draw cout<<"DRAW"<<endl

void solve()
{
    ll l,r;
    cin >> l >> r;
    ll fix = 0;
    ll start = int(log2(r));

    for (int i = start; i >= 0;i--)
    {
        ll a = (r >> i) & 1;
        ll b = (l >> i) & 1;
        if(a)
        {
            ll wt = (1 << i);

            if(b){
                fix += wt;
                r -= wt;
                l -= wt;
            }
            else{
                ll a = fix + wt;
                ll b = fix + wt - 1;
                if(wt+1<=r)
                {
                    cout << a << " " << b << " " << a + 1 << endl;
                }
                else{
                    cout << a << " " << b << " " << b - 1 << endl;
                }
                return;
            }
        }
    }

}
int main()
{
    // unordered_map<long long int,int,custom_hash> mp;
    // StringHash hash(word);
    // hash.substrHash(idx1,idx2)==hash.substrHash(idx3,idx4);
    // Trie* T = new Trie();
    // string ritik="ritik";
    // T->insertNode(ritik);
    // #ifndef ONLINE_JUDGE
    // freopen("Error.txt", "w", stderr);
    // #endif
    fastio();
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Answer: 2


/*******************************************
 @b |I|s|t|i|a|q|u|e| |A|h|m|e|d| |A|r|i|k|
********************************************/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define static_assert(...) ;
#include <tr2/dynamic_bitset>
using u_bitset = tr2::dynamic_bitset<__uint128_t>;
using l_bitset = tr2::dynamic_bitset<__int128_t>;
void __print(int x) { cerr << x; }
#define bigll __int128_t
#define bigull __uint128_t
#define ll int_fast64_t
#define ull uint_fast64_t
#define ld long double
#define pi acos(-1)
#define set_bits __builtin_popcountll
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define FileIO                        \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout)
///@b decltype and const
const int MOD = 1e9 + 7, dx[] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
///@b debug
struct _
{
    ios_base::Init i;
    _()
    {
        cin.sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(10);
    }
} ___;
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

template <typename p, typename q>
using ht = gp_hash_table<p, q>;

///@b PBDS
// template <typename T>
// using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <typename T>
// using o_set_g = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <typename T>
// using o_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <typename T>
// using o_multiset_g = tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

bool f(ll l, ll r)
{
}

inline void solve()
{
    ll l, r;
    cin >> l >> r;
    ll x = l ^ r;
    bitset<32> b(x);
    ll msb = 32;
    for (ll i = 31; i >= 0; i--)
    {
        if (b[i])
        {
            msb = i;
            break;
        }
    }
    // cout <<  << endl;
    bitset<32> a(l);
    bitset<32> ans;
    for (int i = 32; i > msb; i--)
    {
        ans[i] = a[i];
    }
    ans[msb] = 1;
    for (int i = msb - 1; i >= 0; i--)
    {
        ans[i] = 0;
    }
    ll res = ans.to_ullong();
    for (ll i = l; i <= r; i++)
    {
        if (i != res and i != res - 1)
        {
            cout << res << " " << res - 1 << " " << i << "\n";
            return;
        }
    }
}

auto main() -> int32_t
{
    IOS;
    int t = 1, cs = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

/*******************************************
 @b |I|s|t|i|a|q|u|e| |A|h|m|e|d| |A|r|i|k|
********************************************/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define static_assert(...) ;
#include <tr2/dynamic_bitset>
using u_bitset = tr2::dynamic_bitset<__uint128_t>;
using l_bitset = tr2::dynamic_bitset<__int128_t>;
void __print(int x) { cerr << x; }
#define bigll __int128_t
#define bigull __uint128_t
#define ll int_fast64_t
#define ull uint_fast64_t
#define ld long double
#define pi acos(-1)
#define set_bits __builtin_popcountll
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define FileIO                        \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout)
///@b decltype and const
const int MOD = 1e9 + 7, dx[] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
///@b debug
struct _
{
    ios_base::Init i;
    _()
    {
        cin.sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(10);
    }
} ___;
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

template <typename p, typename q>
using ht = gp_hash_table<p, q>;

///@b PBDS
// template <typename T>
// using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <typename T>
// using o_set_g = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <typename T>
// using o_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <typename T>
// using o_multiset_g = tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void mxTrioXor(ll l, ll r)
{
    array<ll, 3> ans = {0, 0, 0};
    ll mx = 0;
    for (ll i = l; i <= r; i++)
    {
        for (ll j = i + 1; j <= r; j++)
        {
            for (ll k = j + 1; k <= r; k++)
            {
                if ((i ^ j ^ k) > mx)
                {
                    mx = i ^ j ^ k;
                    ans = {i, j, k};
                }
            }
        }
    }

    for (ll i = l; i <= r; i++)
    {
        for (ll j = i + 1; j <= r; j++)
        {
            for (ll k = j + 1; k <= r; k++)
            {
                if ((i ^ j ^ k) == mx)
                {
                    cout << i << " " << j << " " << k << endl;
                }
            }
        }
    }
    cout << mx << "\n";
}

inline void solve()
{
    ll l, r;
    cin >> l >> r;
    bitset<32> b(l ^ r), rbit(r);
    bitset<32> ans;
    ll mx = (1ll << 30);
    while (mx > r)
    {
        mx >>= 1;
    }
    for (ll i = l; i <= r; i++)
    {
        if (i != mx and i != (mx - 1))
        {
            cout << mx << " " << mx - 1 << " " << i << "\n";
            return;
        }
    }
}

auto main() -> int32_t
{
    IOS;
    int t = 1, cs = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

Answer: 1


/* This was created by Ravinder Dathak.
 * Codeforces id by name of Mahadeva.
 * On 04-04-2024.
 * As proof that the following code is my own and authenticate.
*/

#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

//Uncomment during contest.
#define int long long int
#define double long double float

#define input(n) for(int i=0;i<(int)n;i++)

//uncomment during practice. Plz take care of int and long long int.
//typedef long long int ll;
//typedef long double ld;

const int Mod= 1e9+7;

//uncomment to use AutoCp and before any submission.
//  #define ONLINE_JUDGE

void solve(){
    int l,r;
    cin>>l>>r;
    int k;
    for(int i=30;i>=0;i--){
        if((l>>i)^(r>>i)){
            k=i;
            break;
        }
    }
    int a=l|((1<<k)-1),b=a+1,c=(a==l)?r:l;
    cout<<a<<' '<<b<<' '<<c<<endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("cmake-build-debug/input.txt","r",stdin);
    freopen("cmake-build-debug/output.txt","w",stdout);
#endif
    int t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

/* This was created by Ravinder Dathak.
 * Codeforces id by name of Mahadeva.
 * On 04-04-2024.
 * As proof that the following code is my own and authenticate.
*/

#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

//Uncomment during contest.
#define int long long int
#define double long double float

#define input(n) for(int i=0;i<(int)n;i++)

//uncomment during practice. Plz take care of int and long long int.
//typedef long long int ll;
//typedef long double ld;

const int Mod= 1e9+7;

//uncomment to use AutoCp and before any submission.
//  #define ONLINE_JUDGE

void solve(){
    int l,r;
    cin>>l>>r;
    if(l==0){
        cout<<l<<' '<<r-1<<' '<<r<<endl;
        return ;
    }
    int ans=0;
    for(int i=log2(r)-1;i>=0;i--){
        if( ((r>>i)&1) == 0 )ans+=(1<<i);
    }
    if(ans==0 || ans<=l)ans=l+1;
    cout<<l<<' '<<ans<<' '<<r<<endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("cmake-build-debug/input.txt","r",stdin);
    freopen("cmake-build-debug/output.txt","w",stdout);
#endif
    int t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>
#define _fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(e) push_back(e)
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define endl '\n'

using namespace std;
using i64 = long long;
using PII = pair<int,int>;
const int INF = 0x3f3f3f3f;
void fun()
{
    int n,m;
    cin >> n >> m;
    int k = 31 - __builtin_clz(n ^ m);
    int a = n | (1 << k - 1);
    int b = a + 1;
    int c = (a == n ? m : n);
    cout << a << ' ' << b << ' ' << c << endl;
}
int main() {
    int t;
    cin >> t;
    while(t -- ) fun();
    return 0;
}

#include <bits/stdc++.h>
#define _fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(e) push_back(e)
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define endl '\n'

using namespace std;
using i64 = long long;
using PII = pair<int,int>;
const int INF = 0x3f3f3f3f;
void fun()
{
    int n,m;
    cin >> n >> m;
    int k = 31 - __builtin_clz(n ^ m);
    int a = n | ((1 << k) - 1);
    int b = a + 1;
    int c = (a == n ? m : n);
    cout << a << ' ' << b << ' ' << c << endl;
}
int main() {
    int t;
    cin >> t;
    while(t -- ) fun();
    return 0;
}

Answer: 2


#include "bits/stdc++.h"
using namespace std;
void solve(){
    int batas_min,batas_max;
    cin>>batas_min>>batas_max;
    int k=31- __builtin_clz(batas_min^batas_max);
    int a = l | ((1 << k) - 1);
    int b = a + 1;
    int c = (a == l ? batas_max : l);
    cout<<a<<" "<<b<<" "<<c<<endl;

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

#include "bits/stdc++.h"
using namespace std;
void solve(){
    int batas_min,batas_max;
    cin>>batas_min>>batas_max;
    int k=31- __builtin_clz(batas_min^batas_max);
    int a = batas_min | ((1 << k) - 1);
    int b = a + 1;
    int c = (a == batas_min ? batas_max : batas_min);
    cout<<a<<" "<<b<<" "<<c<<endl;

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

Answer: 2


#include <bits/stdc++.h>

using namespace std;
#define int long long int
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while (t--) {
        int l, r;
        cin >> l >> r;
        int k = 31 - __builtin_clz(l ^ r);
        int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
        cout << a << " " << b << " " << c << "\n";

    }
    // your code goes here

}

#include <bits/stdc++.h>

using namespace std;
#define int long long int
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while (t--) {
        int l, r;
        cin >> l >> r;
        int a = 0, b = 0, c = 0, pos;
        for (int i = 30; i >= 0; i--) {
            int bit = (1 << i);
            if ((l & b) != (r & b)) {
                pos = i;
                break;
            }
        }

        a = l | ((1 << pos) - 1);
        b = a + 1;
        c = r;

        if (c == a || c == b) {
            c--;
        }
        if (c == a || c == b) {
            c--;
        }
        cout << a << " " << b << " " << c << "\n";

    }
    // your code goes here

}

Answer: 1


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

int l, r;

int main()
{
    int T;
    scanf("%d", &T);
    while (T --)
    {
        scanf("%d%d", &l, &r);
        int t = l ^ r;
        int start;
        for (int i = 30; i >= 0; i --)
            if (t >> i & 1)
            {
                start = i;
                break;
            }
        // cout << "start:" << start << endl;
        int a = 0, b = 0, c = 0;
        if ((t >> (start - 1)) == 1)
        {
            a = (1 << start), b = (1 << start) - 1;
            a = a + (l >> start << start), b = b + (l >> start << start);
            for (int i = l; i <= r; i ++)
                if (i != a && i != b)
                {
                    c = i;
                    break;
                }
        }
        else
        {
            a = (1 << start), b = (1 << (start - 1));
            for (int i = start - 2; i >= 0; i --)
            {
                if (t >> i & 1)
                {
                    if (l >> i & 1) b = b + (1 << i);
                    else    a = a + (1 << i);
                }
                else
                {
                    b = b + (1 << i);
                }
            }
            a = a + (l >> start << start), b = b + (l >> start << start);
            for (int i = l; i <= r; i ++)
                if (i != a && i != b)
                {
                    c = i;
                    break;
                }
        }
        // cout << "start:" << start << endl;
        printf("%d %d %d\n", a, b, c);
        // printf("%d\n", (a ^ b) + (a ^ c) + (b ^ c));
        // printf("%d\n", (123 ^ 121) + (123 ^ 118) + (121 ^ 118));//123 121 118
    }

    return 0;
}

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

int l, r;

int main()
{
    int T;
    scanf("%d", &T);
    while (T --)
    {
        scanf("%d%d", &l, &r);
        int t = l ^ r;
        int start;
        for (int i = 30; i >= 0; i --)
            if (t >> i & 1)
            {
                start = i;
                break;
            }
        // cout << "start:" << start << endl;
        int a = 0, b = 0, c = 0;
        if ((t >> (start - 1)) == 1)
        {
            a = (1 << start), b = (1 << start) - 1;
            for (int i = l; i <= r; i ++)
                if (i != a && i != b)
                {
                    c = i;
                    break;
                }
        }
        else
        {
            a = (1 << start), b = (1 << (start - 1));
            for (int i = start - 2; i >= 0; i --)
            {
                if (t >> i & 1)
                {
                    if (l >> i & 1) b = b + (1 << i);
                    else    a = a + (1 << i);
                }
                else
                {
                    b = b + (1 << i);
                }
            }
            for (int i = l; i <= r; i ++)
                if (i != a && i != b)
                {
                    c = i;
                    break;
                }
        }
        // cout << "start:" << start << endl;
        a = a + (l >> start << start), b = b + (l >> start << start);
        printf("%d %d %d\n", a, b, c);
        // printf("%d\n", (a ^ b) + (a ^ c) + (b ^ c));
        // printf("%d\n", (123 ^ 121) + (123 ^ 118) + (121 ^ 118));//123 121 118
    }

    return 0;
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;

#ifndef ONLINE_JUDGE
#include "DEBUG.h"
#define bug(...)           __f (#__VA_ARGS__, __VA_ARGS__)
#endif

#define first_in_out       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll                 long long int
#define double             long double
#define print(a)           for(auto x : a) cout << x << " ";
#define printpair(a)       for(auto x : a) cout << x.first << " " << x.second<<"\n";

void solve()

{
    ll l, r;
    cin >> l >> r;
    ll a = 0, b = 0, c = 0;
    int f = 0;
    for (int j = 30; j >= 0; j--)
    {
        ll p = (1ll << j);

        if (f) {
            b += p;
            continue;
        }

        if ((l & p) == (r & p)) {
            if ((l & p))
                a += p, b += p;
        }
        else if ((l & p) != (r & p)) {
            a += p;
            f = 1;
        }

    }

    c = l;

    while (c == a or c == b)
        c++;

    cout << a << " " << b << " " << c << "\n";
}

int main()
{
    first_in_out

    int t = 1;
    cin >> t;

    while (t--)
        solve();

}

#include<bits/stdc++.h>
using namespace std;

#ifndef ONLINE_JUDGE
#include "DEBUG.h"
#define bug(...)           __f (#__VA_ARGS__, __VA_ARGS__)
#endif

#define first_in_out       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll                 long long int
#define double             long double
#define print(a)           for(auto x : a) cout << x << " ";
#define printpair(a)       for(auto x : a) cout << x.first << " " << x.second<<"\n";

void solve()

{
    ll l, r;
    cin >> l >> r;
    ll a = 0, b = 0, c = 0;
    int f = 0;
    for (int j = 30; j >= 0; j--)
    {
        ll p = (1ll << j);

        if (f) {
            b += p;
            continue;
        }

        if ((l & p) == (r & p)) {
            if ((l & p))
                a += p, b += p;
        }
        else if ((l & p) != (r & p)) {
            a += p;
            f = 1;
        }

    }

    c = b;

    cout << a << " " << b << " " << c << "\n";
}

int main()
{
    first_in_out

    int t = 1;
    cin >> t;

    while (t--)
        solve();

}

Answer: 1


/*
  __  __          _    _ _____            _   _
 |  \/  |   /\   | |  | |  __ \     /\   | \ | |
 | \  / |  /  \  | |__| | |__) |   /  \  |  \| |
 | |\/| | / /\ \ |  __  |  _  /   / /\ \ | . ` |
 | |  | |/ ____ \| |  | | | \ \  / ____ \| |\  |
 |_|  |_/_/    \_\_|  |_|_|  \_\/_/    \_\_| \_|
                                                     */
#include <bits/stdc++.h>
#include <cmath> // Include cmath for M_PI
#ifndef M_PI
#define M_PI 3.14159265358979323846 // Define M_PI if not already defined
#endif
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ull unsigned long long
#define endl "\n"
using namespace std;
/*
pair<int, int> t[4*MAXN];

pair<int, int> combine(pair<int, int> a, pair<int, int> b) {
    if (a.first > b.first)
        return a;
    if (b.first > a.first)
        return b;
    return make_pair(a.first, a.second + b.second);
}

void build(int a[], int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = make_pair(a[tl], 1);
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] = combine(t[v*2], t[v*2+1]);
    }
}

pair<int, int> get_max(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return make_pair(-INF, 0);
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return combine(get_max(v*2, tl, tm, l, min(r, tm)),
                   get_max(v*2+1, tm+1, tr, max(l, tm+1), r));
}

void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t[v] = make_pair(new_val, 1);
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = combine(t[v*2], t[v*2+1]);
    }
}
*/

template <typename T>
void pop_front(std::vector<T> &v)
{
    if (v.size() > 0)
    {
        v.erase(v.begin());
    }
}
const int MOD = 1e9 + 7;
long long binpow(long long a, long long b, long long m)
{
    a %= m;
    long long res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
bool sortFirst(const pair<ll, ll> &a, const pair<ll, ll> &b)
{
    if (a.first == b.first)
    {
        return a.second > b.second;
    }
    return a.first < b.first;
}

void solve()
{
    ll l, r;
    cin >> l >> r;
    int i = 31;
    bool t = false;
    bool tt = false;
    for (; i >= 0; i--)
    {
        if ((1LL << i) & l)
        {
            t = true;
        }
        if ((1LL << i) & r)
        {
            tt = true;
        }
        if (t && tt)
        {
            break;
        }
    }
    int j = i;
    for (; j >= 0; j--)
    {
        if (((1LL << j) & l) && !((1LL << j) & r))
        {
            break;
        }
    }
    ll k = 31 - __builtin_clz(l ^ r);
    ll a = l | ((1LL << k) - 1);
    ll b = a + 1;
    ll c = l;
    if (a == l)
    {
        c = r;
    }
    cout << a << " " << b << " " << c << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    while (t--)
    {
        solve();
    }

    return 0;
}

/*
  __  __          _    _ _____            _   _
 |  \/  |   /\   | |  | |  __ \     /\   | \ | |
 | \  / |  /  \  | |__| | |__) |   /  \  |  \| |
 | |\/| | / /\ \ |  __  |  _  /   / /\ \ | . ` |
 | |  | |/ ____ \| |  | | | \ \  / ____ \| |\  |
 |_|  |_/_/    \_\_|  |_|_|  \_\/_/    \_\_| \_|
                                                     */
#include <bits/stdc++.h>
#include <cmath> // Include cmath for M_PI
#ifndef M_PI
#define M_PI 3.14159265358979323846 // Define M_PI if not already defined
#endif
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ull unsigned long long
#define endl "\n"
using namespace std;
/*
pair<int, int> t[4*MAXN];

pair<int, int> combine(pair<int, int> a, pair<int, int> b) {
    if (a.first > b.first)
        return a;
    if (b.first > a.first)
        return b;
    return make_pair(a.first, a.second + b.second);
}

void build(int a[], int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = make_pair(a[tl], 1);
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] = combine(t[v*2], t[v*2+1]);
    }
}

pair<int, int> get_max(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return make_pair(-INF, 0);
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return combine(get_max(v*2, tl, tm, l, min(r, tm)),
                   get_max(v*2+1, tm+1, tr, max(l, tm+1), r));
}

void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t[v] = make_pair(new_val, 1);
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = combine(t[v*2], t[v*2+1]);
    }
}
*/

template <typename T>
void pop_front(std::vector<T> &v)
{
    if (v.size() > 0)
    {
        v.erase(v.begin());
    }
}
const int MOD = 1e9 + 7;
long long binpow(long long a, long long b, long long m)
{
    a %= m;
    long long res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
bool sortFirst(const pair<ll, ll> &a, const pair<ll, ll> &b)
{
    if (a.first == b.first)
    {
        return a.second > b.second;
    }
    return a.first < b.first;
}

void solve()
{
    ll l, r;
    cin >> l >> r;
    int i = 31;
    bool t = false;
    bool tt = false;
    for (; i >= 0; i--)
    {
        if ((1LL << i) & l)
        {
            t = true;
        }
        if ((1LL << i) & r)
        {
            tt = true;
        }
        if (t && tt)
        {
            break;
        }
    }
    int j = i;
    for (; j >= 0; j--)
    {
        if (((1LL << j) & l) && !((1LL << j) & r))
        {
            break;
        }
    }
    ll k = 31 - __builtin_clz(l ^ r);
    ll a = l | (1LL << (k - 1));
    ll b = a + 1;
    ll c = l;
    if (b == l)
    {
        c = r;
    }
    cout << a << " " << b << " " << c << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    while (t--)
    {
        solve();
    }

    return 0;
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
int mod=1e9+7;
long long power(long long x,int y)
{
    long long res=1;
    while(y>0)
    {
        int r=y%2;
        if(r==1)
        {
            res=res*x;
        }
        y=y/2;
        x=x*x;
    }
    return res;
}
int main() {
    int t;
    cin>>t;
    while(t--)
    {
       long long low,l,high,h;
       cin>>low>>high;
       l=low;
       h=high;
       vector<int>v1(35,0),v2(35,0);
       int j=32;
      // long long p=1;
       while(high>0)
       {
           int r1=high%2;
           int r2=low%2;
           v1[j]=r1;
           v2[j]=r2;
           j--;

           high=high/2;
           low=low/2;

        }
       // cout<<j<<endl;
        long long z=0;
        int idx;
        for(int i=0;i<=32;i++)
        {
            if(v1[i]==v2[i])
            {
                continue;
            }
            idx=33-i;

           z=power(2,idx);
            z--;
            break;
        }
       // cout<<z<<endl;
      //  cout<<z;
        long long num1=l^z;
        long long num2=h^z;
        if(num1<h&&num1>l)
        {
            cout<<l<<" "<<num1<<" "<<h<<endl;
        }
        else if(num2>l&&num2<h){
             cout<<l<<" "<<num2<<" "<<h<<endl;
        }
        else{
            cout<<l<<" "<<l+1<<" "<<h<<endl;
        }
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define iii pair<int, ii>
#define fi first
#define se second
#define inf 1e16
int tc, l, r;
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen("main.inp","r")) {
        freopen("main.inp", "r", stdin);
        freopen("main.out", "w", stdout);
    }
    cin >> tc;
    while(tc--) {
        cin >> l >> r;
        int a = 0, b = 0, c =  0;
        for(int j = 30; j >= 0; j--) {
            if((r&(1<<j)) && (l&(1<<j))) {
                a += (1<<j);
                b += (1<<j);
                c += (1<<j);
            }
            else if(!(r&(1<<j)) && !(l&(1<<j))) continue;
            else {
                a += (1<<j);
                b += (1<<j)-1;
                c += (1<<j)-2;
                break;
            }
        }
        if(min({a,b,c}) < l) {
            a++;
            b++;
            c++;
        }
        cout << a << ' ' << b << ' ' << c << '\n';
    }
    return 0;
}

Answer: 2


//जय सिया राम
// Author : **Aditya Raj**

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long int
#define ll  long long int
#define ld long double
#define endl '\n'
#define loopi(n) for(int i=0;i<n;i++)

void solve(){
    int l,r;
    cin>>l>>r;
    int a,b,c;
    int ans = 0;
    a = 0;
    b = 0;
    c = 1;
    for(int i=30;i>=0;i--){
        int b1 = 0;
        int b2 = 0;

        if(l&(1ll << i)){
            b1 = 1;
        }
        if(r&(1ll << i)){
            b2 = 1;
        }
        if(b1==b2){
            ans += b1*(1ll << i);
        }
        else{
            a = ans + (1ll<<i);
            b = a - 1;
            break;
        }
    }

    for(int i = l;i<r;i++){
        if(i != a && i != b){
            c = i;
            break;
        }
    }

    cout<<a<<" "<<b<<" "<<c<<" "<<endl;

}

signed main() {
    //fast input output
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin>>t;

    while(t--){

        solve();

    }
    return 0;
}

//जय सिया राम
// Author : **Aditya Raj**

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long int
#define ll  long long int
#define ld long double
#define endl '\n'
#define loopi(n) for(int i=0;i<n;i++)

void solve(){
    int l,r;
    cin>>l>>r;
    int a,b,c;
    int ans = 0;
    a = 0;
    b = 0;
    c = 0;
    for(int i=30;i>=0;i--){
        int b1 = 0;
        int b2 = 0;

        if(l&(1ll << i)){
            b1 = 1;
        }
        if(r&(1ll << i)){
            b2 = 1;
        }
        if(b1==b2){
            ans += b1*(1ll << i);
        }
        else{
            a = ans + (1ll<<i);
            b = a - 1;
            break;
        }
    }

    for(int i = l;i<=r;i++){
        if(i != a && i != b){
            c = i;
            break;
        }
    }

    cout<<a<<" "<<b<<" "<<c<<" "<<endl;

}

signed main() {
    //fast input output
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin>>t;

    while(t--){

        solve();

    }
    return 0;
}

Answer: 2


/*                                                     ॐ हं हनुमते नमः                                                                                */

#include <bits/stdc++.h>
//#include "debugging.h"
#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>;
#define ll long long
const int mod = 1000000007;
#define pb push_back
#define s second
#define f first
#define mp make_pair
#define rep(i,a,b) for(int i = a ; i<=b ; i++)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define vpi vector<pair<int , int>>
#define Sort(a) sort(a.begin() , a.end())
#define Max(a) *max_element(a.begin() , a.end())
#define Min(a) *min_element(a.begin() , a.end())
/***************************************************************************************************************************************************************/

int binexpo(ll a, ll b, ll m = mod){ ll res = 1; a%=m; while(b>0){ if(b&1){ res= (res*a)%m; } a = (a*a)%m; b>>=1; } return res; }
int gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);}
int lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
int modInverse(ll a, ll m) { return binexpo(a, m - 2, m); }
int modAdd(ll a, ll b, int m) { return ((a % m) + (b % m)) % m; }
int modMul(ll a, ll b, int m) { return ((a % m) * (b % m)) % m; }
int modSub(ll a, ll b, int m) { return ((a % m) - (b % m) + m) % m; }
int modDiv(ll a, ll b, int m) { return (modMul(a, modInverse(b, m), m) + m) % m; }
bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
int nCr(int n, int r) { if (r > n - r) r = n - r; int ans = 1; for (int i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans; }
int nCrModP(int n, int r, int p = mod) { if (r > n - r) r = n - r; int C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (int i = 1; i <= n; i++) { for (int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p; } return C[r]; }
int nPr(int n, int r) { int ans = 1; for (int i = 0; i < r; i++) ans *= (n - i); return ans; }
int nPrModP(int n, int r, int p = mod) { int ans = 1; for (int i = 0; i < r; i++) ans = (ans * (n - i)) % p; return ans; }
int log(int num , int base){int ans = 0; while(num){num /= base;ans++;} return ans;}
int countSetBits(int x){int ans = 0;while(x){ans += (x&1);x >>= 1;}return ans;}
/***************************************************************************************************************************************************************/
/*Always High on CP*/

void legend(){
    int l , r;cin>>l>>r;
    int a = 0;
    int b = 0;
    for(int i = 30 ; i>=0 ; i--){
        int bit1 = (l&(1<<i));
        int bit2 = (r&(1<<i));
        if(bit1 == bit2){
            if(bit1 != 0) a |= (1<<i);
        }
        else{
            a += (1<<i);
            b = a - 1;
            break;
        }
    }
    int c = 0;
    for(int i = l ; i<=r ; i++){
        if(i != a && i != b){
            c = i;
            break;
        }
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}

/*Now setting the heart on fire*/

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;cin>>t;
    while(t--){
      legend();
    }
    return 0;
}

/*                                                     ॐ हं हनुमते नमः                                                                                */

#include <bits/stdc++.h>
//#include "debugging.h"
#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>;
#define ll long long
const int mod = 1000000007;
#define pb push_back
#define s second
#define f first
#define mp make_pair
#define rep(i,a,b) for(int i = a ; i<=b ; i++)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define vpi vector<pair<int , int>>
#define Sort(a) sort(a.begin() , a.end())
#define Max(a) *max_element(a.begin() , a.end())
#define Min(a) *min_element(a.begin() , a.end())
/***************************************************************************************************************************************************************/

int binexpo(ll a, ll b, ll m = mod){ ll res = 1; a%=m; while(b>0){ if(b&1){ res= (res*a)%m; } a = (a*a)%m; b>>=1; } return res; }
int gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);}
int lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
int modInverse(ll a, ll m) { return binexpo(a, m - 2, m); }
int modAdd(ll a, ll b, int m) { return ((a % m) + (b % m)) % m; }
int modMul(ll a, ll b, int m) { return ((a % m) * (b % m)) % m; }
int modSub(ll a, ll b, int m) { return ((a % m) - (b % m) + m) % m; }
int modDiv(ll a, ll b, int m) { return (modMul(a, modInverse(b, m), m) + m) % m; }
bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
int nCr(int n, int r) { if (r > n - r) r = n - r; int ans = 1; for (int i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans; }
int nCrModP(int n, int r, int p = mod) { if (r > n - r) r = n - r; int C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (int i = 1; i <= n; i++) { for (int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p; } return C[r]; }
int nPr(int n, int r) { int ans = 1; for (int i = 0; i < r; i++) ans *= (n - i); return ans; }
int nPrModP(int n, int r, int p = mod) { int ans = 1; for (int i = 0; i < r; i++) ans = (ans * (n - i)) % p; return ans; }
int log(int num , int base){int ans = 0; while(num){num /= base;ans++;} return ans;}
int countSetBits(int x){int ans = 0;while(x){ans += (x&1);x >>= 1;}return ans;}
/***************************************************************************************************************************************************************/
/*Always High on CP*/

void legend(){
    int l , r;cin>>l>>r;
    int a = 0;
    int b = 0;
    for(int i = 30 ; i>=0 ; i--){
        int bit1 = (l&(1<<i));
        int bit2 = (r&(1<<i));
        if(bit1 == bit2){
            if(bit1 != 0) a |= (1<<i);
        }
        else{
            a |= (1<<i);
            b = a - 1;
        }
    }
    int c = 0;
    for(int i = l ; i<=r ; i++){
        if(i != a && i != b){
            c = i;
            break;
        }
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}

/*Now setting the heart on fire*/

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;cin>>t;
    while(t--){
      legend();
    }
    return 0;
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
void solve(){
    ll l,r;
    cin>>l>>r;
    ll ans=0;
    ll a=0,b=0,c=0;
    for(ll i=30;i>=0;i--){
        ll curr=(1ll<<i);
        ll b1=0,b2=0;
        if(l & curr){
            b1=1;
        }
        if(r & curr){
            b2=1;
        }
        if(b1==b2){
            ans+=b1*curr;
        }else{
            a=ans+curr;
            b=a-1;
            break;
        }
    }
    for(ll i=l;i<=r;i++){
        if(i!=a and i!=b){
            c=i;
            break;
        }
    }
    cout<<a<<" "<<b<<" "<<c<<"\n";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t;
    cin>> t;
    while(t--)
    solve();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
void solve(){
    ll l,r;
    cin>>l>>r;
    ll ans=0;
    ll a=0,b=0,c=0;
    for(ll i=30;i>=0;i--){
        ll curr=(1ll<<i);
        ll b1=0,b2=0;
        if(l & curr){
            b1=1;
        }
        if(r & curr){
            b2=1;
        }
        if(b1==b2){
            ans+=b1*curr;
        }else{
            a=ans+curr;
            b=a-1;
            c=a;
            break;
        }
    }
    cout<<a<<" "<<b<<" "<<c<<"\n";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t;
    cin>> t;
    while(t--)
    solve();
    return 0;
}

Answer: 1


t=int(input())
for ii in range (0,t):
    l,r=list(map(int, input().split()))
    c=0
    sr=bin(r)[2:]
    t =len(sr) - 1
    sl=bin(l)[2:]
    k=len(sl)-1
    sl="0"*(t-k)+sl
    n=t
    while t>=0:
        d=n-t
        e=int(sr[d]) + int(sl[d])
        if e==1 or e==2:
            if c+2**t<=l+1 or l*2==2**t:
                c+=2**t
        else:
            if c+2**t<r:
                c+=2**t
        t-=1
    print(l,r,c)

t=int(input())
for ii in range (0,t):
    l, r = map(int, input().split())
    k = 0
    for i in range(30, -1, -1):
        if ((l >> i) & 1) ^ ((r >> i) & 1):
            k = i
            break
    a = (1 << k) - 1 | l
    b = a + 1
    c = r if a == l else l
    print(a, b, c)

Answer: 2


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define close ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

void solved()
{
    int l,r;
    cin>>l>>r;
    int k = (l^r);
    bitset<31>b(k);
    int ans = 0;
    for(int i = 0;i<=30;i++)
    {
        if(b[i] == 1)
        {
            ans = i;
        }
    }
    int result = l | ((1 << ans) - 1 );
    cout<<result<<" ";
    cout<<result + 1<<" ";
    cout<<(result == l ? r : l )<<endl;
}

signed main()
{
    close;
    int T;
    cin>>T;
    while(T--)
    {
        solved();
    }
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define close ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

void solved()
{
    int l, r;
    cin >> l >> r;
    bitset<30> right(r);
    bitset<30> left(l);
    bitset<30> ans;
    set<int>st;
    for (int i = 0; i < 30; i++) {
        if (right[i] == 1 && left[i] == 1) {
            ans[i] = 0;
        }
        else if (right[i] == 0 && left[i] == 0) {
            ans[i] = 1;
        }
        else
        {
            st.insert(i);
        }
    }

    int k = ans.to_ulong();

    while(!(k != l && k != r && k >= l && k <= r))
    {
        if(st.empty())
        {
            break;
        }
        ans[*(st.begin())] = 1;
        st.erase(st.begin());
        k = ans.to_ulong();
    }
    cout<<l<<" "<<r<<" "<<k<<endl;
}

signed main()
{
    close;
    int T = 1;
    cin >> T;
    while (T--) {
        solved();
    }
    return 0;
}

Answer: 1


#include <iostream>

using namespace std;
using ll = long long;

void solve(){
    ll a=0,b=0,c=0;
    ll l,r;
    ll ans = 0;
    cin >> l >> r;
    for(int i=31;i>=0;i--){
        int b1 = 0, b2 = 0;
        if(l&(1ll<<i)) b1 = 1;
        if(r&(1ll<<i)) b2 = 1;
        if(b1==b2) ans += b1*(1ll<<i);
        else{
            a = ans+(1ll<<i);
            b = a-1;
            break;
        }
    }
    for(ll i=l;i<=r;i++){
        if(i!=a&&i!=b){
            c = i;
            break;
        }
    }
    cout << a << " " << b << " " << c << endl;
}

int main(){
    int t = 1;
    cin >> t;
    while(t--) solve();
}

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        long long l, r;
        cin >> l >> r;

        long long m = 0;
        if (r > 0) {
            m = 63 - __builtin_clzll(r);
        }
        long long a = (1LL << m);
        if (a > r || a < l) {
            a = r;
        }
        long long b = (a - 1);
        if (b < l) {
            b = r - 1;
        }
        if (b == a) {
            b = a - 1;
        }
        long long c = l;
        if (c == a || c == b) {
            c = l + 1;
            if (c == a || c == b) c++;
        }

        cout << a << " " << b << " " << c << "\n";
    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

#define int int64_t
#define ar array

void solve() {
    int l,r; cin >> l >> r;
    int k = 0;
    for (int i = 0; i <= 30; i++) {
        if (((l^r)>>i) & 1) k = i;
    }
    int x = r & ((1 << 31) - (1 << k));
    if (r == x) cout << l << ' ' << x << ' ' << x-1 << '\n';
    else cout << r << ' ' << x << ' ' << x-1 << '\n';
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1; cin >> t;
    while (t--) {
        solve();
    }
}

#include <bits/stdc++.h>

using namespace std;

#define int int64_t
#define ar array

void solve() {
    int l,r; cin >> l >> r;
    int k = 0;
    for (int i = 1; i <= 30; i++) {
        if (((l^r)>>i) & 1) k = i-1;
    }
    int x = r & ((1 << 31) - (1 << k));
    if (r == x) cout << l << ' ' << x << ' ' << x-1 << '\n';
    else cout << r << ' ' << x << ' ' << x-1 << '\n';
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1; cin >> t;
    while (t--) {
        solve();
    }
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9+7;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int total, l, r;
    cin>>total;
    for (int cap = 0; cap < total; ++cap) {
        cin>>l>>r;
        int diff = 0, inv = 0;
        for (int i = 30; i >= 0; --i) {
            //cout<<'-'<<i<<' '<<(r & (1<<i))<<' '<<(l & (1<<i))<<'\n';
            if ((r & (1<<i)) != (l & (1<<i))) {
                diff = i;
                break;
            }
        }
        for (int j = diff - 1; j >= 0; --j) {
            //cout<<j<<' '<<(r & (1<<j))<<(l & (1<<j))<<'\n';
            if ((r & (1<<j)) >= (l & (1<<j))) {
                inv = j;
                break;
            }
        }
        // inv += 1;
        int bind = r & (1<<inv), ret;
        if (bind) {
            ret = r;
        } else {
            ret = l;
        }
        //cout<<diff<<'\n';
        int oink = ret % (1<<inv+1);
        //cout<<oink<<'\n';
        ret -= oink;
        ret += (1<<(inv+1)) - 1 - oink;
        if (ret < l) {
            ret += (1<<diff);
        }
        cout<<l<<' '<<ret<<' '<<r<<'\n';
    }
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9+7;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int total, l, r;
    cin>>total;
    for (int cap = 0; cap < total; ++cap) {
        cin>>l>>r;
        int diff = 0, inv = 0;
        for (int i = 30; i >= 0; --i) {
            //cout<<'-'<<i<<' '<<(r & (1<<i))<<' '<<(l & (1<<i))<<'\n';
            if ((r & (1<<i)) != (l & (1<<i))) {
                diff = i;
                break;
            }
        }
        for (int j = diff - 1; j >= 0; --j) {
            if ((r & (1<<j)) >= (l & (1<<j))) {
                inv = j;
                break;
            }
        }
        // inv += 1;
        int bind = r & (1<<inv), ret;
        if (bind == 1) {
            ret = r;
        } else {
            ret = l;
        }
        //cout<<diff<<'\n';
        int oink = ret % (1<<inv+1);
        ret -= oink;
        ret += (1<<(inv+1)) - 1 - oink;
        if (ret < l) {
            ret += (1<<diff);
        }
        cout<<l<<' '<<ret<<' '<<r<<'\n';
    }
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<ll>a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int sheng=0;
        int jiang=0;
        for(int i=0;i<n-1;i++){
            if(a[i]>a[i+1]){
                jiang++;
            }
            if(a[i]<a[i+1]){
                sheng++;
            }
        }
        if(jiang>=sheng){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int a[n+1];
		int y=1;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			if(i>1)
            a[i]-=a[i-1];
			if(a[i]<0)
            y=0;
		}
		if(y==1)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

#define entf          cout << endl

#define ent           cout << "\n"

#define REP(i, a, b)  for (int i = a; i < b; ++i)

#define REPV(i, a, b) for (int i = a; i >= b; --i)

#define MOD           1000000007

#define PRINT(x) cout << x << endl

#define d(x) cerr << #x << " = " << x << endl  // Pass a variable name and it will print it with the value

#define TESTCASES true

void solve(int tt) {

int n;

cin >> n;

int val;

vector<int> a;

a.reserve(n);

REP(i, 0, n){

cin >> val;

a.push_back(val);

}

if(a[0] > a[1]) {

cout << "NO" << endl;

return;

}

bool ans = true;

for(int i = 0; i < n -1; i++) {

if(a[i] > a[i+1]) {

ans = false;

break;

}

int diff = min(a[i], a[i+1]);

a[i+1] -= a[i];

a[i] -= a[i];

}

cout << (ans ? "YES": "NO") << endl;

}

int main() {

ios::sync_with_stdio(0);

cin.tie(0);

if (TESTCASES) {

int tt; cin >> tt;

REP(i, 1, tt+1) {

solve(i);

}

} else solve(1);

return 0;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

#define entf          cout << endl

#define ent           cout << "\n"

#define REP(i, a, b)  for (int i = a; i < b; ++i)

#define REPV(i, a, b) for (int i = a; i >= b; --i)

#define MOD           1000000007

#define PRINT(x) cout << x << endl

#define d(x) cerr << #x << " = " << x << endl  // Pass a variable name and it will print it with the value

#define TESTCASES true

void solve(int tt) {

int n;

cin >> n;

int val;

vector<int> a;

a.reserve(n);

REP(i, 0, n){

cin >> val;

a.push_back(val);

}

// if(a[0] > a[1]) {

//     cout << "NO" << endl;

//     return;

// }

bool ans = true;

for(int i = 0; i < n -2; i++) {

if(a[i] > a[i+1]) {

ans = false;

break;

}

a[i+1] -= a[i];

a[i] -= a[i];

}

cout << (ans ? "YES": "NO") << endl;

}

int main() {

ios::sync_with_stdio(0);

cin.tie(0);

if (TESTCASES) {

int tt; cin >> tt;

REP(i, 1, tt+1) {

solve(i);

}

} else solve(1);

return 0;

}

Answer: 1


#include <bits/stdc++.h>
using namespace std;

int numFib(vector<int>& v, int i) {

    int totalFib = 0;
    totalFib = (i == v[0] + v[1]) ? totalFib + 1 : totalFib;
    totalFib = (v[2] == i + v[1]) ? totalFib + 1 : totalFib;
    totalFib = (v[3] == i + v[2]) ? totalFib + 1 : totalFib;

    return totalFib;

}
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin>>t;

    while (t--) {

        int n;
        cin>>n;
        vector<int> v(n);

        for (int i = 0; i < n; i++) cin>>v[i];

        bool valid = true;
        int minNum = INT_MAX;

        for (int i = 0; i < n - 1; i++) {
            if (i > 0 && v[i-1] > v[i]) {
                valid = false;
                break;
            }

            minNum = min(v[i], v[i-1]);
            v[i] -= minNum;
            v[i-1] -= minNum;
        }

        if (valid && v[v.size() - 1] >= v[v.size() - 2]) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }

    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin>>t;

    while (t--) {

        int n;
        cin>>n;
        vector<int> v(n);

        for (int i = 0; i < n; i++) cin>>v[i];

        bool valid = true;
        int minNum = INT_MAX;

        for (int i = 1; i < n; i++) {

            if (v[i-1] > v[i]) {
                valid = false;
                break;
            }
            minNum = min(v[i], v[i-1]);
            v[i] -= minNum;
            v[i-1] -= minNum;
        }

        if (valid && v[v.size() - 1] >= v[v.size() - 2]) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }

    }

    return 0;
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define ull unsigned long long

int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};

int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

void Mostafa() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif

}

void solve(){

    int n; cin>>n;

    vector<int> a(n);

    for(int i=0; i<n; i++) cin>>a[i];

    for (int i = 0; i < n-1; ++i) {

        int mn = min(a[i], a[i+1]);

        a[i] -= mn;

        a[i+1] -= mn;

    }

    if(is_sorted(a.begin(), a.end())) cout<<"YES\n";

    else cout<<"NO\n";

}

int main() {

    Mostafa();

    int t; cin>>t;

    while(t--) {

        solve();

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define ull unsigned long long

int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};

int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

void Mostafa() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif

}

void solve(){

    int n; cin>>n;

    vector<int> a(n);

    for(int i=0; i<n; i++) cin>>a[i];

    for (int i = 1; i < n; i+=2) {

        if(a[i] < a[i-1]) {

            cout<<"NO\n";

            return;

        }

    }

    cout<<"YES\n";

}

int main() {

    Mostafa();

    int t; cin>>t;

    while(t--) {

        solve();

    }

    return 0;

}

Answer: 1


#include <bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        long long n;
        cin >> n;
        vector<long long> v(n);
        for(long i=0 ;i<n ;i++){
            cin >> v[i];
        }

        for(long long i =0 ; i<n-1 ;i++){
            int temp = min(v[i] , v[i+1]);
            v[i] =v[i] - temp;
            v[i+1] = v[i+1]- temp;
        }

        int cnt =0;
        for(long long i=0 ;i< n ;i++){
            if(v[i]!=0){
                ++cnt;
            }
        }

        if(cnt == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
    long long t;
    cin >> t;
    while(t--){
        long long n;
        cin >> n;
        vector<long long> v(n);
        for(long i=0 ;i<n ;i++){
            cin >> v[i];
        }

        for(long long i =0 ; i<n-1 ;i++){
            long long temp = min(v[i] , v[i+1]);
            v[i] =v[i] - temp;
            v[i+1] = v[i+1]- temp;
        }
        v[n-1]=0;

        long long cnt =0;
        for(long long i=0 ;i< n ;i++){
            if(v[i]!=0){
                ++cnt;
            }
        }

        if(cnt == 0){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve(){

    ll n; cin>>n;

    vector<ll> v(n);

    for(int i=0;i<n;i++) cin>>v[i];

    if(is_sorted(v.begin(),v.end())){

        cout<<"YES"<<endl;

        return;

    }

    vector<ll> diff(n-1);

    for(int i=0;i<n-1;i++){

        diff[i] = v[i+1]-v[i];

    }

    for(int i=0;i<n-2;i++){

        if(diff[i]<0 and diff[i+1]<0){

            cout<<"NO"<<endl;

            return;

        }

    }

    if(is_sorted(v.rbegin(), v.rend())){

        cout<<"NO"<<endl;

        return;

    }

    cout<<"YES"<<endl;

}

int main(){

    int t;

    cin>>t;

    while(t--){

        solve();

    }

    // solve();

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve(){

    ll n; cin>>n;

    vector<ll> v(n);

    for(int i=0;i<n;i++) cin>>v[i];

    // if(is_sorted(v.begin(),v.end())){

    //     cout<<"YES"<<endl;

    //     return;

    // }

    for(int i=0;i<n-1;i++){

        ll diff = min(v[i], v[i+1]);

        v[i]-=diff;

        v[i+1]-=diff;

    }

    if(is_sorted(v.begin(), v.end())){

        cout<<"YES"<<endl;

    }

    else cout<<"NO"<<endl;

}

int main(){

    int t;

    cin>>t;

    while(t--){

        solve();

    }

    // solve();

}

Answer: 2


#include <bits/stdc++.h>
#define al(c) c.begin(),c.end()
#define sz(c) ll(c.size())
#define ll long long
#define tr(a,it) for(auto it=a.begin(); it!=a.end(); it++)
#define present(c, x)(c.find(x) != c.end())
#define cpresent(c, x)(find(al(c), x) != c.end())
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define vvpll vector<vpll>
#define pll pair<ll,ll>
#define inf 1e18
#define MOD 1000000007
#define moda 998244353
#define MAXN 1
#define loop(i,s,e) for(ll i=s; i<e; i++)
#define revloop(i,s,e) for(ll i=s; i>=e; i--)
#define newl cout << endl

using namespace std;

/////////////////////////////////////////////////////////////////////////////////////

// DEBUG GG

#define debug(x)     \
  cout << #x << " "; \
  _print(x);         \
  cout << endl;

void _print(int x) {
	cout << x;
}

void _print(char x) {
	cout << x;
}

void _print(string s) {
	cout << s;
}

void _print(ll x) {
	cout << x;
}

void _print(bool a) {
	cout << a;
}

template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
	cout << "{";
	_print(p.first);
	cout << ",";
	_print(p.second);
	cout << "}";
}
template <class T>
void _print(vector<T> v) {
	cout << "[ ";
	for (T i : v) {
		_print(i);
		cout << " ";
	}
	cout << "]";
}

template <class T>
void _print(set<T> st) {
	cout << "[ ";
	for (T i : st) {
		_print(i);
		cout << " ";
	}
	cout << "]";
}

template <class T>
void _print(multiset<T> v) {
	cout << "[ ";
	for (T i : v) {
		_print(i);
		cout << " ";
	}
	cout << "]";
}

template <class T, class V>
void _print(map<T, V> v) {
	cout << "[ ";
	for (auto i : v) {
		_print(i);
		cout << " ";
	}
	cout << "]";
}

/////////////////////////////////////////////////////////////////////////////////////

ll cyclen(ll i, ll n) {
	return (i % n + (i % n == 0) * n);
}

ll power(ll a, ll b, ll mod) {
	ll p = 1;
	while(b > 0) {
		if(b & 1)
			p = (p * a) % mod;
		a = (a * a) % mod;
		b = b >> 1;
	}
	return p;
}

ll gcd(ll a, ll b) {
	if(!(a % b)) return b;
	return gcd(b, a % b);
}

ll inv_mod(ll n, ll mod) {
	ll pow = mod - 2;
	return power(n, pow, mod);
}

ll MSB(ll n)
{
	ll b = 0;
	while (n) {
		b++;
		n /= 2;
	}
	return b;
}

void solve(int tc) {
    ll n;
    cin>>n;
    vll a(n);
    loop(i,0,n){
        cin>>a[i];
    }
    loop(i,0,n-1){
        if(a[i] < a[i+1]){
            a[i+1] = a[i+1] - a[i];
            a[i] = 0;
        }
    }
    loop(i,0,n-1){
        if(a[i] > a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;

}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	cin >> t;
	int tc = 0;
	while (t--) {
		tc++;
		solve(tc);
	}

	return 0;
}

#include <bits/stdc++.h>
#define al(c) c.begin(),c.end()
#define sz(c) ll(c.size())
#define ll long long
#define tr(a,it) for(auto it=a.begin(); it!=a.end(); it++)
#define present(c, x)(c.find(x) != c.end())
#define cpresent(c, x)(find(al(c), x) != c.end())
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define vvpll vector<vpll>
#define pll pair<ll,ll>
#define inf 1e18
#define MOD 1000000007
#define moda 998244353
#define MAXN 1
#define loop(i,s,e) for(ll i=s; i<e; i++)
#define revloop(i,s,e) for(ll i=s; i>=e; i--)
#define newl cout << endl

using namespace std;

/////////////////////////////////////////////////////////////////////////////////////

// DEBUG GG

#define debug(x)     \
  cout << #x << " "; \
  _print(x);         \
  cout << endl;

void _print(int x) {
	cout << x;
}

void _print(char x) {
	cout << x;
}

void _print(string s) {
	cout << s;
}

void _print(ll x) {
	cout << x;
}

void _print(bool a) {
	cout << a;
}

template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
	cout << "{";
	_print(p.first);
	cout << ",";
	_print(p.second);
	cout << "}";
}
template <class T>
void _print(vector<T> v) {
	cout << "[ ";
	for (T i : v) {
		_print(i);
		cout << " ";
	}
	cout << "]";
}

template <class T>
void _print(set<T> st) {
	cout << "[ ";
	for (T i : st) {
		_print(i);
		cout << " ";
	}
	cout << "]";
}

template <class T>
void _print(multiset<T> v) {
	cout << "[ ";
	for (T i : v) {
		_print(i);
		cout << " ";
	}
	cout << "]";
}

template <class T, class V>
void _print(map<T, V> v) {
	cout << "[ ";
	for (auto i : v) {
		_print(i);
		cout << " ";
	}
	cout << "]";
}

/////////////////////////////////////////////////////////////////////////////////////

ll cyclen(ll i, ll n) {
	return (i % n + (i % n == 0) * n);
}

ll power(ll a, ll b, ll mod) {
	ll p = 1;
	while(b > 0) {
		if(b & 1)
			p = (p * a) % mod;
		a = (a * a) % mod;
		b = b >> 1;
	}
	return p;
}

ll gcd(ll a, ll b) {
	if(!(a % b)) return b;
	return gcd(b, a % b);
}

ll inv_mod(ll n, ll mod) {
	ll pow = mod - 2;
	return power(n, pow, mod);
}

ll MSB(ll n)
{
	ll b = 0;
	while (n) {
		b++;
		n /= 2;
	}
	return b;
}

void solve(int tc) {
    ll n;
    cin>>n;
    vll a(n);
    loop(i,0,n){
        cin>>a[i];
    }
    loop(i,0,n-1){
        if(a[i] < a[i+1]){
            a[i+1] = a[i+1] - a[i];
            a[i] = 0;
        }
        else{
            a[i] = a[i] - a[i+1];
            a[i+1] = 0;
        }
    }
    loop(i,0,n-1){
        if(a[i] > a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;

}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	cin >> t;
	int tc = 0;
	while (t--) {
		tc++;
		solve(tc);
	}

	return 0;
}

Answer: 2