ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>

using namespace std;
#define fore(i, l, r)                                      \
  for (auto i = (l) - ((l) > (r)); i != (r) - ((l) > (r)); \
       i += 1 - 2 * ((l) > (r)))
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using ld = long double;
using lli = long long;
using ii = pair<int, int>;

const int N = 1e3;

string a, b, c;
int mem[N][N];
int done[N][N];
int timer = 0;

int dp(int ai, int bi){
    int ci = ai + bi;
    debug(ai, bi, ci);
    if(ai > sz(a) || bi > sz(b)){
        return 2 * N + 20;
    }
    if(ci >= sz(c)){
        return 0;
    }

    auto & ans = mem[ai][bi];
    auto vis = done[ai][bi];

    if(vis != timer){
        vis = timer;
        ans = 0;

        int conta = 0, contb = 0;
        if(a[ai] != c[ci]){
            debug( ai, a[ai], c[ci]);
            conta++;
        }
        if(b[bi] != c[ci]){
            debug(bi, b[bi], c[ci]);
            contb++;
        }

        ans = min(dp(ai + 1, bi) + conta, dp(ai, bi + 1) + contb);
    }

    return ans;
}

int main() {
    cin.tie(0)->sync_with_stdio(0), cout.tie(0);
    timer = 0;
    int t; cin >> t;

    fore(_, 0, t){
        timer ++;
        cin >> a >> b >> c;

        int p = dp(0, 0);
        debug(p);
        cout << p << '\n';
    }
    return 0;
}

Submission (verdict: Runtime error on test 16):
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>

using namespace std;
#define fore(i, l, r)                                      \
  for (auto i = (l) - ((l) > (r)); i != (r) - ((l) > (r)); \
       i += 1 - 2 * ((l) > (r)))
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using ld = long double;
using lli = long long;
using ii = pair<int, int>;

const int N = 1e3;

string a, b, c;
int mem[N][N];
int done[N][N];
int timer = 0;

int dp(int ai, int bi){
    int ci = ai + bi;
    debug(ai, bi, ci);
    if(ai > sz(a) || bi > sz(b)){
        return 2 * N + 20;
    }
    if(ci >= sz(c)){
        return 0;
    }

    auto & ans = mem[ai][bi];
    auto & vis = done[ai][bi];

    if(vis != timer){
        vis = timer;
        ans = 0;

        int conta = 0, contb = 0;
        if(a[ai] != c[ci]){
            debug( ai, a[ai], c[ci]);
            conta++;
        }
        if(b[bi] != c[ci]){
            debug(bi, b[bi], c[ci]);
            contb++;
        }

        ans = min(dp(ai + 1, bi) + conta, dp(ai, bi + 1) + contb);
    }

    return ans;
}

int main() {
    cin.tie(0)->sync_with_stdio(0), cout.tie(0);
    timer = 0;
    int t; cin >> t;

    fore(_, 0, t){
        timer ++;
        cin >> a >> b >> c;

        int p = dp(0, 0);
        debug(p);
        cout << p << '\n';
    }
    return 0;
}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)


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

#define ll long long

#define fastIo() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;







