ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

Previous 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;
		}
	}
}

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){
							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;
		}
	}
}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

Previous 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){
							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;
		}
	}
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a[200005];
ll gcd(ll a,ll 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;
		ll sum=0;
		for(int i=0;i<x;i++){
			cin>>a[i];
			sum+=a[i];
		}
		if(sum%x==0){
			ll sum1=0;
			ll 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){
				ll c=gcd(sum1,sum2);
				if(x%2==1){
					if(sum1%(x/2+1)==0){
						if(sum1==sum2+c){
							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;
		}
	}
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n = 0, arr[10001] = { 0 }, pos[10001] = { 0 }, ret[10001] = { 0 }, cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		pos[i] = i;
	}
	for (int i = n; i >= 1; i--) {
		for (int j = pos[arr[i]]; j > 1; j--) {
			cout << pos[j] << " " << pos[j - 1] << endl;
			swap(pos[j], pos[j - 1]);
			cnt++;
		}
		for (int j = pos[arr[i]]; j < i; j++) {
			cout << pos[j + 1] << " " << pos[j] << endl;
			swap(pos[j], pos[j + 1]);
			cnt++;
		}
	}
	cout << cnt;
	return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n = 0, arr[10001] = { 0 }, pos[10001] = { 0 }, ret[10001] = { 0 }, cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		pos[i] = i;
	}
	for (int i = n; i >= 1; i--) {
		for (int j = pos[arr[i]]; j > 1; j--) {
			cout << pos[j] << " " << pos[j - 1] << endl;
			swap(pos[j], pos[j - 1]);
			cnt++;
		}
		for (int j = pos[arr[i]]; j < i; j++) {
			cout << pos[j + 1] << " " << pos[j] << endl;
			swap(pos[j], pos[j + 1]);
			cnt++;
		}
	}
	cout << cnt;
	return 0;
}

Submission (verdict: Wrong answer on test 4):
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n = 0, arr[1001] = { 0 }, pos[1001] = { 0 }, ret[1000001][2] = {0}, cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		pos[i] = i;
	}
	for (int i = n; i >= 1; i--) {
		for (int j = pos[arr[i]]; j > 1; j--) {
			ret[++cnt][0] = pos[j], ret[cnt][1] = pos[j - 1];
			swap(pos[j], pos[j - 1]);
		}
		for (int j = pos[arr[i]]; j < i; j++) {
			ret[++cnt][0] = pos[j + 1], ret[cnt][1] = pos[j];
			swap(pos[j], pos[j + 1]);
		}
	}
	cout << cnt << endl;
	for (int i = 1; i <= cnt; i++) cout << ret[i][0] << " " << ret[i][1] << endl;
	return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n = 0, arr[1001] = { 0 }, pos[1001] = { 0 }, ret[1000001][2] = {0}, cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		pos[i] = i;
	}
	for (int i = n; i >= 1; i--) {
		for (int j = pos[arr[i]]; j > 1; j--) {
			ret[++cnt][0] = pos[j], ret[cnt][1] = pos[j - 1];
			swap(pos[j], pos[j - 1]);
		}
		for (int j = pos[arr[i]]; j < i; j++) {
			ret[++cnt][0] = pos[j + 1], ret[cnt][1] = pos[j];
			swap(pos[j], pos[j + 1]);
		}
	}
	cout << cnt << endl;
	for (int i = 1; i <= cnt; i++) cout << ret[i][0] << " " << ret[i][1] << endl;
	return 0;
}

Submission (verdict: Accepted):
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n = 0, arr[1001] = { 0 }, pos[1001] = { 0 }, p[1001] = { 0 }, ret1[1000001][2] = { 0 }, ret2[1000001][2] = { 0 }, cnt1 = 0, cnt2 = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		pos[i] = i;
		p[i] = i;
	}
	for (int i = n; i >= 1; i--) {
		for (int j = p[arr[i]]; j > 1; j--) {
			p[arr[i]]--;
			p[pos[j - 1]]++;
			ret1[++cnt1][0] = pos[j], ret1[cnt1][1] = pos[j - 1];
			swap(pos[j], pos[j - 1]);
		}
		for (int j = p[arr[i]]; j < i; j++) {
			p[arr[i]]++;
			p[pos[j + 1]]--;
			ret1[++cnt1][0] = pos[j + 1], ret1[cnt1][1] = pos[j];
			swap(pos[j], pos[j + 1]);
		}
	}
	for (int i = 1; i <= n; i++) { pos[i] = i; p[i] = i; }
	for (int i = 1; i <= n; i++) {
		for (int j = p[arr[i]]; j < n; j++) {
			p[arr[i]]++;
			p[pos[j + 1]]--;
			ret2[++cnt2][0] = pos[j + 1], ret2[cnt2][1] = pos[j];
			swap(pos[j + 1], pos[j]);
		}
		for (int j = p[arr[i]]; j > i; j--) {
			p[arr[i]]--;
			p[pos[j - 1]]++;
			ret2[++cnt2][0] = pos[j], ret2[cnt2][1] = pos[j - 1];
			swap(pos[j], pos[j - 1]);
		}
	}
	cout << max(cnt1, cnt2) << endl;
	if (cnt1 > cnt2)for (int i = 1; i <= cnt1; i++) cout << ret1[i][0] << " " << ret1[i][1] << endl;
	else for (int i = 1; i <= cnt2; i++) cout << ret2[i][0] << " " << ret2[i][1] << endl;
	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

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

