ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: Node.js


Submission (verdict: Wrong answer on test 2):
const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

let countInput = 0
let numberTest = 0
let testCase = 0

let inputContainer = []
let outputs = []



const inputProcess = (input) => {
    if (input.length == 1 ) {
        return
    } else {
        testCase++
        inputContainer.push(input)
    }
}


const computeOutput = () => {    
    
    for (const stringNumber of inputContainer) {
        // I can only turn squares on : 1, 2, 3
        // i need to go through the string, look for either 1, 2, or 3 and replace them with possible strings
        let holder = []
        let sum = 0
        let twoCounter = 0
        let threeCounter = 0
        let output = "NO"
        for (let i = 0; i < stringNumber.length; i++) {
            const number = stringNumber[i]
            if (number == "2") 
                twoCounter++
            else if (number == "3")
                threeCounter++
            sum += parseInt(number)
        }

        // console.log(`Sum : ${sum}`)

        let sumGen = 0
        if ((twoCounter > 0) && (threeCounter > 0)) {
            // console.log(`twoCounter : ${twoCounter}, threeCounter : ${threeCounter}`)
            for (let j = 0; j <= twoCounter; j++) {
                for (let k = 0; k <= threeCounter; k++) {
                     sumGen = sum + 2*j + 6*k
                    //  console.log(`j : ${j}, k : ${k}, sumGen: ${sumGen}`)
                     if (sumGen % 9 === 0 ) {
                        output = "YES"
                        break
                    }
                }
             }
        }
        else if ((twoCounter > 0) && !(threeCounter > 0)) {
            console.log("CounterTwo > 0")
            for (let j = 0; j <= twoCounter; j++) {
                sumGen = sum + 2*j
                if (sumGen % 9 === 0 ) {
                    output = "YES"
                    break
                }
             }
        }
        else if (!(twoCounter > 0) && (threeCounter > 0) ) {
            // console.log("CounterThree> 0")
            for (let k = 0; k <= threeCounter; k++) {
                sumGen = sum + 6*k
                if (sumGen % 9 === 0 ) {
                    output = "YES"
                    break
                }
            }
        }
        else {
            sumGen = sum
            if (sumGen % 9 === 0 ) {
                output = "YES"
            }
        }
        outputs.push(output)
    }
}

const printOutput = () => {
    for (const output of outputs) {
        console.log(output)
    }
}


rl.on('line', (input) => {
    if (countInput === 0) {
        testNumber = parseInt(input)
        countInput++
        return
    }
    inputProcess(input)
    if (testCase === testNumber) {
        computeOutput()
        printOutput()
        
        rl.close()
    }
    // console.log(inputContainer)
})
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#define int long long
using namespace std;

const int maxn = 3e5 + 1, mod = 998244353;
vector<int> nodes[maxn];
int fa[maxn];

struct Deg
{
	int deg;
	int id;
} deg[maxn];

void find_fa(int now, int pre)
{
	fa[now] = pre;
	for (auto to : nodes[now]) {
		if (to == pre) continue;
		find_fa(to, now);
	}
}

int is_adjacent(int u, int v)
{
	return (fa[u] == v) || (fa[v] == u);
}

int cmp(Deg a, Deg b)
{
	return a.deg > b.deg;
}

void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i <= n; i++) nodes[i].clear();
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		nodes[u].push_back(v);
		nodes[v].push_back(u);
	}
	if (n == 2) {
		cout << 0 << endl;
		return ;
	} else if (n == 3) {
		cout << 1 << endl;
		return ;
	}
	find_fa(1, -1);
	for (int i = 1; i <= n; i++) {
		deg[i - 1].id = i;
		deg[i - 1].deg = nodes[i].size();
	}
	sort(deg + 1, deg + n + 1, cmp);
	int ans = deg[0].deg + deg[1].deg - is_adjacent(deg[0].id, deg[1].id);
	for (int i = 2; i < n; i++)
		ans = max(ans, max(deg[0].deg + deg[i].deg - is_adjacent(deg[0].id, deg[i].id), deg[1].deg + deg[i].deg - is_adjacent(deg[1].id, deg[i].id)));
	cout << ans - 1 << endl;
}

signed main()
{
	//freopen("code.in", "r", stdin);
	ios_base::sync_with_stdio(false);

	int T;
	cin >> T;
	while (T--) {
		solve();
	}

	return 0;
}


