ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>

using namespace std;

#define int long long 
#define PII pair<int, int>

const int N = 2e5 + 10, M = 4e5 + 10;

int n;
vector<int> edge[N];
bool st[N];

void dfs(int u)
{
	if (st[u]) return;
	st[u] = true;
	for (auto v : edge[u]) dfs(v);
}

void sol()
{
	memset(st, 0, sizeof st);
	cin >> n;
	for (int i = 1; i <= n; i++) edge[i].clear();
	for (int i = 1; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	int res = 0;
	for (int i = 1; i <= n; i++)
		if (!st[i])
		{
			res++;
			dfs(i);
		}
	set<PII> S;
	for (int i = 1; i <= n; i++) S.insert({edge[i].size(), i});
	auto it = prev(S.end());
	res += it->first - 1;
	for (auto v : edge[it->second])
	{
		S.erase({edge[v].size(), v});
		S.insert({edge[v].size() - 1, v});
	}
	S.erase(it);
	res += prev(S.end())->first - 1;
	cout << res << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin >> T;
	while (T--) sol();
	return 0;
} 

Submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 2e5 + 10, M = 4e5 + 10;

int n;
vector<int> edge[N];
bool st[N];

void dfs(int u)
{
	if (st[u]) return;
	st[u] = true;
	for (auto v : edge[u]) dfs(v);
}

void sol()
{
	memset(st, 0, sizeof st);
	cin >> n;
	for (int i = 1; i <= n; i++) edge[i].clear();
	for (int i = 1; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		if (!st[i])
		{
			cnt++;
			dfs(i);
		}
	multiset<int> S, s;
	for (int i = 1; i <= n; i++) S.insert(edge[i].size());
	int res = 0;
	for (int i = 1; i <= n; i++)
	{
		s = S;
		s.erase(s.find(edge[i].size()));
		for (auto v : edge[i])
		{
			s.erase(s.find(edge[v].size()));
			s.insert(edge[v].size() - 1);
		}
		res = max(res, cnt + (int)edge[i].size() + *prev(s.end()) - 2);
	}
	cout << res << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin >> T;
	while (T--) sol();
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>

using namespace std;

#define int long long 
#define PII pair<int, int>

const int N = 2e5 + 10, M = 4e5 + 10;

int n;
vector<int> edge[N];
bool st[N];

void dfs(int u)
{
	if (st[u]) return;
	st[u] = true;
	for (auto v : edge[u]) dfs(v);
}

void sol()
{
	memset(st, 0, sizeof st);
	cin >> n;
	for (int i = 1; i <= n; i++) edge[i].clear();
	for (int i = 1; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	int res = 0;
	for (int i = 1; i <= n; i++)
		if (!st[i])
		{
			res++;
			dfs(i);
		}
	set<PII> S;
	for (int i = 1; i <= n; i++) S.insert({edge[i].size(), i});
	auto it = prev(S.end());
	res += it->first - 1;
	for (auto v : edge[it->second])
	{
		S.erase({edge[v].size(), v});
		S.insert({edge[v].size() - 1, v});
	}
	S.erase(it);
	res += prev(S.end())->first - 1;
	cout << res << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin >> T;
	while (T--) sol();
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 2e5 + 10, M = 4e5 + 10;

int n;
vector<int> edge[N];
bool st[N];

void dfs(int u)
{
	if (st[u]) return;
	st[u] = true;
	for (auto v : edge[u]) dfs(v);
}

void sol()
{
	memset(st, 0, sizeof st);
	cin >> n;
	for (int i = 1; i <= n; i++) edge[i].clear();
	for (int i = 1; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		if (!st[i])
		{
			cnt++;
			dfs(i);
		}
	multiset<int> S, s;
	for (int i = 1; i <= n; i++) S.insert(edge[i].size());
	int res = 0;
	for (int i = 1; i <= n; i++)
	{
		s = S;
		s.erase(s.find(edge[i].size()));
		for (auto v : edge[i])
		{
			s.erase(s.find(edge[v].size()));
			s.insert(edge[v].size() - 1);
		}
		res = max(res, cnt + (int)edge[i].size() + *prev(s.end()) - 2);
	}
	cout << res << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin >> T;
	while (T--) sol();
	return 0;
} 

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

using namespace std;

#define int long long

const int N = 2e5 + 10, M = 4e5 + 10;

int n;
vector<int> edge[N];
bool st[N];

void dfs(int u)
{
	if (st[u]) return;
	st[u] = true;
	for (auto v : edge[u]) dfs(v);
}

void sol()
{
	memset(st, 0, sizeof st);
	cin >> n;
	for (int i = 1; i <= n; i++) edge[i].clear();
	for (int i = 1; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		if (!st[i])
		{
			cnt++;
			dfs(i);
		}
	multiset<int> S;
	for (int i = 1; i <= n; i++) S.insert(edge[i].size());
	int res = 0;
	for (int i = 1; i <= n; i++)
	{
		S.erase(S.find(edge[i].size()));
		for (auto v : edge[i])
		{
			S.erase(S.find(edge[v].size()));
			S.insert(edge[v].size() - 1);
		}
		res = max(res, cnt + (int)edge[i].size() + *prev(S.end()) - 2);
		S.insert(edge[i].size());
		for (auto v : edge[i])
		{
			S.erase(S.find(edge[v].size() - 1));
			S.insert(edge[v].size());
		}
	}
	cout << res << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin >> T;
	while (T--) sol();
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>

using namespace std;



void solve(){

    int n , l , r;

    cin>>n>>l>>r;

    vector<int> acc1(n,0);

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

        cin>>acc1[i];

    }

    vector<int> left;

    vector<int> right;



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

        if(i<l-1){

            right.push_back(acc1[i]);

        }

        else if(i<r){

            right.push_back(acc1[i]);

            left.push_back(acc1[i]);

        }

        else{

            left.push_back(acc1[i]);

        }

    }

    sort(left.begin(),left.end());

    sort(right.begin(),right.end());



    int sumleft = 0;

    int sumright = 0;

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

        sumleft+=left[i];

        sumright+=right[i];

    }

    cout<<min(sumleft,sumright)<<endl;



}



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);cout.tie(NULL);

    int rounds;

    cin>>rounds;

    while(rounds--){

        solve();

    }

    return 0;

}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;



void solve(){

    int n , l , r;

    cin>>n>>l>>r;

    vector<int> acc1(n,0);

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

        cin>>acc1[i];

    }

    vector<int> left;

    vector<int> right;



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

        if(i<l-1){

            right.push_back(acc1[i]);

        }

        else if(i<=r){

            right.push_back(acc1[i]);

            left.push_back(acc1[i]);

        }

        else{

            left.push_back(acc1[i]);

        }

    }

    sort(left.begin(),left.end());

    sort(right.begin(),right.end());



    int sumleft = 0;

    int sumright = 0;

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

        sumleft+=left[i];

        sumright+=right[i];

    }

    cout<<min(sumleft,sumright)<<endl;



}



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);cout.tie(NULL);

    int rounds;

    cin>>rounds;

    while(rounds--){

        solve();

    }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;