void solve()
{
    string s;cin>>s;
    int n = s.size();
    cout<<s[0]<<endl;
    for(int i = 0;i<n;i++)
    {
        int curr = s[i] - '0';
        int maxi = -1;
        // cout<<"curr --> "<<curr<<endl;
        for(int j = 1;j<9 && (i+j) < n;j++)
        {
            int curr_eval = s[i+j] - '0';
            curr_eval -= j;
            maxi = max(maxi , curr_eval);
        }
        // cout<<"maxi --> "<<maxi<<endl;
        if(curr >= maxi)
        {
            continue;
        }
        else
        {
            int idx = 0;
            for(int j = 1 ;j<9 && (i+j) < n;j++)
            {
                if((s[i+j] - '0') - j == maxi)
                {
                    idx = i+j;
                    break;
                }
            }
            char temp = maxi + '0';
            for(int j = idx ; j >= i+1;j--)
            {
                s[j] = s[j-1];
            }
            s[i] = temp;
        }
        // cout<<"s --> "<<s<<endl;
    }
    cout<<s<<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt;
    cin >> tt;

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

    return 0;
}



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

void solve()
{
    string s;cin>>s;
    int n = s.size();
    // cout<<s[0]<<endl;
    for(int i = 0;i<n;i++)
    {
        int curr = s[i] - '0';
        int maxi = -1;
        // cout<<"curr --> "<<curr<<endl;
        for(int j = 1;j<9 && (i+j) < n;j++)
        {
            int curr_eval = s[i+j] - '0';
            curr_eval -= j;
            maxi = max(maxi , curr_eval);
        }
        // cout<<"maxi --> "<<maxi<<endl;
        if(curr >= maxi)
        {
            continue;
        }
        else
        {
            int idx = 0;
            for(int j = 1 ;j<9 && (i+j) < n;j++)
            {
                if((s[i+j] - '0') - j == maxi)
                {
                    idx = i+j;
                    break;
                }
            }
            char temp = maxi + '0';
            for(int j = idx ; j >= i+1;j--)
            {
                s[j] = s[j-1];
            }
            s[i] = temp;
        }
        // cout<<"s --> "<<s<<endl;
    }
    cout<<s<<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt;
    cin >> tt;

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

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


Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <string>
#include <deque>
#include <vector>
using namespace std;

void solve() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        int n = s.length();
        deque<int> dq; // Tracks indices of potential positions for swapping
        string result = s;

        for (int i = 1; i < n; ++i) {
            // Check the deque for valid positions
            while (!dq.empty() && i - dq.front() > 9) {
                dq.pop_front(); // Remove invalid positions
            }

            // Try to find a position to swap
            bool swapped = false;
            for (auto it = dq.rbegin(); it != dq.rend(); ++it) {
                int pos = *it;
                if (result[pos] < result[i] - 1) {
                    swap(result[pos], result[i]);
                    result[pos]++;
                    swapped = true;
                    break;
                }
            }

            // Add current position if it's not 0 or leftmost digit
            if (!swapped && s[i] != '0') {
                dq.push_back(i);
            }
        }

        cout << result << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <string>
#include <deque>
#include <vector>
using namespace std;

void solve() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        int n = s.length();
        deque<int> dq; // Tracks indices of potential positions for swapping
        string result = s;

        for (int i = 1; i < n; ++i) {
            // Check the deque for valid positions
            while (!dq.empty() && i - dq.front() > 9) {
                dq.pop_front(); // Remove invalid positions
            }

            // Try to find a position to swap
            bool swapped = false;
            for (auto it = dq.rbegin(); it != dq.rend(); ++it) {
                int pos = *it;
                if (result[pos] < result[i] - 1) {
                    swap(result[pos], result[i]);
                    result[pos]++;
                    swapped = true;
                    break;
                }
            }

            // Add current position if it's not 0 or leftmost digit
            if (!swapped && s[i] != '0') {
                dq.push_back(i);
            }
        }

        cout << result << "\n";
    }
}

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


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