Submission (verdict: Accepted):
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#define int long long
using namespace std;

const int maxn = 3e5 + 1, mod = 998244353;
vector<int> nodes[maxn];
int fa[maxn];

struct Deg
{
	int deg;
	int id;
} deg[maxn];

void find_fa(int now, int pre)
{
	fa[now] = pre;
	for (auto to : nodes[now]) {
		if (to == pre) continue;
		find_fa(to, now);
	}
}

int is_adjacent(int u, int v)
{
	return (fa[u] == v) || (fa[v] == u);
}

int cmp(Deg a, Deg b)
{
	return a.deg > b.deg;
}

void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i <= n; i++) nodes[i].clear();
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		nodes[u].push_back(v);
		nodes[v].push_back(u);
	}
	if (n == 2) {
		cout << 0 << endl;
		return ;
	} else if (n == 3) {
		cout << 1 << endl;
		return ;
	}
	find_fa(1, -1);
	for (int i = 1; i <= n; i++) {
		deg[i - 1].id = i;
		deg[i - 1].deg = nodes[i].size();
	}
	sort(deg, deg + n, cmp);
	int ans = deg[0].deg + deg[1].deg - is_adjacent(deg[0].id, deg[1].id);
	for (int i = 2; i < n; i++)
		ans = max(ans, max(deg[0].deg + deg[i].deg - is_adjacent(deg[0].id, deg[i].id), deg[1].deg + deg[i].deg - is_adjacent(deg[1].id, deg[i].id)));
	cout << ans - 1 << endl;
}

signed main()
{
//	freopen("code.in", "r", stdin);
	ios_base::sync_with_stdio(false);

	int T;
	cin >> T;
	while (T--) {
		solve();
	}

	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#define int long long
using namespace std;

const int maxn = 3e5 + 1, mod = 998244353;
vector<int> nodes[maxn];
int fa[maxn];

struct Deg
{
	int deg;
	int id;
} deg[maxn];

void find_fa(int now, int pre)
{
	fa[now] = pre;
	for (auto to : nodes[now]) {
		if (to == pre) continue;
		find_fa(to, now);
	}
}

int is_adjacent(int u, int v)
{
	return (fa[u] == v) || (fa[v] == u);
}

int cmp(Deg a, Deg b)
{
	return a.deg > b.deg;
}

void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i <= n; i++) nodes[i].clear();
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		nodes[u].push_back(v);
		nodes[v].push_back(u);
	}
	if (n == 2) {
		cout << 0 << endl;
		return ;
	} else if (n == 3) {
		cout << 1 << endl;
		return ;
	}
	find_fa(1, -1);
	for (int i = 1; i <= n; i++) {
		deg[i].id = i;
		deg[i].deg = nodes[i].size();
	}
	sort(deg + 1, deg + n + 1, cmp);
	int ans = deg[0].deg + deg[1].deg - is_adjacent(deg[0].id, deg[1].id);
	for (int i = 2; i < n; i++)
		ans = max(ans, max(deg[0].deg + deg[i].deg - is_adjacent(deg[0].id, deg[i].id), deg[1].deg + deg[i].deg - is_adjacent(deg[1].id, deg[i].id)));
	cout << ans - 1 << endl;
}

signed main()
{
	//freopen("code.in", "r", stdin);
	ios_base::sync_with_stdio(false);

	int T;
	cin >> T;
	while (T--) {
		solve();
	}

	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#define int long long
using namespace std;

const int maxn = 3e5 + 1, mod = 998244353;
vector<int> nodes[maxn];
int fa[maxn];

struct Deg
{
	int deg;
	int id;
} deg[maxn];

void find_fa(int now, int pre)
{
	fa[now] = pre;
	for (auto to : nodes[now]) {
		if (to == pre) continue;
		find_fa(to, now);
	}
}

int is_adjacent(int u, int v)
{
	return (fa[u] == v) || (fa[v] == u);
}

int cmp(Deg a, Deg b)
{
	return a.deg > b.deg;
}

void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i <= n; i++) nodes[i].clear();
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		nodes[u].push_back(v);
		nodes[v].push_back(u);
	}
	if (n == 2) {
		cout << 0 << endl;
		return ;
	} else if (n == 3) {
		cout << 1 << endl;
		return ;
	}
	find_fa(1, -1);
	for (int i = 1; i <= n; i++) {
		deg[i].id = i;
		deg[i].deg = nodes[i].size();
	}
	sort(deg + 1, deg + n + 1, cmp);
	int ans = deg[0].deg + deg[1].deg - is_adjacent(deg[0].id, deg[1].id);
	for (int i = 2; i < n; i++)
		ans = max(ans, max(deg[0].deg + deg[i].deg - is_adjacent(deg[0].id, deg[i].id), deg[1].deg + deg[i].deg - is_adjacent(deg[1].id, deg[i].id)));
	cout << ans - 1 << endl;
}