void solve() {

    int n, x, y; cin >> n >> x >> y;

    vector<int> arr(n, -1);

    x--; y--;

    arr[x]=0;

    if(x+1==n) arr[0]=1;

    else arr[x+1]=1;

    if(x==0) arr[n-1]=1;

    else arr[x-1]=1;



    if(arr[y]==-1){

        arr[y]=1;

        if(y+1==n && arr[0]==-1)arr[0]=0;

        else if(arr[y+1]==-1) arr[y+1]=0;

        if(y==0 && arr[n-1]==-1) arr[n-1]=0;

        else if(arr[y-1]==-1) arr[y-1]=0;

    }

    int cnt;

    if(x+1==n) cnt=0;

    else cnt=x+1;



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

        if(cnt == x || cnt==y){

            if(cnt+1==n) cnt=0;

            else cnt++;

            continue;

        }



        int prev=-1, aft=-1;

        if(cnt==0) prev=arr[n-1];

        else prev=arr[cnt-1];



        if(cnt+1==n && arr[0]!=-1) aft=arr[0];

        else if(cnt+1<n && arr[cnt+1]!=-1) aft=arr[cnt+1];



        // cout<<aft<<'\n';

        if(aft==-1 && cnt+1==n){

            arr[0]=prev; aft=arr[0];

        }

        else if(cnt+1 < n && aft==-1){

             arr[cnt+1]=prev; aft=arr[cnt+1];

        }



        if(arr[cnt] == prev || arr[cnt]==aft) arr[cnt]=2;

        if(cnt+1==n) cnt=0;

        else cnt++;

    }

    

    

    for(auto &it:arr) cout<<it<<" ";

    cout<<'\n';

}



int main() {

    fastIo();

    int t = 1;

    cin >> t;

    for(int i = 0; i < t; i++) solve();

}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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

#define ll long long

#define fastIo() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;







void solve() {

    int n, x, y; cin >> n >> x >> y;

    vector<int> arr(n, -1);

    x--; y--;

    arr[x]=0;

    if(x+1==n) arr[0]=1;

    else arr[x+1]=1;

    if(x==0) arr[n-1]=1;

    else arr[x-1]=1;



    if(arr[y]==-1){

        arr[y]=1;

        if(y+1==n && arr[0]==-1)arr[0]=0;

        else if(arr[y+1]==-1) arr[y+1]=0;

        if(y==0 && arr[n-1]==-1) arr[n-1]=0;

        else if(arr[y-1]==-1) arr[y-1]=0;

    }

    int cnt;

    if(x+1==n) cnt=0;

    else cnt=x+1;



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

        if(cnt == x || cnt==y){

            if(cnt+1==n) cnt=0;

            else cnt++;

            continue;

        }



        int prev=-1, aft=-1;

        if(cnt==0) prev=arr[n-1];

        else prev=arr[cnt-1];



        if(cnt+1==n && arr[0]!=-1) aft=arr[0];

        else if(cnt+1<n && arr[cnt+1]!=-1) aft=arr[cnt+1];



        // cout<<aft<<'\n';

        if(aft==-1 && cnt+1==n){

            arr[0]=prev; aft=arr[0];

        }

        else if(cnt+1 < n && aft==-1){

             arr[cnt+1]=prev; aft=arr[cnt+1];

        }



        if(arr[cnt] == prev || arr[cnt]==aft) arr[cnt]=2;

        if(cnt+1==n) cnt=0;

        else cnt++;

    }

    

    

    for(auto &it:arr) cout<<it<<" ";

    cout<<'\n';

}



int main() {

    fastIo();

    int t = 1;

    cin >> t;

    for(int i = 0; i < t; i++) solve();

}

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

#define ll long long

#define fastIo() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;







void solve() {

    int n, x, y; cin >> n >> x >> y;

    vector<int> arr(n, -1);

    x--; y--;

    arr[x]=0;

    if (x + 1 < n) arr[x+1]=1;

    else arr[0]=1;

    

    if (x-1>=0) arr[x-1]=1;

    else arr[n-1]=1;



    if(arr[y]==-1){

        arr[y]=1;

        if (y + 1 < n && arr[y + 1] == -1) arr[y + 1] = 0;

        else if (y + 1 == n && arr[0] == -1) arr[0] = 0;

        

        if (y - 1 >= 0 && arr[y - 1] == -1) arr[y - 1] = 0;

        else if (y - 1 < 0 && arr[n - 1] == -1) arr[n - 1] = 0;

    }

    int cnt = (x + 1 == n) ? 0 : x + 1;



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

        if(cnt == x || cnt==y){

            cnt=(cnt+1)%n;

            continue;

        }



        int prev = (cnt == 0) ? arr[n - 1] : arr[cnt - 1];

        int aft = -1;



        if (cnt + 1 < n && arr[cnt + 1] != -1) aft = arr[cnt + 1];

        else if (cnt + 1 == n && arr[0] != -1) aft = arr[0];



        if (aft == -1) {

            if (cnt + 1 == n) arr[0] = prev, aft = arr[0];

            else arr[cnt + 1] = prev, aft = arr[cnt + 1];

        }



        if (arr[cnt] == -1 || arr[cnt] == prev || arr[cnt] == aft) arr[cnt] = 2;

        cnt = (cnt + 1) % n; 

    }

    

    

    for(auto &it:arr) cout<<it<<" ";

    cout<<'\n';

}