void solve()
{
    string s;cin>>s;
    int n = s.size();
    cout<<s[0]<<endl;
    for(int i = 0;i<n;i++)
    {
        int curr = s[i] - '0';
        int maxi = -1;
        // cout<<"curr --> "<<curr<<endl;
        for(int j = 1;j<9 && (i+j) < n;j++)
        {
            int curr_eval = s[i+j] - '0';
            curr_eval -= j;
            maxi = max(maxi , curr_eval);
        }
        // cout<<"maxi --> "<<maxi<<endl;
        if(curr >= maxi)
        {
            continue;
        }
        else
        {
            int idx = 0;
            for(int j = 1 ;j<9 && (i+j) < n;j++)
            {
                if((s[i+j] - '0') - j == maxi)
                {
                    idx = i+j;
                    break;
                }
            }
            char temp = maxi + '0';
            for(int j = idx ; j >= i+1;j--)
            {
                s[j] = s[j-1];
            }
            s[i] = temp;
        }
        // cout<<"s --> "<<s<<endl;
    }
    cout<<s<<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt;
    cin >> tt;

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

    return 0;
}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)


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

using namespace std;

using ll = long long;

void fileIO(){

#ifndef ONLINE_JUDGE

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

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

#endif

}





void solve(){

    int n;

    cin >> n;

    string s;

    cin >> s;

    int p_idx = n - 1, s_idx = 0;

    while (s_idx < n && s[s_idx] == 's') s_idx ++;

    while (p_idx >= 0 && s[p_idx] == 'p') p_idx --;

    int p_cnt = 0, s_cnt = 0;

    for (int i = s_idx; i < p_idx; ++i) {

        p_cnt += s[i] == 'p';

        s_cnt += s[i] == 's';

    }

    if(p_cnt > 0 && s_cnt > 0){

        return void(cout << "NO\n");

    }



    cout << "YES\n";

}



int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    fileIO();

    int t = 1;

    cin >> t;

    for (int it = 1; it <= t; it++)

    {

        solve();

    }



    return 0;

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

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

using namespace std;

using ll = long long;

void fileIO(){

#ifndef ONLINE_JUDGE

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

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

#endif

}





void solve(){

    int n;

    cin >> n;

    string s;

    cin >> s;

    int p_idx = n - 1, s_idx = 0;

    while (s_idx < n && s[s_idx] == 's') s_idx ++;

    while (p_idx >= 0 && s[p_idx] == 'p') p_idx --;

    int p_cnt = 0, s_cnt = 0;



    for (int i = s_idx ; i <= p_idx ; ++i) {

        p_cnt += s[i] == 'p';

        s_cnt += s[i] == 's';

    }



    if(p_cnt > 0 && s_cnt > 0){

        return void(cout << "NO\n");

    }



    cout << "YES\n";

}



int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    fileIO();

    int t = 1;

    cin >> t;

    for (int it = 1; it <= t; it++)

    {

        solve();

    }



    return 0;

}

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

using namespace std;

using ll = long long;

void fileIO(){

#ifndef ONLINE_JUDGE

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

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

#endif

}





void solve(){

    int n;

    cin >> n;

    string s;

    cin >> s;

    int p_idx = n - 1, s_idx = 0;

    if (s_idx < n && s[s_idx] == 's') s_idx ++;

    if (p_idx >= 0 && s[p_idx] == 'p') p_idx --;

    int p_cnt = 0, s_cnt = 0;



    for (int i = s_idx ; i <= p_idx ; ++i) {

        p_cnt += s[i] == 'p';

        s_cnt += s[i] == 's';

    }



    //sspp



    if(p_cnt > 0 && s_cnt > 0){

        return void(cout << "NO\n");

    }



    cout << "YES\n";

}



int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    fileIO();

    int t = 1;

    cin >> t;

    for (int it = 1; it <= t; it++)

    {

        solve();

    }



    return 0;

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

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

using namespace std;

using ll = long long;

void fileIO(){

#ifndef ONLINE_JUDGE

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

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

#endif

}





void solve(){

    int n;

    cin >> n;

    string s;

    cin >> s;

    int p_idx = n - 1, s_idx = 0;

    while (s_idx < n && s[s_idx] == 's') s_idx ++;

    while (p_idx >= 0 && s[p_idx] == 'p') p_idx --;

    int p_cnt = 0, s_cnt = 0;

    for (int i = s_idx; i < p_idx; ++i) {

        p_cnt += s[i] == 'p';

        s_cnt += s[i] == 's';

    }

    if(p_cnt > 0 && s_cnt > 0){

        return void(cout << "NO\n");

    }



    cout << "YES\n";

}