void solve(){

    int n , l , r;

    cin>>n>>l>>r;

    vector<int> acc1(n,0);

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

        cin>>acc1[i];

    }

    vector<int> left;

    vector<int> right;



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

        if(i<l-1){

            right.push_back(acc1[i]);

        }

        else if(i<=r){

            right.push_back(acc1[i]);

            left.push_back(acc1[i]);

        }

        else{

            left.push_back(acc1[i]);

        }

    }

    sort(left.begin(),left.end());

    sort(right.begin(),right.end());



    int sumleft = 0;

    int sumright = 0;

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

        sumleft+=left[i];

        sumright+=right[i];

    }

    cout<<min(sumleft,sumright)<<endl;



}



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);cout.tie(NULL);

    int rounds;

    cin>>rounds;

    while(rounds--){

        solve();

    }

    return 0;

}

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

using namespace std;



void solve(){

    int n , l , r;

    cin>>n>>l>>r;

    vector<int> acc1(n,0);

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

        cin>>acc1[i];

    }

    vector<int> left;

    vector<int> right;



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

        if(i<l-1){

            right.push_back(acc1[i]);

        }

        else if(i<r){

            right.push_back(acc1[i]);

            left.push_back(acc1[i]);

        }

        else{

            left.push_back(acc1[i]);

        }

    }

    sort(left.begin(),left.end());

    sort(right.begin(),right.end());



    long long sumleft = 0;

    long long sumright = 0;

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

        sumleft+=left[i];

        sumright+=right[i];

    }

    cout<<min(sumleft,sumright)<<endl;



}



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);cout.tie(NULL);

    int rounds;

    cin>>rounds;

    while(rounds--){

        solve();

    }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>