int main() {

    fastIo();

    int t = 1;

    cin >> t;

    for(int i = 0; i < t; i++) solve();

}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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

#define ll long long

#define fastIo() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;







void solve() {

    int n, x, y; cin >> n >> x >> y;

    vector<int> arr(n, -1);

    x--; y--;

    arr[x]=0;

    if (x + 1 < n) arr[x+1]=1;

    else arr[0]=1;

    

    if (x-1>=0) arr[x-1]=1;

    else arr[n-1]=1;



    if(arr[y]==-1){

        arr[y]=1;

        if (y + 1 < n && arr[y + 1] == -1) arr[y + 1] = 0;

        else if (y + 1 == n && arr[0] == -1) arr[0] = 0;

        

        if (y - 1 >= 0 && arr[y - 1] == -1) arr[y - 1] = 0;

        else if (y - 1 < 0 && arr[n - 1] == -1) arr[n - 1] = 0;

    }

    int cnt = (x + 1 == n) ? 0 : x + 1;



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

        if(cnt == x || cnt==y){

            cnt=(cnt+1)%n;

            continue;

        }



        int prev = (cnt == 0) ? arr[n - 1] : arr[cnt - 1];

        int aft = -1;



        if (cnt + 1 < n && arr[cnt + 1] != -1) aft = arr[cnt + 1];

        else if (cnt + 1 == n && arr[0] != -1) aft = arr[0];



        if (aft == -1) {

            if (cnt + 1 == n) arr[0] = prev, aft = arr[0];

            else arr[cnt + 1] = prev, aft = arr[cnt + 1];

        }



        if (arr[cnt] == -1 || arr[cnt] == prev || arr[cnt] == aft) arr[cnt] = 2;

        cnt = (cnt + 1) % n; 

    }

    

    

    for(auto &it:arr) cout<<it<<" ";

    cout<<'\n';

}



int main() {

    fastIo();

    int t = 1;

    cin >> t;

    for(int i = 0; i < t; i++) solve();

}

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

#define ll long long

#define fastIo() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;







void solve() {

    int n, x, y; cin >> n >> x >> y;

    vector<int> arr(n, -1);

    x--; y--;

    arr[x]=0;

    if (x + 1 < n) arr[x+1]=1;

    else arr[0]=1;

    

    if (x-1>=0) arr[x-1]=1;

    else arr[n-1]=1;



    if(arr[y]==-1){

        arr[y]=1;

        if (y + 1 < n && arr[y + 1] == -1) arr[y + 1] = 0;

        else if (y + 1 == n && arr[0] == -1) arr[0] = 0;

        

        if (y - 1 >= 0 && arr[y - 1] == -1) arr[y - 1] = 0;

        else if (y - 1 < 0 && arr[n - 1] == -1) arr[n - 1] = 0;

    }



    int cnt = (x + 1 == n) ? 0 : x + 1;



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





        int prev = (cnt == 0) ? arr[n - 1] : arr[cnt - 1];

        int aft = -1;



        if (cnt + 1 < n && arr[cnt + 1] != -1) aft = arr[cnt + 1];

        else if (cnt + 1 == n && arr[0] != -1) aft = arr[0];



        if (aft == -1) {

            if (cnt + 1 == n) arr[0] = prev, aft = arr[0];

            else arr[cnt + 1] = prev, aft = arr[cnt + 1];

        }



        if(cnt == x || cnt==y){

            cnt=(cnt+1)%n;

            continue;

        }



        if (arr[cnt] == prev || arr[cnt] == aft) arr[cnt] = 2;

        cnt = (cnt + 1) % n; 

    }

    

    

    for(auto &it:arr) cout<<it<<" ";

    cout<<'\n';

}



