ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int T, l[40], r[40], lenl, lenr;

int main () {
	scanf("%d", &T);
	while (T--) {
		memset(l, 0, sizeof(l)), memset(r, 0, sizeof(r)), lenl = lenr = 0;
		int x, y, L, R;
		scanf("%d%d", &x, &y);
		L = x, R = y;
		while (x)
			l[++lenl] = x & 1, x >>= 1;
		while (y)
			r[++lenr] = y & 1, y >>= 1;
		lenl = lenr;
		int sum = 0, len = lenr, id = 0;
		for (int i = len, base = (1 << len); i; i--, base >>= 1) {
			if (l[i] != r[i]) {
				id = len - i + 1;
				break;
			}
			sum += base;
		}
		int a = sum + (1 << (len - id)), b = a - 1;
		for (int i = R; i >= L; i--)
			if (i != a && i != b) {
				printf("%d %d %d\n", a, b, i);
				break;
			}
	}
	return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int T, l[40], r[40], lenl, lenr;

int main () {
	scanf("%d", &T);
	while (T--) {
		memset(l, 0, sizeof(l)), memset(r, 0, sizeof(r)), lenl = lenr = 0;
		int x, y, L, R;
		scanf("%d%d", &x, &y);
		L = x, R = y;
		while (x)
			l[++lenl] = x & 1, x >>= 1;
		while (y)
			r[++lenr] = y & 1, y >>= 1;
		lenl = lenr;
		int sum = 0, len = lenr, id = 0;
		for (int i = len, base = (1 << len); i; i--, base >>= 1) {
			if (l[i] != r[i]) {
				id = i - 1;
				break;
			}
			sum += base;
		}
		int a = sum + (1 << id), b = a - 1;
		for (int i = R; i >= L; i--)
			if (i != a && i != b) {
				printf("%d %d %d\n", a, b, i);
				break;
			}
	}
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define lc p<<1
#define rc p<<1|1
//#define int long long
#define mp make_pair
#define vi vector<int>
#define vc vector<char>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vvpi vector<vector<pair<int,int>>>
typedef long long ll;
typedef tuple<int,int,int> tp;
typedef pair<int,int> PII;
typedef pair<ll,pair<ll,ll>> PIII;
typedef pair<ll,pair<ll,pair<ll,ll>>> pIIII;
const int N = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
void solve() {
    int n;cin >> n;
    vvi g(n + 1, vi());
    vi d(n + 1, 0);
    for(int i = 1; i <= n - 1; i ++) {
        int u, v;cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
        d[u] ++ , d[v] ++;
    }

    int cnt = 0;

    for(int i = 1; i <= n; i ++) {
        cnt += d[i] >= 2;
    }
    if(cnt == 0) {
        cout << 0 << "\n";
    } else if(cnt == 1) {
        cout << 2 << "\n";
    } else {
        cout << 4 << "\n";
    }
    
}
signed main() {    
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
/*
Do smth instead of nothing and stay organized
Don't get stuck on one approach
*/

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define lc p<<1
#define rc p<<1|1
//#define int long long
#define mp make_pair
#define vi vector<int>
#define vc vector<char>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vvpi vector<vector<pair<int,int>>>
typedef long long ll;
typedef tuple<int,int,int> tp;
typedef pair<int,int> PII;
typedef pair<ll,pair<ll,ll>> PIII;
typedef pair<ll,pair<ll,pair<ll,ll>>> pIIII;
const int N = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
void solve() {
    int n;cin >> n;
    vvi g(n + 1, vi());
    vi d(n + 1, 0);
    for(int i = 1; i <= n - 1; i ++) {
        int u, v;cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
        d[u] ++ , d[v] ++;
    }
    
    int ans = 0;
    multiset<int> st;
    for(int i = 1; i <= n; i ++) {
        st.insert(d[i]);
    }

    for(int i = 1; i <= n; i ++) {
        st.erase(d[i]);
        for(auto v : g[i]) {
            st.erase(d[v]);
        }
        if(!st.empty()) {
            ans = max(ans, d[i] + *st.rbegin() - 1);
        }

        st.insert(d[i]);
        for(auto v : g[i]) {
            st.insert(d[i]);
            ans = max(ans, d[i] + d[v] - 2);
        }
    }
    
    cout << ans << "\n";
    
}
signed main() {    
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
/*
Do smth instead of nothing and stay organized
Don't get stuck on one approach
*/
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define lc p<<1
#define rc p<<1|1
//#define int long long
#define mp make_pair
#define vi vector<int>
#define vc vector<char>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vvpi vector<vector<pair<int,int>>>
typedef long long ll;
typedef tuple<int,int,int> tp;
typedef pair<int,int> PII;
typedef pair<ll,pair<ll,ll>> PIII;
typedef pair<ll,pair<ll,pair<ll,ll>>> pIIII;
const int N = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
void solve() {
    int n;cin >> n;
    vvi g(n + 1, vi());
    vi d(n + 1, 0);
    for(int i = 1; i <= n - 1; i ++) {
        int u, v;cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
        d[u] ++ , d[v] ++;
    }

    int cnt = 0;

    for(int i = 1; i <= n; i ++) {
        cnt += d[i] >= 2;
    }
    if(cnt == 0) {
        cout << 0 << "\n";
    } else if(cnt == 1) {
        cout << 2 << "\n";
    } else {
        cout << 4 << "\n";
    }
    
}
signed main() {    
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
/*
Do smth instead of nothing and stay organized
Don't get stuck on one approach
*/
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
#include<iostream>
#include<cstring>
using namespace std;


int main(){
    int t;
    cin>>t;
    string number;
    int temp;
    int length;
    for(int test=0;test<t;test++){
        cin>>number;
        length=number.size();
        int i=1;
        while(i<length){
            if(number[i]>(number[i-1]+1)){
                temp=number[i];
                number[i]=number[i-1];
                number[i-1]=(temp-1);
                if(i<9){  i=1;}
                else{i=i-(number[i]-'0'); }
              
                 }
            else{
                i++;
            }

        }
        cout<<number<<'\n';





    }

}

Submission (verdict: Accepted):
#include<iostream>
#include<cstring>
using namespace std;


int main(){
    int t;
    cin>>t;
    string number;
    int temp;
    int length;
    for(int test=0;test<t;test++){
        cin>>number;
        length=number.size();
        int i=1;
        while(i<length){
            if(number[i]>(number[i-1]+1)){
                temp=number[i];
                number[i]=number[i-1];
                number[i-1]=(temp-1);
             //   cout<<((number[i-1]-'0'));
                if(i<9){  i=1;}
                else{i=i-(number[i-1]-'0'); }
              
                 }
            else{
                i++;
            }

        }
        cout<<number<<'\n';





    }

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include<iostream>
#include<cstring>
using namespace std;


int main(){
    int t;
    cin>>t;
    string number;
    int temp;
    int length;
    for(int test=0;test<t;test++){
        cin>>number;
        length=number.size();
        int i=1;
        while(i<length){
            if(number[i]>(number[i-1]+1)){
                temp=number[i];
                number[i]=number[i-1];
                number[i-1]=(temp-1);

                i=1;
                 }
            else{
                i++;
            }

        }
        cout<<number<<'\n';





    }

}

Submission (verdict: Wrong answer on test 3):
#include<iostream>
#include<cstring>
using namespace std;


int main(){
    int t;
    cin>>t;
    string number;
    int temp;
    int length;
    for(int test=0;test<t;test++){
        cin>>number;
        length=number.size();
        int i=1;
        while(i<length){
            if(number[i]>(number[i-1]+1)){
                temp=number[i];
                number[i]=number[i-1];
                number[i-1]=(temp-1);
                if(i<9){  i=1;}
                else{i=i-(number[i]-'0'); }
              
                 }
            else{
                i++;
            }

        }
        cout<<number<<'\n';





    }

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 6):
#include<iostream>
#include<cstring>
using namespace std;


int main(){
    int t;
    cin>>t;
    string number;
    int temp;
    int length;
    for(int test=0;test<t;test++){
        cin>>number;
        length=number.size();
        int i=1;
        while(i<length){
            if(number[i]>(number[i-1]+1)){
                temp=number[i];
                number[i]=number[i-1];
                number[i-1]=(temp-1);

                i=1;
                 }
            else{
                i++;
            }

        }
        cout<<number<<'\n';





    }

}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 2):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 55;

vector<int> l;
int t,n;
int ans;

int get(vector<int> l){
    int res = 0;
    for(int i : l){
        res += i;
    }
    return res;
}

void dfs(vector<int> l,bool turn){
    //这个数组rep后的数值和就是rep前的最后一项减第一项
    if(l.size() == 1) return;
    ans = max(ans,l[l.size()-1] - l[0]);//数值rep后的和的大小

    vector<int> rep,rev;
    for(int i=0;i<l.size();i++){
        if(i > 0) rep.push_back(l[i]-l[i-1]);
        rev.push_back(l[l.size()-i-1]);
    }
    //记录rep后的数值和翻转后的数组
    dfs(rep,1);
    if(!turn) return;
    dfs(rev,0);
}

signed main(){
    scanf("%lld",&t);
    while(t--){
        scanf("%lld",&n);
        l.clear();

        for(int i=1;i<=n;i++){
            int x;
            scanf("%lld",&x);
            l.push_back(x);
        }

        ans = get(l);//记录最开始的数值
        dfs(l,1);
        printf("%lld\n",ans);
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 55;

vector<int> l;
int t,n;
int ans;

int get(vector<int> l){
    int res = 0;
    for(int i : l){
        res += i;
    }
    return res;
}

void dfs(vector<int> l){
    //这个数组rep后的数值和就是rep前的最后一项减第一项
    if(l.size() == 1) return;
    int temp = l[l.size()-1] - l[0];
    // printf("temp = %lld\n",temp);
    ans = max(ans,max(temp,-temp));//数值rep后的和的大小
    vector<int> rep;
    for(int i=0;i<l.size();i++){
        if(i > 0) rep.push_back(l[i]-l[i-1]);
    }
    //记录rep后的数值和翻转后的数组
    dfs(rep);
}

signed main(){
    scanf("%lld",&t);
    while(t--){
        scanf("%lld",&n);
        l.clear();

        for(int i=1;i<=n;i++){
            int x;
            scanf("%lld",&x);
            l.push_back(x);
        }

        ans = get(l);//记录最开始的数值
        dfs(l);
        printf("%lld\n",ans);
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 2):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 55;

vector<int> l;
int t,n;
int ans;

int get(vector<int> l){
    int res = 0;
    for(int i : l){
        res += i;
    }
    return res;
}

void dfs(vector<int> l,bool turn){
    if(turn) ans = max(get(l),ans);
    if(l.size() == 1){
        return;
    }

    vector<int> temp;
    for(int i=1;i<l.size();i++)
        temp.push_back(l[i]-l[i-1]);
    
    dfs(temp,1);
    if(!turn) return;
    reverse(l.begin(),l.end());
    dfs(l,0);
}

signed main(){
    scanf("%lld",&t);
    while(t--){
        scanf("%lld",&n);
        l.clear();

        for(int i=1;i<=n;i++){
            int x;
            scanf("%lld",&x);
            l.push_back(x);
        }

        ans = get(l);
        dfs(l,1);
        printf("%lld\n",ans);
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 2):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 55;

vector<int> l;
int t,n;
int ans;

int get(vector<int> l){
    int res = 0;
    for(int i : l){
        res += i;
    }
    return res;
}

void dfs(vector<int> l,bool turn){
    //这个数组rep后的数值和就是rep前的最后一项减第一项
    if(l.size() == 1) return;
    ans = max(ans,l[l.size()-1] - l[0]);//数值rep后的和的大小

    vector<int> rep,rev;
    for(int i=0;i<l.size();i++){
        if(i > 0) rep.push_back(l[i]-l[i-1]);
        rev.push_back(l[l.size()-i-1]);
    }
    //记录rep后的数值和翻转后的数组
    dfs(rep,1);
    if(!turn) return;
    dfs(rev,0);
}

signed main(){
    scanf("%lld",&t);
    while(t--){
        scanf("%lld",&n);
        l.clear();

        for(int i=1;i<=n;i++){
            int x;
            scanf("%lld",&x);
            l.push_back(x);
        }

        ans = get(l);//记录最开始的数值
        dfs(l,1);
        printf("%lld\n",ans);
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 2):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 55;

vector<int> l;
int t,n;
int ans;

int get(vector<int> l){
    int res = 0;
    for(int i : l){
        res += i;
    }
    return res;
}

void dfs(vector<int> l,bool turn){
    if(turn) ans = max(get(l),ans);
    if(l.size() == 1){
        return;
    }

    vector<int> temp;
    for(int i=1;i<l.size();i++)
        temp.push_back(l[i]-l[i-1]);
    
    dfs(temp,1);
    if(!turn) return;
    reverse(l.begin(),l.end());
    dfs(l,0);
}

signed main(){
    scanf("%lld",&t);
    while(t--){
        scanf("%lld",&n);
        l.clear();

        for(int i=1;i<=n;i++){
            int x;
            scanf("%lld",&x);
            l.push_back(x);
        }

        ans = get(l);
        dfs(l,1);
        printf("%lld\n",ans);
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: GNU C11


Submission (verdict: Wrong answer on test 2):
#include <stdio.h>
#include <string.h>

#define N 200000

char s[N + 1];
int T;

int main() {
    scanf("%d", &T); getchar();
    
    for (int i = 0; i < T; i++) {
        scanf("%s", s); getchar();

        int n = strlen(s);
        for (int j = 0; j < n; j++) {
            int ptr = j;
            for (int k = j + 1; k < j + 10; k++) {
                if ((s[k] - '0') - k > (s[ptr] - '0') - ptr) {
                    ptr = k;
                }
            }
            while (ptr > j) {
                s[ptr]--;
                s[ptr - 1] ^= s[ptr];
                s[ptr] ^= s[ptr - 1];
                s[ptr - 1] ^= s[ptr];
                ptr--;
            }
        }

        printf("%s\n", s);
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: GNU C11

Previous submission (verdict: Wrong answer on test 2):
#include <stdio.h>
#include <string.h>

#define N 200000

char s[N + 1];
int T;

int main() {
    scanf("%d", &T); getchar();
    
    for (int i = 0; i < T; i++) {
        scanf("%s", s); getchar();

        int n = strlen(s);
        for (int j = 0; j < n; j++) {
            int ptr = j;
            for (int k = j + 1; k < j + 10; k++) {
                if ((s[k] - '0') - k > (s[ptr] - '0') - ptr) {
                    ptr = k;
                }
            }
            while (ptr > j) {
                s[ptr]--;
                s[ptr - 1] ^= s[ptr];
                s[ptr] ^= s[ptr - 1];
                s[ptr - 1] ^= s[ptr];
                ptr--;
            }
        }

        for (int j = 0; j < n; j++) printf("%c", s[j]); puts("");
    }
    return 0;
}

Submission (verdict: Accepted):
#include <stdio.h>
#include <string.h>

#define N 200000

char s[N + 1];
int T;

int main() {
    scanf("%d", &T); getchar();
    
    for (int i = 0; i < T; i++) {
        scanf("%s", s); getchar();

        int n = strlen(s);
        for (int j = 0; j < n; j++) {
            int ptr = j;
            for (int k = j + 1; k < j + 10 && k < n; k++) {
                if ((s[k] - '0') - k > (s[ptr] - '0') - ptr) {
                    ptr = k;
                }
            }
            while (ptr > j) {
                s[ptr]--;
                s[ptr - 1] ^= s[ptr];
                s[ptr] ^= s[ptr - 1];
                s[ptr - 1] ^= s[ptr];
                ptr--;
            }
        }

        printf("%s\n", s);    
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: GNU C11

Previous submission (verdict: Wrong answer on test 2):
#include <stdio.h>
#include <string.h>

#define N 200000

char s[N + 1];
int T;

int main() {
    scanf("%d", &T); getchar();
    
    for (int i = 0; i < T; i++) {
        scanf("%s", s); getchar();

        int n = strlen(s);
        for (int j = 0; j < n; j++) {
            int ptr = j;
            for (int k = j + 1; k < j + 10; k++) {
                if ((s[k] - '0') - k > (s[ptr] - '0') - ptr) {
                    ptr = k;
                }
            }
            while (ptr > j) {
                s[ptr]--;
                s[ptr - 1] ^= s[ptr];
                s[ptr] ^= s[ptr - 1];
                s[ptr - 1] ^= s[ptr];
                ptr--;
            }
        }

        printf("%s\n", s);
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <stdio.h>
#include <string.h>

#define N 200000

char s[N + 1];
int T;

int main() {
    scanf("%d", &T); getchar();
    
    for (int i = 0; i < T; i++) {
        scanf("%s", s); getchar();

        int n = strlen(s);
        for (int j = 0; j < n; j++) {
            int ptr = j;
            for (int k = j + 1; k < j + 10; k++) {
                if ((s[k] - '0') - k > (s[ptr] - '0') - ptr) {
                    ptr = k;
                }
            }
            while (ptr > j) {
                s[ptr]--;
                s[ptr - 1] ^= s[ptr];
                s[ptr] ^= s[ptr - 1];
                s[ptr - 1] ^= s[ptr];
                ptr--;
            }
        }

        for (int j = 0; j < n; j++) printf("%c", s[j]); puts("");
    }
    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>
using namespace std;
#define int long long
const int N=1e5+5,INF=0x3f3f3f,Mod=1e9+7,J=40;//一些
int T,l,r;
int ans[31];
void solve(){
	scanf("%lld%lld",&l,&r);
	memset(ans,0,sizeof ans);
	cout<<l<<" ";
    bitset<32> x(l),y(r),ans(0);
	int cnt=0;
	for(int i=31;i>=0;i--){
		if(x[i]!=y[i]){
			cnt=i;
			break;
		}else{
			ans[i]=x[i];
		}
	}
	for(int i=cnt;i>=0;i--){
		if(x[i]!=y[i]){
			ans[i]=1;
			if(ans.to_ulong()>=r){
				ans[i]=0;
			}
		}else{
			ans[i]=!x[i];
		}
	}
	cout<<ans.to_ulong()<<" "<<r<<endl;
}
signed/*int*/ main(){
	scanf("%d",&T);
	while(T--){
		solve();
	}
	return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5,INF=0x3f3f3f,Mod=1e9+7,J=40;//一些
int T,l,r;
void solve(){
	scanf("%lld%lld",&l,&r);
	bitset<32> x(l),y(r),ans(0);
	int cnt=31;
	while(cnt>=0){
		if(x[cnt]!=y[cnt]){
			break;
		}
		cnt--;
	}
    for(int i=31;i>cnt;i--){
    	ans[i]=x[i];
	} 
	for(int i=cnt;i>=0;i--){
		if(x[i]==y[i]){
			ans[i]=x[i]^1;
		}
	}
	for(int i=cnt;i>=0;i--){
        if(x[i]!=y[i]){
            ans[i]=1;
            if(ans.to_ulong()>=r){
            	ans[i]=0;
			} 
        }
    }
	cout<<l<<" "<<ans.to_ulong()<<" "<<r<<endl;
}
signed/*int*/ main(){
	scanf("%d",&T);
	while(T--){
		solve();
	}
	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>
using namespace std;
#define int long long
const int N=1e5+5,INF=0x3f3f3f,Mod=1e9+7,J=40;//一些
int T,l,r;
int ans[31];
void solve(){
	scanf("%lld%lld",&l,&r);
	memset(ans,0,sizeof ans);
	cout<<l<<" "<<r<<" ";
    bitset<32> x(l),y(r),ans(0);
	int cnt=0;
	for(int i=31;i>=0;i--){
		if(x[i]!=y[i]){
			cnt=i;
			break;
		}else{
			ans[i]=x[i];
		}
	}
	for(int i=cnt;i>=0;i--){
		if(x[i]!=y[i]){
			ans[i]=1;
			if(ans.to_ulong()>=r){
				ans[i]=0;
			}
		}else{
			ans[i]=!x[i];
		}
	}
	cout<<ans.to_ulong()<<endl;
}
signed/*int*/ main(){
	scanf("%d",&T);
	while(T--){
		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>
using namespace std;
#define int long long
const int N=1e5+5,INF=0x3f3f3f,Mod=1e9+7,J=40;//一些
int T,l,r;
int ans[31];
void solve(){
	scanf("%lld%lld",&l,&r);
	memset(ans,0,sizeof ans);
	cout<<l<<" "<<r<<" ";
    bitset<32> x(l),y(r),ans(0);
	int cnt=0;
	for(int i=31;i>=0;i--){
		if(x[i]!=y[i]){
			cnt=i;
			break;
		}else{
			ans[i]=x[i];
		}
	}
	for(int i=cnt;i>=0;i--){
		if(x[i]!=y[i]){
			ans[i]=1;
			if(ans.to_ulong()>=r){
				ans[i]=0;
			}
		}else{
			ans[i]=!x[i];
		}
	}
	cout<<ans.to_ulong()<<endl;
}
signed/*int*/ main(){
	scanf("%d",&T);
	while(T--){
		solve();
	}
	return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5,INF=0x3f3f3f,Mod=1e9+7,J=40;//一些
int T,l,r;
int ans[31];
void solve(){
	scanf("%lld%lld",&l,&r);
	memset(ans,0,sizeof ans);
	cout<<l<<" ";
    bitset<32> x(l),y(r),ans(0);
	int cnt=0;
	for(int i=31;i>=0;i--){
		if(x[i]!=y[i]){
			cnt=i;
			break;
		}else{
			ans[i]=x[i];
		}
	}
	for(int i=cnt;i>=0;i--){
		if(x[i]!=y[i]){
			ans[i]=1;
			if(ans.to_ulong()>=r){
				ans[i]=0;
			}
		}else{
			ans[i]=!x[i];
		}
	}
	cout<<ans.to_ulong()<<" "<<r<<endl;
}
signed/*int*/ main(){
	scanf("%d",&T);
	while(T--){
		solve();
	}
	return 0;
}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int gcd(int a,int b){
	if(a%b==0){
		return b;
	}
	return gcd(b,a%b);
}
int main(int argc, char** argv) {
	cin>>n;
	while(n-->0){
		int x;
		cin>>x;
		int sum=0;
		for(int i=0;i<x;i++){
			cin>>a[i];
			sum+=a[i];
		}
		if(sum%x==0){
			int sum1=0;
			int sum2=0;
			for(int i=0;i<x;i+=2){
				sum1+=a[i];
			}
			for(int i=1;i<x;i+=2){
				sum2+=a[i];
			}
			if(sum1>=sum2){
				int c=gcd(sum1,sum2);
				if(x%2==1){
					if(sum1%(x/2+1)==0){
						if(sum1==sum2+c&&sum2%(x/2)==0){
							cout<<"YES"<<endl;
						}else{
							cout<<"NO"<<endl;
						}
					}else{
						cout<<"NO"<<endl;
					}
				}else{
					if(sum1==sum2&&sum1%(x/2)==0){
						cout<<"YES"<<endl;
					}else{
						cout<<"NO"<<endl;
					}
				} 
				
			}else{
				cout<<"NO"<<endl;
			}
		}else{
			cout<<"NO"<<endl;
		}
	}
}