using namespace std;



void solve(){

    int n , l , r;

    cin>>n>>l>>r;

    vector<int> acc1(n,0);

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

        cin>>acc1[i];

    }

    vector<int> left;

    vector<int> right;



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

        if(i<l-1){

            right.push_back(acc1[i]);

        }

        else if(i<r){

            right.push_back(acc1[i]);

            left.push_back(acc1[i]);

        }

        else{

            left.push_back(acc1[i]);

        }

    }

    sort(left.begin(),left.end());

    sort(right.begin(),right.end());



    int sumleft = 0;

    int sumright = 0;

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

        sumleft+=left[i];

        sumright+=right[i];

    }

    cout<<min(sumleft,sumright)<<endl;



}



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);cout.tie(NULL);

    int rounds;

    cin>>rounds;

    while(rounds--){

        solve();

    }

    return 0;

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

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int maxint = INT_MAX;// 2147483647
int minint = INT_MIN;// -2147483648
long long maxll = LLONG_MAX;// 9223372036854775807
long long minll = LLONG_MIN;// -9223372036854775808
ll jc(ll n){
    if(n==1||n==0)
    return (ll)1;
    else
    return n*jc(n-1);
}
void yes(){
    cout<<"Yes\n";
}
void no(){
    cout<<"No\n";
}
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
}
ll qpow(ll a, ll k, ll p)
{
    ll res = 1;
    while (k)
    {
        if (k & 1)
            res = (ll)res * a % p;
        a = (ll)a * a % p;
        k >>= 1;
    }
    return res;
}
void solve(){
    //cout<<(15^16)+(17^16)+(15^17);
    ll l,r;
    cin>>l>>r;
    int i=0;
    for(i=31;i>=0;i--){
        if((l>>i)!=(r>>i))
            break;
    }
    cout<<(1<<i)<<" "<<((1<<i)-1)<<" "<<((1<<i)-2>=l?(1<<i)-2:(1<<i)+1);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t=1;
    cin>>t;
    for(int i=0;i<t;i++){
        solve();
        cout<<'\n';
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int maxint = INT_MAX;// 2147483647
int minint = INT_MIN;// -2147483648
long long maxll = LLONG_MAX;// 9223372036854775807
long long minll = LLONG_MIN;// -9223372036854775808
ll jc(ll n){
    if(n==1||n==0)
    return (ll)1;
    else
    return n*jc(n-1);
}
void yes(){
    cout<<"Yes\n";
}
void no(){
    cout<<"No\n";
}
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
}
ll qpow(ll a, ll k, ll p)
{
    ll res = 1;
    while (k)
    {
        if (k & 1)
            res = (ll)res * a % p;
        a = (ll)a * a % p;
        k >>= 1;
    }
    return res;
}
void solve(){
    //cout<<(15^16)+(17^16)+(15^17);
    ll l,r;
    cin>>l>>r;
    ll i=0;
    ll ans=0;
    for(i=31;i>=0;i--){
        if((l>>i)!=(r>>i))
            break;
        else
            ans+=((l>>i)&1)<<i;
    }
    cout<<ans+(1<<i)<<" "<<ans+((1<<i)-1)<<" "<<ans+((1<<i)-2>=l?(1<<i)-2:(1<<i)+1);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t=1;
    cin>>t;
    for(int i=0;i<t;i++){
        solve();
        cout<<'\n';
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int maxint = INT_MAX;// 2147483647
int minint = INT_MIN;// -2147483648
long long maxll = LLONG_MAX;// 9223372036854775807
long long minll = LLONG_MIN;// -9223372036854775808
ll jc(ll n){
    if(n==1||n==0)
    return (ll)1;
    else
    return n*jc(n-1);
}
void yes(){
    cout<<"Yes\n";
}
void no(){
    cout<<"No\n";
}
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
}
ll qpow(ll a, ll k, ll p)
{
    ll res = 1;
    while (k)
    {
        if (k & 1)
            res = (ll)res * a % p;
        a = (ll)a * a % p;
        k >>= 1;
    }
    return res;
}
void solve(){
    //cout<<(15^16)+(17^16)+(15^17);
    ll l,r;
    cin>>l>>r;
    int i=0;
    for(i=31;i>=0;i--){
        if((l>>i)!=(r>>i))
            break;
    }
    cout<<(1<<i)<<" "<<((1<<i)-1)<<" "<<((1<<i)-2>=l?(1<<i)-2:(1<<i)+1);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t=1;
    cin>>t;
    for(int i=0;i<t;i++){
        solve();
        cout<<'\n';
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int maxint = INT_MAX;// 2147483647
int minint = INT_MIN;// -2147483648
long long maxll = LLONG_MAX;// 9223372036854775807
long long minll = LLONG_MIN;// -9223372036854775808
ll jc(ll n){
    if(n==1||n==0)
    return (ll)1;
    else
    return n*jc(n-1);
}
void yes(){
    cout<<"Yes\n";
}
void no(){
    cout<<"No\n";
}
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
}
ll qpow(ll a, ll k, ll p)
{
    ll res = 1;
    while (k)
    {
        if (k & 1)
            res = (ll)res * a % p;
        a = (ll)a * a % p;
        k >>= 1;
    }
    return res;
}
void solve(){
    //cout<<(15^16)+(17^16)+(15^17);
    ll l,r;
    cin>>l>>r;
    ll i=0;
    ll ans=0;
    for(i=31;i>=0;i--){
        if((l>>i)!=(r>>i))
            break;
        else
            ans+=((l>>i)&1)<<i;
    }
    cout<<ans+(1<<i)<<" "<<ans+((1<<i)-1)<<" "<<ans+((1<<i)-2>=l?(1<<i)-2:(1<<i)+1);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t=1;
    cin>>t;
    for(int i=0;i<t;i++){
        solve();
        cout<<'\n';
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int maxint = INT_MAX;// 2147483647
int minint = INT_MIN;// -2147483648
long long maxll = LLONG_MAX;// 9223372036854775807
long long minll = LLONG_MIN;// -9223372036854775808
ll jc(ll n){
    if(n==1||n==0)
    return (ll)1;
    else
    return n*jc(n-1);
}
void yes(){
    cout<<"Yes\n";
}
void no(){
    cout<<"No\n";
}
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
}
ll qpow(ll a, ll k, ll p)
{
    ll res = 1;
    while (k)
    {
        if (k & 1)
            res = (ll)res * a % p;
        a = (ll)a * a % p;
        k >>= 1;
    }
    return res;
}
void solve(){
    //cout<<(15^16)+(17^16)+(15^17);
    ll l,r;
    cin>>l>>r;
    ll i=0;
    ll ans=0;
    for(i=31;i>=0;i--){
        if((l>>i)!=(r>>i))
            break;
        else
            ans+=((l>>i)&1)<<i;
    }
    cout<<ans+(1<<i)<<" "<<ans+((1<<i)-1)<<" "<<(ans+(1<<i)-2>=l?ans+(1<<i)-2:ans+(1<<i)+1);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t=1;
    cin>>t;
    for(int i=0;i<t;i++){
        solve();
        cout<<'\n';
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#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;
        cout<<l<<' '<<ret<<' '<<r<<'\n';
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#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';
    }
}

Submission (verdict: Accepted):
#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';
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#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;
        cout<<l<<' '<<ret<<' '<<r<<'\n';
    }
}

Submission (verdict: Wrong answer on test 2):
#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';
    }
}