signed main()
{
	//freopen("code.in", "r", stdin);
	ios_base::sync_with_stdio(false);

	int T;
	cin >> T;
	while (T--) {
		solve();
	}

	return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#define int long long
using namespace std;

const int maxn = 3e5 + 1, mod = 998244353;
vector<int> nodes[maxn];
int fa[maxn];

struct Deg
{
	int deg;
	int id;
} deg[maxn];

void find_fa(int now, int pre)
{
	fa[now] = pre;
	for (auto to : nodes[now]) {
		if (to == pre) continue;
		find_fa(to, now);
	}
}

int is_adjacent(int u, int v)
{
	return (fa[u] == v) || (fa[v] == u);
}

int cmp(Deg a, Deg b)
{
	return a.deg > b.deg;
}

void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i <= n; i++) nodes[i].clear();
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		nodes[u].push_back(v);
		nodes[v].push_back(u);
	}
	if (n == 2) {
		cout << 0 << endl;
		return ;
	} else if (n == 3) {
		cout << 1 << endl;
		return ;
	}
	find_fa(1, -1);
	for (int i = 1; i <= n; i++) {
		deg[i - 1].id = i;
		deg[i - 1].deg = nodes[i].size();
	}
	sort(deg + 1, deg + n + 1, cmp);
	int ans = deg[0].deg + deg[1].deg - is_adjacent(deg[0].id, deg[1].id);
	for (int i = 2; i < n; i++)
		ans = max(ans, max(deg[0].deg + deg[i].deg - is_adjacent(deg[0].id, deg[i].id), deg[1].deg + deg[i].deg - is_adjacent(deg[1].id, deg[i].id)));
	cout << ans - 1 << endl;
}

signed main()
{
	//freopen("code.in", "r", stdin);
	ios_base::sync_with_stdio(false);

	int T;
	cin >> T;
	while (T--) {
		solve();
	}

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

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

int main() {
    #ifndef ONLINE_JUDGE
        freopen("Input.txt", "r", stdin);
        freopen("Output.txt", "w", stdout);
    #endif
    
    int t;
    cin >> t;

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

        int a = 0 , b = 0 , c = 0 , bit = -1 , xtra = 0;

        for (int i = 30; i >= 0; i--){
            if ((l & (1ll << i)) == 0){
                if ((r & (1ll << i))){
                    bit = i;
                    break;
                }
            }
            else if ((r & (1ll << i))){
                xtra += (1ll << i);
            }
        }
    
        b = (1ll << bit) + xtra;
        a = b - 1;

        if (a == l) c = r;
        else c = a - 1;

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


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

#define ordered_set tree<ll , null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define endl '\n'
#define ll long long
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;

const int mod = 1000000007;
const int N = 2e5 + 5;
const int base = 59, base1 = 59;

random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> d(0, 1e9);

void solve(){
    ll l, r;
    cin >> l >> r;
    ll x = r;
    ll y = r;
    ll z = l;
    for(int i = 30; i >= 0; i--){
        if((x & (1 << i)) and (y - pow(2, i)) >= l){
            y -= pow(2, i);
        }
    }
    for(int i = 30; i >= 0; i--){
        if((x & (1 << i)) and !(y & (1 << i))){
            z += pow(2, i);
        }
    }
    for(int i = 30; i >= 0; i--){
        if((x & (1 << i)) and (y & (1 << i)) and (z - pow(2, i)) >= l){
            z -= pow(2, i);
        }
    }
    cout << x << " " << y << " " << z << endl;
}
int main(){
    io;
    ll t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
/*
9
ejibmyyju

*/
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


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

int main() {
    #ifndef ONLINE_JUDGE
        freopen("Input.txt", "r", stdin);
        freopen("Output.txt", "w", stdout);
    #endif
    
    int t;
    cin >> t;

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

        int a = 0 , b = 0 , c = 0 , bit = -1 , xtra = 0;

        for (int i = 30; i >= 0; i--){
            if ((l & (1ll << i)) == 0){
                if ((r & (1ll << i))){
                    bit = i;
                    break;
                }
            }
            else if ((r & (1ll << i))){
                xtra += (1ll << i);
            }
        }
    
        b = (1ll << bit) + xtra;
        a = b - 1;

        if (a == l) c = r;
        else c = a - 1;

        cout << a << ' ' << b << ' ' << c << '\n';
    }
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(x,y) __gcd(x,y)

void solve(){
	int n,s;cin>>n;
	int a[n];
	for(int i=0;i<n;i++){cin>>a[i];}

	s=n*(n-1);
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j]){s--;}
		}
	}
	cout<<s<<endl;

	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]<a[j]){cout<<a[j]<<' '<<a[i]<<endl;}
			cout<<a[i]<<' '<<a[j]<<endl;
		}
	}
}

