ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;


void solve(){
	string s;
	cin >> s;
	int n = s.length();
	
	int i = 1;
	while(i < n){
		bool condition = false;
		if(s[i] != 0 and s[i] - s[i-1] > 1){
			char temp = s[i] - 1;
			s[i] = s[i-1];
			s[i-1] = temp;
			condition = true;
		}
		i++;
		if(condition){
			i = 1;
		}
	}
	
	cout<<s<<endl;
	return;
}

int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

using namespace std;


void solve(){
	string s;
	cin >> s;
	
	string lefthand = "";
	string righthand = "";
	while(s.size() != 0){
		for(int j = s.length() - 1; j > 0; j--){
			if(s[j] != 0 and s[j] - s[j-1] > 1){
				char temp = s[j] - 1;
				s[j] = s[j-1];
				s[j-1] = temp;
			}
		}
		lefthand = lefthand + s[0];
		s = s.erase(0, 1);

		if(s.size() == 0){
			break;
		}

		for(int j = 1; j < s.length(); j++){
			if(s[j] != 0 and s[j] - s[j-1] > 1){
				char temp = s[j] - 1;
				s[j] = s[j-1];
				s[j-1] = temp;
			}
		}
		righthand = s[s.size() - 1] + righthand;
		s = s.erase(s.size() - 1);
	}
	cout<<lefthand + righthand<<endl;
	return;
}


int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;


void solve(){
	string s;
	cin >> s;
	
	string lefthand = "";
	string righthand = "";
	while(s.size() != 0){
		for(int j = s.length() - 1; j > 0; j--){
			if(s[j] != 0 and s[j] - s[j-1] > 1){
				char temp = s[j] - 1;
				s[j] = s[j-1];
				s[j-1] = temp;
			}
		}
		lefthand = lefthand + s[0];
		s = s.erase(0, 1);

		if(s.size() == 0){
			break;
		}

		for(int j = 1; j < s.length(); j++){
			if(s[j] != 0 and s[j] - s[j-1] > 1){
				char temp = s[j] - 1;
				s[j] = s[j-1];
				s[j-1] = temp;
			}
		}
		righthand = s[s.size() - 1] + righthand;
		s = s.erase(s.size() - 1);
	}
	cout<<lefthand + righthand<<endl;
	return;
}


int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

using namespace std;


void solve(){
	string s;
	cin>>s;
	for(int i = 0;i <s.size();i++){
		int best = s[i] - 0, pos = i;
		for(int j = i; j < min(i+10, (int) s.size()); j++){
			if(s[j] - (j-i) > best){
				best = s[j] - (j-i);
				pos = j;
			}
		}
		while(pos > i){
			swap(s[pos], s[pos - 1]);
			pos--;
		}
		s[i]= best;
	} 
	cout<<s<<endl;
}