int main() {

    fastIo();

    int t = 1;

    cin >> t;

    for(int i = 0; i < t; i++) solve();

}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define fastIo() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

void solve(){
    ll l, r; cin >> l >> r;
    int cnt=0;

    if(r-l==2){
        cout<<r<<" "<<r-1<<" "<<r-2<<'\n';
        return;
    }
    for(int i=0; i<=30; i++){
        ll potencia=pow(2, i);
        if(r&potencia){
            cnt=i;
        }
    }

    ll min=l, max=r;
    for(int i=0; i<=cnt; i++){
        ll potencia=pow(2, i);
        if((min&potencia) == (max&potencia) && (min&potencia)){
            if(min-potencia>=l){
                min-=potencia;
            }
            else if(max-potencia>=l){
                max-=potencia;
            }
        }
        else if((min&potencia) == (max&potencia) && !(min&potencia)){
            if(min+potencia<=r){
                min+=potencia;
            }
            else if(max+potencia<=r){
                max+=potencia;
            }
        }   
    }
    ll mid;
    if(min==l){
        mid=l+1;
    }
    else{
        mid=l;
    }

    cout<<mid<<" "<<min<<" "<<max<<'\n';
    
    
}




int main() {
    fastIo();
    int t; cin >> t;
    while(t--) solve();

    return 0;
}

Submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
#define ll long long
#define fastIo() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

void solve(){
    ll l, r; cin >> l >> r;
    int cnt=0;

    // if(r-l==2){
    //     cout<<r<<" "<<r-1<<" "<<r-2<<'\n';
    //     return;
    // }
    for(int i=0; i<=30; i++){
        ll potencia=pow(2, i);
        if(r&potencia){
            cnt=i;
        }
    }

    ll min=l, max=r;
    for(int i=0; i<=cnt; i++){
        ll potencia=pow(2, i);
        if((min&potencia) == (max&potencia) && (min&potencia)){
            if(min-potencia>=l){
                min-=potencia;
            }
            else if(max-potencia>=l){
                max-=potencia;
            }
        }
        else if((min&potencia) == (max&potencia) && !(min&potencia)){
            if(min+potencia<=r){
                min+=potencia;
            }
            else if(max+potencia<=r){
                max+=potencia;
            }
        }   
    }
    ll mid;
    if(min==l || max==l){
        for(int i=l; i<=r; i++){
            if(i!=min && i!=max){
                mid=i;
            }
        }
    }
    else{
        mid=l;
    }

    cout<<mid<<" "<<min<<" "<<max<<'\n';
    
    
}