int main(){
	int _=1;
	//cin>>_;
	while(_--) solve();
	return 0;
}

Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(x,y) __gcd(x,y)

void solve(){
	int n,s;cin>>n;
	int a[n];
	for(int i=0;i<n;i++){cin>>a[i];}

	s=n*(n-1);
	pair<int,int>p;
	vector<pair<int,int>>v;
	for(int i=n;i>1;i--){
		for(int j=0;j<i-1;j++){
			if(a[j]<a[j+1]){
				p={a[j],a[j+1]};
				v.push_back(p);
			}
			else{s--;swap(a[j],a[j+1]);}
			p={a[j+1],a[j]};
			v.push_back(p);
		}
	}

	cout<<s<<endl;
	for(int i=s-1;i>=0;i--){
		cout<<v[i].first<<' '<<v[i].second<<endl;
	}
}	

int main(){
	int _=1;
	//cin>>_;
	while(_--) solve();
	return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(x,y) __gcd(x,y)

void solve(){
	int n,s;cin>>n;
	int a[n];
	for(int i=0;i<n;i++){cin>>a[i];}

	s=n*(n-1);
	pair<int,int>p;
	vector<pair<int,int>>v;
	for(int i=n;i>1;i--){
		for(int j=0;j<i-1;j++){
			if(a[j]<a[j+1]){
				p={a[j],a[j+1]};
				v.push_back(p);
			}
			else{s--;swap(a[j],a[j+1]);}
			p={a[j+1],a[j]};
			v.push_back(p);
		}
	}

	cout<<s<<endl;
	for(int i=s-1;i>=0;i--){
		cout<<v[i].first<<' '<<v[i].second<<endl;
	}
}	

int main(){
	int _=1;
	//cin>>_;
	while(_--) solve();
	return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(x,y) __gcd(x,y)

void solve(){
	int n,idx,t;cin>>n;

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

	t=n*(n-1);
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			t-=(a[i]>a[j]);
		}
	}

	cout<<t<<endl;

	int s[n];
	for(int i=0;i<n;i++){s[i]=i+1;}

	for(int i=n-1;i>=0;i--){
		for(int j=0;j<n;j++){
			if(s[j]==a[i]){idx=j;break;}
		}

		while(idx>0){
			cout<<s[idx]<<' '<<s[idx-1]<<endl;;
			swap(s[idx],s[idx-1]);
			idx--;
		}
	}
}	

int main(){
	int _=1;
	//cin>>_;
	while(_--) solve();
	return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(x,y) __gcd(x,y)

void solve(){
	int n,s;cin>>n;
	int a[n];
	for(int i=0;i<n;i++){cin>>a[i];}

	s=n*(n-1);
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j]){s--;}
		}
	}
	cout<<s<<endl;

	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]<a[j]){cout<<a[j]<<' '<<a[i]<<endl;}
			cout<<a[i]<<' '<<a[j]<<endl;
		}
	}
}

int main(){
	int _=1;
	//cin>>_;
	while(_--) solve();
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


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

#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define F0R(i,a) FOR(i,0,a)
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) x*y/__gcd(x,y)