int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
const int mod = 1000000007; 
const int N = 1e5+10; 
using namespace std;
typedef pair<int,int>pii;
#define endl "\n"
#define yes cout<<"YES\n"
#define no  cout<<"NO\n"
#define forn(i,x, n) for (int i = x; i < int(n); i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define stin(a) string a; cin>>a
#define sz(a) (int)(a.size())
#define fin(a) for (auto &x : a) cin>>x
#define fout(a) for (auto &x : a) cout<<x<<" "; cout<<endl;
#define ll long long int
ll powm(ll x, ll n) {
    x %= mod;
    if (n == 0)
        return 1;
    else if (n == 1)
        return x%mod;
    int p = powm(x * x%mod, n / 2);
    if (n % 2)
        return p * x % mod;
    else
        return p;
}
void solve()
{
    int n; cin>>n;
    vector<int>v(n); fin(v);
    int x=v[n-1];
    int mx=*max_element(all(v));
    if(mx-x>=x) no;
    else yes;
}
int32_t main()
{
   ios_base::sync_with_stdio (0);
   cin.tie (0);
   cout.tie (0);
   int t; cin>>t; while(t--)
   solve();
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
const int mod = 1000000007; 
const int N = 1e5+10; 
using namespace std;
typedef pair<int,int>pii;
#define endl "\n"
#define yes cout<<"YES\n"
#define no  cout<<"NO\n"
#define forn(i,x, n) for (int i = x; i < int(n); i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define stin(a) string a; cin>>a
#define sz(a) (int)(a.size())
#define fin(a) for (auto &x : a) cin>>x
#define fout(a) for (auto &x : a) cout<<x<<" "; cout<<endl;
#define ll long long int
ll powm(ll x, ll n) {
    x %= mod;
    if (n == 0)
        return 1;
    else if (n == 1)
        return x%mod;
    int p = powm(x * x%mod, n / 2);
    if (n % 2)
        return p * x % mod;
    else
        return p;
}
void solve()
{
    int n; cin>>n;
    vector<int>v(n); fin(v);
    
    for(int i=0;i<n-1;i++)
    {
      if(v[i]>v[i+1]) {
        no; return;
      }
      v[i+1]-=v[i];
    }
    yes;
}
int32_t main()
{
   ios_base::sync_with_stdio (0);
   cin.tie (0);
   cout.tie (0);
   int t; cin>>t; while(t--)
   solve();
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
const int mod = 1000000007; 
const int N = 1e5+10; 
using namespace std;
typedef pair<int,int>pii;
#define endl "\n"
#define yes cout<<"YES\n"
#define no  cout<<"NO\n"
#define forn(i,x, n) for (int i = x; i < int(n); i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define stin(a) string a; cin>>a
#define sz(a) (int)(a.size())
#define fin(a) for (auto &x : a) cin>>x
#define fout(a) for (auto &x : a) cout<<x<<" "; cout<<endl;
#define ll long long int
ll powm(ll x, ll n) {
    x %= mod;
    if (n == 0)
        return 1;
    else if (n == 1)
        return x%mod;
    int p = powm(x * x%mod, n / 2);
    if (n % 2)
        return p * x % mod;
    else
        return p;
}
void solve()
{
    int n; cin>>n;
    vector<int>v(n); fin(v);
    int x=v[n-1];
    int mx=*max_element(all(v));
    if(mx-x>x) no;
    else yes;
}
int32_t main()
{
   ios_base::sync_with_stdio (0);
   cin.tie (0);
   cout.tie (0);
   int t; cin>>t; while(t--)
   solve();
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
const int mod = 1000000007; 
const int N = 1e5+10; 
using namespace std;
typedef pair<int,int>pii;
#define endl "\n"
#define yes cout<<"YES\n"
#define no  cout<<"NO\n"
#define forn(i,x, n) for (int i = x; i < int(n); i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define stin(a) string a; cin>>a
#define sz(a) (int)(a.size())
#define fin(a) for (auto &x : a) cin>>x
#define fout(a) for (auto &x : a) cout<<x<<" "; cout<<endl;
#define ll long long int
ll powm(ll x, ll n) {
    x %= mod;
    if (n == 0)
        return 1;
    else if (n == 1)
        return x%mod;
    int p = powm(x * x%mod, n / 2);
    if (n % 2)
        return p * x % mod;
    else
        return p;
}
void solve()
{
    int n; cin>>n;
    vector<int>v(n); fin(v);
    int x=v[n-1];
    int mx=*max_element(all(v));
    if(mx-x>=x) no;
    else yes;
}
int32_t main()
{
   ios_base::sync_with_stdio (0);
   cin.tie (0);
   cout.tie (0);
   int t; cin>>t; while(t--)
   solve();
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
const int mod = 1000000007; 
const int N = 1e5+10; 
using namespace std;
typedef pair<int,int>pii;
#define endl "\n"
#define yes cout<<"YES\n"
#define no  cout<<"NO\n"
#define forn(i,x, n) for (int i = x; i < int(n); i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define stin(a) string a; cin>>a
#define sz(a) (int)(a.size())
#define fin(a) for (auto &x : a) cin>>x
#define fout(a) for (auto &x : a) cout<<x<<" "; cout<<endl;
#define ll long long int
ll powm(ll x, ll n) {
    x %= mod;
    if (n == 0)
        return 1;
    else if (n == 1)
        return x%mod;
    int p = powm(x * x%mod, n / 2);
    if (n % 2)
        return p * x % mod;
    else
        return p;
}
void solve()
{
    int n; cin>>n;
    vector<int>v(n); fin(v);
    int x=v[n-1];
    int mx=*max_element(all(v));
    if(mx-x>x) no;
    else yes;
}
int32_t main()
{
   ios_base::sync_with_stdio (0);
   cin.tie (0);
   cout.tie (0);
   int t; cin>>t; while(t--)
   solve();
}
Problem: 2060D - Subtract Min Sort
Language: PyPy 3

Previous submission (verdict: Wrong answer on test 2):
for i in range(int(input())):
    N = int(input())
    A = [int(x) for x in input().split()]
    print("YES" if A[0]<A[1] else "NO")

Submission (verdict: Accepted):
for i in range(int(input())):
    N = int(input())
    A = [int(x) for x in input().split()]
    for i in range(N-1):
        minimum = min(A[i], A[i+1])
        A[i] -= minimum
        A[i+1] -= minimum
    print("YES" if A==sorted(A) else "NO")
Problem: 2060D - Subtract Min Sort
Language: PyPy 3

Previous submission (verdict: Wrong answer on test 2):
for i in range(int(input())):
    N = int(input())
    A = [int(x) for x in input().split()]
    print("YES" if A[-2]<A[-1] else "NO")

Submission (verdict: Wrong answer on test 2):
for i in range(int(input())):
    N = int(input())
    A = [int(x) for x in input().split()]
    print("YES" if A[0]<A[1] else "NO")
Problem: 2062C - Cirno and Operations
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 2):
t=int(input())
while t:
	t-=1
	n = int(input())
	a = list(map(int, input().split()))

	total = sum(a)
	while n > 1:
		left = sum(a)-sum(a[1:n])
		right = sum(a)-sum(a[:n-1])

		if left >= right:
			a.reverse()

		for i in range(0, n-1):
				a[i] = a[i+1]-a[i]
		
		n-=1
		a = a[0:n]
		
	print(max(total, a[0]))
Problem: 2062C - Cirno and Operations
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
t=int(input())
while t:
	t-=1
	n = int(input())
	a = list(map(int, input().split()))

	total = sum(a)
	while n > 1:
		left = sum(a)-sum(a[1:n])
		right = sum(a)-sum(a[:n-1])

		total = max(total, left, right)
		if left >= right:
			a.reverse()

		for i in range(0, n-1):
				a[i] = a[i+1]-a[i]
		
		n-=1
		a = a[0:n]
		
	print(max(total, a[0]))

Submission (verdict: Accepted):
t=int(input())
while t:
	t-=1
	n = int(input())
	a = list(map(int, input().split()))

	total = sum(a)
	while n > 1:
		left = sum(a[:n-1])-sum(a[1:n])
		right = sum(a[1:n])-sum(a[:n-1])

		total = max(total, left, right)
		if left >= right:
			a.reverse()

		for i in range(0, n-1):
			a[i] = a[i+1]-a[i]
		
		n-=1
		a = a[0:n]
		
	print(max(total, a[0]))
Problem: 2062C - Cirno and Operations
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
t=int(input())
while t:
	t-=1
	n = int(input())
	a = list(map(int, input().split()))

	total = sum(a)
	while n > 1:
		left = sum(a)-sum(a[1:n])
		right = sum(a)-sum(a[:n-1])

		if left >= right:
			a.reverse()

		for i in range(0, n-1):
				a[i] = a[i+1]-a[i]
		
		n-=1
		a = a[0:n]
		
	print(max(total, a[0]))

Submission (verdict: Wrong answer on test 2):
t=int(input())
while t:
	t-=1
	n = int(input())
	a = list(map(int, input().split()))

	total = sum(a)
	while n > 1:
		left = sum(a)-sum(a[1:n])
		right = sum(a)-sum(a[:n-1])

		total = max(total, left, right)
		if left >= right:
			a.reverse()

		for i in range(0, n-1):
				a[i] = a[i+1]-a[i]
		
		n-=1
		a = a[0:n]
		
	print(max(total, a[0]))
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define pb push_back
#define all(x) (x).begin(), (x).end()

void solve() {
    int n;
    cin >> n;
    vi adj[n + 1];
    vi f(n + 1, 0);

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
        f[u]++;
        f[v]++;
    }
    
    if (n <= 2) {
        cout << 0 << endl;
        return;
    }
    if (n == 3) {
        cout << 1 << endl;
        return;
    }

    // int mx = max_element(f.begin() + 1, f.end()) - f.begin();
    int mx_val=0,mx=0;
    for(int i=n;i>=1;i--)
    {
        if(f[i]>mx_val )
        {
            mx_val=f[i];
            mx=i;
        }
    }
    // cout<<mx<<endl;
    vi deg(n + 1);
    for (int i = 1; i <= n; i++) {
        deg[i] = adj[i].size();
    }

    int temp = deg[mx];

    for (auto ele : adj[mx]) {
        deg[ele]--;
    }
   

    deg[mx] = 0;
    //  for(int i=1;i<=n;i++ )
    // {
    //     cout<<i<<"->"<<deg[i]<<endl;
    // }
    int sc_mx = max_element(deg.begin() + 1, deg.end()) - deg.begin();
    // cout<<sc_mx<<endl;

    cout << deg[sc_mx] + temp - 1 << endl;
}

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


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define pb push_back
#define all(x) (x).begin(), (x).end()

void solve() {
    int n;
    cin >> n;
    vi adj[n + 1];
    vi f(n + 1, 0);

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
        f[u]++;
        f[v]++;
    }
    
    if (n <= 2) {
        cout << 0 << endl;
        return;
    }
    if (n == 3) {
        cout << 1 << endl;
        return;
    }

    // int mx = max_element(f.begin() + 1, f.end()) - f.begin();
    int mx_val=0,mx=0;
    for(int i=n;i>=1;i--)
    {
        if(f[i]>mx_val )
        {
            mx_val=f[i];
            mx=i;
        }
    }
    // cout<<mx<<endl;
    vi deg(n + 1);
    int cnt=0;
    int ans=adj[mx].size();
    for (int i = 1; i <= n; i++) {
        deg[i] = adj[i].size();
        if(deg[i] == ans)
        {
            cnt++;
        }
    }

    if(cnt>=2)
    {
        cout<<ans+ans-1<<endl;
        return ;
    }

    int temp = deg[mx];

    for (auto ele : adj[mx]) {
        deg[ele]--;
    }
   

    deg[mx] = 0;
   
    int sc_mx = max_element(deg.begin() + 1, deg.end()) - deg.begin();
    // cout<<sc_mx<<endl;

    cout << deg[sc_mx] + temp - 1 << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tc;
    cin >> tc;
    while (tc--) solve();
    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 int long long
#define vi vector<int>
#define pb push_back
#define all(x) (x).begin(), (x).end()

void solve() {
    int n;
    cin >> n;
    vi adj[n + 1];
    vi f(n + 1, 0);

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
        f[u]++;
        f[v]++;
    }
    
    if (n <= 2) {
        cout << 0 << endl;
        return;
    }
    if (n == 3) {
        cout << 1 << endl;
        return;
    }

    // int mx = max_element(f.begin() + 1, f.end()) - f.begin();
    int mx_val=0,mx=0;
    for(int i=n;i>=1;i--)
    {
        if(f[i]>mx_val )
        {
            mx_val=f[i];
            mx=i;
        }
    }
    // cout<<mx<<endl;
    vi deg(n + 1);
    int cnt=0;
    int ans=adj[mx].size();
    for (int i = 1; i <= n; i++) {
        deg[i] = adj[i].size();
        if(deg[i] == ans)
        {
            cnt++;
        }
    }

    if(cnt>=2)
    {
        cout<<ans+ans-1<<endl;
        return ;
    }

    int temp = deg[mx];

    for (auto ele : adj[mx]) {
        deg[ele]--;
    }
   

    deg[mx] = 0;
   
    int sc_mx = max_element(deg.begin() + 1, deg.end()) - deg.begin();
    // cout<<sc_mx<<endl;

    cout << deg[sc_mx] + temp - 1 << endl;
}

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


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define pb push_back
#define all(x) (x).begin(), (x).end()

void solve() {
    int n;
    cin >> n;
    vi adj[n + 1];
    vi f(n + 1, 0);

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
        f[u]++;
        f[v]++;
    }
    
    if (n <= 2) {
        cout << 0 << endl;
        return;
    }
    if (n == 3) {
        cout << 1 << endl;
        return;
    }

    int ind = max_element(all(f)) - f.begin();
    int ans = f[ind];

    int ct = 0;
    for (auto it : adj[ind]) {    
        if (f[it] == ans)
            ct++;
    }

    if (ct >= 2) {
        cout << (ans + ans - 1) << endl;
        return;
    }

    for (auto it : adj[ind]) { 
        f[it]--;
    }
    f[ind] = 0;

    int ind1 = max_element(all(f)) - f.begin();
    ans += (f[ind1] - 1);
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tc;
    cin >> tc;
    while (tc--) solve();
    return 0;
}
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 int long long
#define vi vector<int>
#define pb push_back
#define all(x) (x).begin(), (x).end()