int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    fileIO();

    int t = 1;

    cin >> t;

    for (int it = 1; it <= t; it++)

    {

        solve();

    }



    return 0;

}

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

using namespace std;

using ll = long long;

void fileIO(){

#ifndef ONLINE_JUDGE

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

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

#endif

}





void solve(){

    int n;

    cin >> n;

    string s;

    cin >> s;

    int p_idx = n - 1, s_idx = 0;

    while (s_idx < n && s[s_idx] == 's') s_idx ++;

    while (p_idx >= 0 && s[p_idx] == 'p') p_idx --;

    int p_cnt = 0, s_cnt = 0;



    for (int i = s_idx ; i <= p_idx ; ++i) {

        p_cnt += s[i] == 'p';

        s_cnt += s[i] == 's';

    }



    if(p_cnt > 0 && s_cnt > 0){

        return void(cout << "NO\n");

    }



    cout << "YES\n";

}



int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    fileIO();

    int t = 1;

    cin >> t;

    for (int it = 1; it <= t; it++)

    {

        solve();

    }



    return 0;

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


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
const int N = 309, M = 998244353;

void solve()
{
    int n;
    cin>>n;
    vector<vector<int>> g(n+1);
    vector<int> ind(n+1,0);

    for(int i=0,u,v;i<n-1;++i)
    {
        cin>>u>>v;
        g[u].push_back(v),g[v].push_back(u);
        ind[u]++,ind[v]++;
    }

    int tag = 0;
    for(int i=1;i<=n;++i)
        if(!tag||ind[i]>ind[tag]) tag = i;
    int ans = ind[tag];

    for(int i=0;i<(int)g[tag].size();++i) ind[g[tag][i]]--;

    int tag1 = 0;
    for(int i=1;i<=n;++i)
        if(i!=tag&&(!tag1||ind[i]>ind[tag1])) tag1 = i;

    if(!tag1) ans--;
    else ans += ind[tag1]-1;
    cout<<ans<< '\n';
}

int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    //fflush(stdout);

    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 <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
const int N = 309, M = 998244353;

void solve()
{
    int n;
    cin>>n;
    vector<vector<int>> g(n+1);
    vector<int> ind(n+1,0);

    for(int i=0,u,v;i<n-1;++i)
    {
        cin>>u>>v;
        g[u].push_back(v),g[v].push_back(u);
        ind[u]++,ind[v]++;
    }

    int tag = 0;
    for(int i=1;i<=n;++i)
        if(!tag||ind[i]>ind[tag]) tag = i;
    int ans = ind[tag];

    for(int i=0;i<(int)g[tag].size();++i) ind[g[tag][i]]--;

    int tag1 = 0;
    for(int i=1;i<=n;++i)
        if(i!=tag&&(!tag1||ind[i]>ind[tag1])) tag1 = i;

    if(!tag1) ans--;
    else ans += ind[tag1]-1;
    cout<<ans<< '\n';
}

int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    //fflush(stdout);

    int t;
    cin>>t;
    while(t--) solve();

    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
const int N = 309, M = 998244353;

void solve()
{
    int n;
    cin>>n;
    vector<vector<int>> g(n+1);
    vector<int> ind(n+1,0);

    for(int i=0,u,v;i<n-1;++i)
    {
        cin>>u>>v;
        g[u].push_back(v),g[v].push_back(u);
        ind[u]++,ind[v]++;
    }

    int tag=0,cnt=0;
    for(int i=1;i<=n;++i)
        if(ind[i]>ind[tag]) tag=i,cnt=0;
        else if(ind[i]==ind[tag]) cnt++;

    if(cnt>=3) cout<<ind[tag]*2-1<<'\n';
    else if(cnt==2)
    {
        bool is = false;
        for(int i=0;i<(int)g[tag][i];++i)
            if(ind[g[tag][i]]==ind[tag]) is = true;
        if(is) cout<< ind[tag]*2-2<< '\n';
        else cout<< ind[tag]*2-1<< '\n';
    }
    else
    {
        for(int i=0;i<(int)g[tag].size();++i) ind[g[tag][i]]--;
        int mx=0;
        for(int i=1;i<=n;++i)
            if(i!=tag) mx = max(mx,ind[i]);
        cout<< ind[tag]+mx-1<< '\n';
    }

}

int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    //fflush(stdout);

    int t;
    cin>>t;
    while(t--) solve();

    return 0;
}