const int R=1e9+7;
const int Q=998244353;

void solve(){
	int n;cin>>n;
	map<pair<int,int>,bool>edges;
	pair<int,int>p;
	vector<int>a(n+1,0);
	F0R(i,n-1){
		int u,v;
		cin>>u>>v;
		if(u>v){swap(u,v);}
		p={u,v};
		edges[p]=true;
		a[u]++;a[v]++;
	}
	int idx1,maxi;
	idx1=1;maxi=a[idx1];
	FOR(i,1,n+1){
		if(maxi<a[i]){maxi=a[i];idx1=i;}
	}
	int idx2=1+(idx1==1);
	maxi=a[idx2];
	FOR(i,1,n+1){
		if(maxi<a[i]&&i!=idx1){maxi=a[i];idx2=i;}
	}
	int idx3=-1;
	if(n>2){
		if(idx1>1&&idx2>1){idx3=1;}
		else if(idx1==2||idx2==2){idx3=3;}
		else{idx3=2;}
		maxi=a[idx3];
		FOR(i,1,n+1){
			if(maxi<a[i]&&i!=idx1&&i!=idx2){maxi=a[i];idx3=i;}
		}
	}
	if(idx1>idx2){swap(idx1,idx2);}
	p={idx1,idx2};
	int ans=a[idx1]+a[idx2]-(edges[p])-1;
	if(idx3>0){
		p={min(idx1,idx3),max(idx1,idx3)};
		ans=max(ans,a[idx1]+a[idx3]-(edges[p])-1);
		p={min(idx2,idx3),max(idx2,idx3)};
		ans=max(ans,a[idx2]+a[idx3]-(edges[p])-1);
	}
	cout<<ans<<endl;
}	

int main(){
	int _=1;
	cin>>_;
	while(_--) solve();
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

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

#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define F0R(i,a) FOR(i,0,a)
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) x*y/__gcd(x,y)

const int R=1e9+7;
const int Q=998244353;

void solve(){
	int n;cin>>n;
	map<pair<int,int>,bool>edges;
	pair<int,int>p;
	vector<int>a(n+1,0);
	F0R(i,n-1){
		int u,v;
		cin>>u>>v;
		if(u>v){swap(u,v);}
		p={u,v};
		edges[p]=true;
		a[u]++;a[v]++;
	}
	int idx1,maxi;
	idx1=1;maxi=a[idx1];
	FOR(i,1,n+1){
		if(maxi<a[i]){maxi=a[i];idx1=i;}
	}
	int idx2=1+(idx1==1);
	maxi=a[idx2];
	FOR(i,1,n+1){
		if(maxi<a[i]&&i!=idx1){maxi=a[i];idx2=i;}
	}
	int idx3=-1;
	if(n>2){
		if(idx1>1&&idx2>1){idx3=1;}
		else if(idx1==2||idx2==2){idx3=3;}
		else{idx3=2;}
		maxi=a[idx3];
		FOR(i,1,n+1){
			if(maxi<a[i]&&i!=idx1&&i!=idx2){maxi=a[i];idx3=i;}
		}
	}
	if(idx1>idx2){swap(idx1,idx2);}
	p={idx1,idx2};
	int ans=a[idx1]+a[idx2]-(edges[p])-1;
	if(idx3>0){
		p={min(idx1,idx3),max(idx1,idx3)};
		ans=max(ans,a[idx1]+a[idx3]-(edges[p])-1);
		p={min(idx2,idx3),max(idx2,idx3)};
		ans=max(ans,a[idx2]+a[idx3]-(edges[p])-1);
	}
	cout<<ans<<endl;
}	

int main(){
	int _=1;
	cin>>_;
	while(_--) solve();
	return 0;
}

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

#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define F0R(i,a) FOR(i,0,a)
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) x*y/__gcd(x,y)

const int R=1e9+7;
const int Q=998244353;