int main() {
    fastIo();
    int t; cin >> t;
    while(t--) solve();

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
#define ll long long
#define fastIo() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

void solve(){
    ll l, r; cin >> l >> r;
    int cnt=0;

    // if(r-l==2){
    //     cout<<r<<" "<<r-1<<" "<<r-2<<'\n';
    //     return;
    // }
    for(int i=0; i<=30; i++){
        ll potencia=pow(2, i);
        if(r&potencia){
            cnt=i;
        }
    }

    ll min=l, max=r;
    for(int i=0; i<=cnt; i++){
        ll potencia=pow(2, i);
        if((min&potencia) == (max&potencia) && (min&potencia)){
            if(min-potencia>=l){
                min-=potencia;
            }
            else if(max-potencia>=l){
                max-=potencia;
            }
        }
        else if((min&potencia) == (max&potencia) && !(min&potencia)){
            if(min+potencia<=r){
                min+=potencia;
            }
            else if(max+potencia<=r){
                max+=potencia;
            }
        }   
    }
    ll mid;
    if(min==l || max==l){
        for(int i=l; i<=r; i++){
            if(i!=min && i!=max){
                mid=i;
            }
        }
    }
    else{
        mid=l;
    }

    cout<<mid<<" "<<min<<" "<<max<<'\n';
    
    
}




int main() {
    fastIo();
    int t; cin >> t;
    while(t--) solve();

    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
#define fastIo() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

void solve(){
    ll l, r; cin >> l >> r;
    int cnt=0;

    // if(r-l==2){
    //     cout<<r<<" "<<r-1<<" "<<r-2<<'\n';
    //     return;
    // }
    for(int i=0; i<=30; i++){
        ll potencia=pow(2, i);
        if(r&potencia){
            cnt=i;
        }
    }

    ll min=l, max=r;
    for(int i=0; i<=cnt; i++){
        ll potencia=pow(2, i);
        if((min&potencia) == (max&potencia) && (min&potencia)){
            if(min-potencia>=l){
                min-=potencia;
            }
            else if(max-potencia>=l){
                max-=potencia;
            }
        }
        else if((min&potencia) == (max&potencia) && !(min&potencia)){
            if(min+potencia<=r){
                min+=potencia;
            }
            else if(max+potencia<=r){
                max+=potencia;
            }
        }   
    }
    ll mid;
    if(min==l || max==l){
        for(ll i=l; i<=r; i++){
            if(i!=min && i!=max){
                mid=i;
                break;
            }
        }
    }
    else{
        mid=l;
    }

    cout<<mid<<" "<<min<<" "<<max<<'\n';
    
    
}




int main() {
    fastIo();
    int t; cin >> t;
    while(t--) solve();

    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>
#define ll long long
#define fastIo() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

void solve(){
    ll l, r; cin >> l >> r;
    int cnt=0;

    if(r-l==2){
        cout<<r<<" "<<r-1<<" "<<r-2<<'\n';
        return;
    }
    for(int i=0; i<=30; i++){
        ll potencia=pow(2, i);
        if(r&potencia){
            cnt=i;
        }
    }

    ll min=l, max=r;
    for(int i=0; i<=cnt; i++){
        ll potencia=pow(2, i);
        if((min&potencia) == (max&potencia) && (min&potencia)){
            if(min-potencia>=l){
                min-=potencia;
            }
            else if(max-potencia>=l){
                max-=potencia;
            }
        }
        else if((min&potencia) == (max&potencia) && !(min&potencia)){
            if(min+potencia<=r){
                min+=potencia;
            }
            else if(max+potencia<=r){
                max+=potencia;
            }
        }   
    }
    ll mid;
    if(min==l){
        mid=l+1;
    }
    else{
        mid=l;
    }

    cout<<mid<<" "<<min<<" "<<max<<'\n';
    
    
}




int main() {
    fastIo();
    int t; cin >> t;
    while(t--) solve();

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename Key, typename Value>
using ordered_map = tree<Key, Value, less<Key>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename Key, typename Value = null_type>
using trie = trie<Key, Value, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;
#define SET(m, i) ((m) | (1ULL << (i)))
#define TEST(m, i) ((m) & (1ULL << (i)))
#define CLEAR(m, i) ((m) &~ (1ULL << (i)))
#define DEBUG(n) (cout << (n) << endl)
#define CLEAN(arr) (memset(arr, 0, sizeof(arr)))
#define ALL(v) (v).begin(), (v).end()


typedef long long int ll;
typedef std::vector<int> vec;
using namespace std;

const int MAX = 2e5+20;

ll msb(ll n) {
    ll res = -1;
    for(int i = 0; i < 60; i++) {
        if(TEST(n, i)) res = i;
    }
    return res;
}

void sol(){        
    ll l, r;
    cin >> l >> r;
    ll mid = 0;
    ll ms = msb(r);
    for(int i = ms; i > -1; i--) {
        if(TEST(r, i) && TEST(l, i)) {
            if(mid + ((1LL << i) - 1) <= l) {
                mid = SET(mid, i);
            }
        }
        else if(!TEST(r, i) && !TEST(l, i)) {
            if(SET(mid, i) < r) {
                mid = SET(mid, i);
            }
        }
        else if(TEST(r, i) || TEST(l, i)) {
            if(mid + ((1 << i) - 1) <= l) {
                mid = SET(mid, i);
            }
        }
    }
    cout << l << ' ' << mid << ' ' << r << endl;
}

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

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


    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


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

#define ranges std::ranges
#define views std::views

using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

using pii = std::pair<int, int>;
using a3 = std::array<int, 3>;
using a4 = std::array<int, 4>;

const int N = 1e6;
const int MAXN = 1e6 + 10;
const int inf = 1e9;
// const int mod = 1e9 + 7;
const int mod = 998244353;

void solve() {
    int n, m;std::cin >> n >> m;
    std::vector<int> a(n), b(m);
    for (int& x : a)std::cin >> x;
    for (int& x : b)std::cin >> x;
    std::map<int, i64> cnt, bcnt;
    std::set<int, std::greater<int>> st;
    for (int& x : a)cnt[x]++;
    for (int& x : b)bcnt[x]++, st.insert(x);
    while (st.size()) {
        int top = *st.begin();
        st.erase(st.begin());
        i64 c = bcnt[top];
        i64 nc = cnt[top];
        if (nc > c) {
            std::cout << "No";
            return;
        }
        i64 la = c - nc;
        if (la) {
            if (top <= 1) {
                std::cout << "No";
                return;
            }
            if (top % 2) {
                st.insert(top / 2);
                st.insert(top / 2 + 1);
                bcnt[top / 2] += la;
                bcnt[top / 2 + 1] += la;
            }
            else {
                st.insert(top / 2);
                bcnt[top / 2] += la * 2;
            }
        }
    }
    std::cout << "Yes";
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0), std::cout.tie(0);
    int t;std::cin >> t;
    while (t--) {
        solve();
        std::cout << '\n';
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define all(v) (v).begin(),(v).end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define fi first 
#define se second
#define pb push_back

/*------------- Hardwork beats Talent, when Talent doesn't work hard!! -------------*/
const ll infl = 1e17 + 7;
const int inf = 1e8 + 7;
const int mod = 1e9 + 7;


void Hrid_solve(){
    int n;
    cin >> n;
    vector<int> deg(n+1);
    set<pair<int,int>> st;
    for(int i=0; i<n-1; i++){
        int u,v;
        cin >> u >> v;
        deg[u]++;
        deg[v]++;
        st.insert({u,v});
        st.insert({v,u});
    }

    vector<pair<int,int>> vp;
    for(int i=1; i<=n; i++){
        vp.pb({deg[i],i});
    }
    sort(all(vp), greater<pair<int,int>>());

    int ans =0; 
    for(int i=1; i<n; i++){
        if(!st.count({vp[i].se,vp[0].se})){
            ans = max(ans, vp[i].fi+vp[0].fi-1);
        }
        else{
            ans = max(ans, vp[i].fi+vp[0].fi-2);
        }
    }

    cout << ans << endl;

}


/*------------------ Today's decision might impact you Tomorrow !! ------------------*/

int32_t main(){
    fast_IO;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     // freopen("output.txt", "w", stdout);
    // #endif

    int tc = 1;
    cin >> tc;
    for(int kase = 1; kase <= tc; kase++){
        // cout << "Case " << kase << ": \n";
        Hrid_solve();
    }

    return 0;
}