void solve() {
    int n;
    cin >> n;
    vi adj[n + 1];
    vi f(n + 1, 0);

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
        f[u]++;
        f[v]++;
    }

    if (n <= 2) {
        cout << 0 << endl;
        return;
    }
    if (n == 3) {
        cout << 1 << endl;
        return;
    }

    int mx = max_element(f.begin() + 1, f.end()) - f.begin();
    vi deg(n + 1);
    for (int i = 1; i <= n; i++) {
        deg[i] = adj[i].size();
    }

    int temp = deg[mx];

    for (auto ele : adj[mx]) {
        deg[ele]--;
    }

    deg[mx] = 0;
    int sc_mx = max_element(deg.begin() + 1, deg.end()) - deg.begin();

    cout << deg[sc_mx] + temp - 1 << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tc;
    cin >> tc;
    while (tc--) solve();
    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 int long long
#define vi vector<int>
#define pb push_back
#define all(x) (x).begin(), (x).end()

void solve() {
    int n;
    cin >> n;
    vi adj[n + 1];
    vi f(n + 1, 0);

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
        f[u]++;
        f[v]++;
    }

    if (n <= 2) {
        cout << 0 << endl;
        return;
    }
    if (n == 3) {
        cout << 1 << endl;
        return;
    }

    int mx = max_element(f.begin() + 1, f.end()) - f.begin();
    vi deg(n + 1);
    for (int i = 1; i <= n; i++) {
        deg[i] = adj[i].size();
    }

    int temp = deg[mx];

    for (auto ele : adj[mx]) {
        deg[ele]--;
    }

    deg[mx] = 0;
    int sc_mx = max_element(deg.begin() + 1, deg.end()) - deg.begin();

    cout << deg[sc_mx] + temp - 1 << endl;
}

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


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define pb push_back
#define all(x) (x).begin(), (x).end()