void solve(){
	int n;cin>>n;
	map<pair<int,int>,bool>edges;
	pair<int,int>p;
	vector<int>a(n+1,0);
	F0R(i,n-1){
		int u,v;
		cin>>u>>v;
		p={min(u,v),max(u,v)};
		edges[p]=true;
		a[u]++;a[v]++;
	}
	int idx1,maxi;
	idx1=maxi=0;
	FOR(i,1,n+1){
		if(maxi<a[i]){maxi=a[i];idx1=i;}
	}
	int idx2;
	idx2=maxi=0;
	FOR(i,1,n+1){
		if(maxi<a[i]&&i!=idx1){maxi=a[i];idx2=i;}
	}
	int idx3=0;
	if(n>2){
		maxi=0;
		FOR(i,1,n+1){
			if(maxi<a[i]&&i!=idx1&&i!=idx2){maxi=a[i];idx3=i;}
		}
	}
	p={min(idx1,idx2),max(idx1,idx2)};
	int ans=a[idx1]+a[idx2]-(edges[p])-1;
	if(idx3>0){
		p={min(idx1,idx3),max(idx1,idx3)};
		ans=max(ans,a[idx1]+a[idx3]-(edges[p])-1);
		p={min(idx2,idx3),max(idx2,idx3)};
		ans=max(ans,a[idx2]+a[idx3]-(edges[p])-1);
	}
	cout<<ans<<endl;
}	

int main(){
	int _=1;
	cin>>_;
	while(_--) solve();
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

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

#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define F0R(i,a) FOR(i,0,a)
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) x*y/__gcd(x,y)

const int R=1e9+7;
const int Q=998244353;

void solve(){
	int n;cin>>n;
	map<pair<int,int>,bool>edges;
	pair<int,int>p;
	vector<int>a(n+1,0);
	F0R(i,n-1){
		int u,v;
		cin>>u>>v;
		p={min(u,v),max(u,v)};
		edges[p]=true;
		a[u]++;a[v]++;
	}
	int idx1,maxi;
	idx1=maxi=0;
	FOR(i,1,n+1){
		if(maxi<a[i]){maxi=a[i];idx1=i;}
	}
	int idx2;
	idx2=maxi=0;
	FOR(i,1,n+1){
		if(maxi<a[i]&&i!=idx1){maxi=a[i];idx2=i;}
	}
	int idx3=0;
	if(n>2){
		maxi=0;
		FOR(i,1,n+1){
			if(maxi<a[i]&&i!=idx1&&i!=idx2){maxi=a[i];idx3=i;}
		}
	}
	p={min(idx1,idx2),max(idx1,idx2)};
	int ans=a[idx1]+a[idx2]-(edges[p])-1;
	if(idx3>0){
		p={min(idx1,idx3),max(idx1,idx3)};
		ans=max(ans,a[idx1]+a[idx3]-(edges[p])-1);
		p={min(idx2,idx3),max(idx2,idx3)};
		ans=max(ans,a[idx2]+a[idx3]-(edges[p])-1);
	}
	cout<<ans<<endl;
}	

int main(){
	int _=1;
	cin>>_;
	while(_--) solve();
	return 0;
}

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

#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define F0R(i,a) FOR(i,0,a)
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) x*y/__gcd(x,y)

const int R=1e9+7;
const int Q=998244353;

void solve(){
	int n;cin>>n;
	map<pair<int,int>,bool>edges;
	pair<int,int>p;
	vector<int>a(n+1,0);
	F0R(i,n-1){
		int u,v;
		cin>>u>>v;
		p={min(u,v),max(u,v)};
		edges[p]=true;
		a[u]++;a[v]++;
	}
	int idx1,maxi;
	idx1=maxi=0;
	FOR(i,1,n+1){
		if(maxi<a[i]){maxi=a[i];idx1=i;}
	}
	int idx2;
	idx2=maxi=0;
	FOR(i,1,n+1){
		if(maxi<a[i]&&i!=idx1){maxi=a[i];idx2=i;}
	}
	p={min(idx1,idx2),max(idx1,idx2)};
	int ans=a[idx1]+a[idx2]-(edges[p])-1;
	FOR(i,1,n+1){
		if(i!=idx1&&i!=idx2){
			p={min(idx1,i),max(idx1,i)};
			ans=max(ans,a[idx1]+a[i]-(edges[p])-1);
			p={min(idx2,i),max(idx2,i)};
			ans=max(ans,a[idx2]+a[i]-(edges[p])-1);
		}
	}
	cout<<ans<<endl;
}	

int main(){
	int _=1;
	cin>>_;
	while(_--) solve();
	return 0;
}