void solve() {
    int n;
    cin >> n;
    vi adj[n + 1];
    vi f(n + 1, 0);

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
        f[u]++;
        f[v]++;
    }
    f[1]=1;

    if (n <= 2) {
        cout << 0 << endl;
        return;
    }
    // if (n == 3) {
    //     cout << 1 << endl;
    //     return;
    // }

    int mx = max_element(f.begin() + 1, f.end()) - f.begin();
    // cout<<mx<<endl;
    vi deg(n + 1);
    for (int i = 1; i <= n; i++) {
        deg[i] = adj[i].size();
    }

    int temp = deg[mx];

    for (auto ele : adj[mx]) {
        deg[ele]--;
    }
   

    deg[mx] = 0;
    //  for(int i=1;i<=n;i++ )
    // {
    //     cout<<i<<"->"<<deg[i]<<endl;
    // }
    int sc_mx = max_element(deg.begin() + 1, deg.end()) - deg.begin();
    // cout<<sc_mx<<endl;

    cout << deg[sc_mx] + temp - 1 << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tc;
    cin >> tc;
    while (tc--) solve();
    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 int long long
#define vi vector<int>
#define pb push_back
#define all(x) (x).begin(), (x).end()

void solve() {
    int n;
    cin >> n;
    vi adj[n + 1];
    vi f(n + 1, 0);

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
        f[u]++;
        f[v]++;
    }
    f[1]=1;

    if (n <= 2) {
        cout << 0 << endl;
        return;
    }
    // if (n == 3) {
    //     cout << 1 << endl;
    //     return;
    // }

    int mx = max_element(f.begin() + 1, f.end()) - f.begin();
    // cout<<mx<<endl;
    vi deg(n + 1);
    for (int i = 1; i <= n; i++) {
        deg[i] = adj[i].size();
    }

    int temp = deg[mx];

    for (auto ele : adj[mx]) {
        deg[ele]--;
    }
   

    deg[mx] = 0;
    //  for(int i=1;i<=n;i++ )
    // {
    //     cout<<i<<"->"<<deg[i]<<endl;
    // }
    int sc_mx = max_element(deg.begin() + 1, deg.end()) - deg.begin();
    // cout<<sc_mx<<endl;

    cout << deg[sc_mx] + temp - 1 << endl;
}

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


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define pb push_back
#define all(x) (x).begin(), (x).end()

void solve() {
    int n;
    cin >> n;
    vi adj[n + 1];
    vi f(n + 1, 0);

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
        f[u]++;
        f[v]++;
    }
    
    if (n <= 2) {
        cout << 0 << endl;
        return;
    }
    if (n == 3) {
        cout << 1 << endl;
        return;
    }

    // int mx = max_element(f.begin() + 1, f.end()) - f.begin();
    int mx_val=0,mx=0;
    for(int i=n;i>=1;i--)
    {
        if(f[i]>mx_val )
        {
            mx_val=f[i];
            mx=i;
        }
    }
    // cout<<mx<<endl;
    vi deg(n + 1);
    for (int i = 1; i <= n; i++) {
        deg[i] = adj[i].size();
    }

    int temp = deg[mx];

    for (auto ele : adj[mx]) {
        deg[ele]--;
    }
   

    deg[mx] = 0;
    //  for(int i=1;i<=n;i++ )
    // {
    //     cout<<i<<"->"<<deg[i]<<endl;
    // }
    int sc_mx = max_element(deg.begin() + 1, deg.end()) - deg.begin();
    // cout<<sc_mx<<endl;

    cout << deg[sc_mx] + temp - 1 << endl;
}

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