ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=2*(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
ll mn, n,t, cm, b, sat, c, l, r, k, m;
ll a[dim], res[dim], cnt[dim];
pll p[dim];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;

        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        if(a[2]>a[1]){
            cout<<"YES"<<endl;
        }
        else if(a[1]==a[2]){
            ll fl=0;
            for(int i=3; i<=n; i+=2){
                if(a[i]>a[i+1] && i!=n)fl=1;
            }
            if(fl){
                cout<<"NO"<<endl;

            }
            else cout<<"YES"<<endl;

        }
        else{
            cout<<"NO"<<endl;
        }
    }


    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=2*(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
ll mn, n,t, cm, b, sat, c, l, r, k, m;
ll a[dim], res[dim], cnt[dim];
pll p[dim];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;

        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        if(a[2]>a[1]){
            ll fl=0;
            for(int i=3; i<n; i++){
                if(a[i]-a[i+1]>=2)fl=1;
            }

            if(fl){
                cout<<"NO"<<endl;

            }
            else cout<<"YES"<<endl;
        }
        else if(a[1]==a[2]){
            ll fl=0;
            for(int i=3; i<n; i+=2){
                if(a[i]>a[i+1] )fl=1;
            }
            if(fl){
                cout<<"NO"<<endl;

            }
            else cout<<"YES"<<endl;


        }
        else{
            cout<<"NO"<<endl;
        }
    }


    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=2*(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
ll mn, n,t, cm, b, sat, c, l, r, k, m;
ll a[dim], res[dim], cnt[dim];
pll p[dim];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;

        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        if(a[2]>a[1]){
            ll fl=0;
            for(int i=3; i<n; i++){
                if(a[i]-a[i+1]>=2)fl=1;
            }

            if(fl){
                cout<<"NO"<<endl;

            }
            else cout<<"YES"<<endl;
        }
        else if(a[1]==a[2]){
            ll fl=0;
            for(int i=3; i<n; i+=2){
                if(a[i]>a[i+1] )fl=1;
            }
            if(fl){
                cout<<"NO"<<endl;

            }
            else cout<<"YES"<<endl;


        }
        else{
            cout<<"NO"<<endl;
        }
    }


    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=2*(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
ll mn, n,t, cm, b, sat, c, l, r, k, m;
ll a[dim], res[dim], cnt[dim];
pll p[dim];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;

        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        ll fl=0;
        for(int i=1; i<n; i++){
            if(a[i]>a[i+1]){
                fl=1;
            }
            else{
                a[i+1]-=a[i];
            }
        }
        if(fl==1){
            cout<<"NO"<<endl;

        }
        else cout<<"YES"<<endl;
    }


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

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

using namespace std;
typedef int ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>
ll mn, n, cm, b, sat, pr[dim], c,  k, m, l, r, g, t;
ll vis[dim];
//string t;
string s;
ll dp[dim], a[dim];


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x, y, k;
    cin>>t;
    while(t--){
        cin>>n;
        vll tmp, cur;
        ll sum;
        sum=0;
        ll mx=-inf;
        for(int i=1; i<=n; i++){
            cin>>x;
            tmp.push_back(x);
            sum+=x;
        }
        mx=sum;
        for(int i=1; i<n; i++){
            sum=0;
            for(int i=0; i+1<tmp.size(); i++){
                cur.push_back(tmp[i+1]-tmp[i]);
                sum+=tmp[i+1]-tmp[i];
            }
            if(sum<0 ){
               for(int j=0; j<n-i; j++){
                cur[j]=-cur[j];
               }

                sum=-sum;
            }

            mx=max(mx, sum);

            tmp=cur;
            cur.clear();
        }
        cout<<mx<<endl;

    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>
ll mn, n, cm, b, sat, pr[dim], c,  k, m, l, r, g, t;
ll vis[dim];
//string t;
string s;
ll dp[dim], a[dim];


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x, y, k;
    cin>>t;
    while(t--){
        cin>>n;
        vll tmp, cur;
        ll sum;
        sum=0;
        ll mx=-inf;
        for(int i=1; i<=n; i++){
            cin>>x;
            tmp.push_back(x);
            sum+=x;
        }
        mx=sum;
        for(int i=1; i<n; i++){
            sum=0;
            for(int i=0; i+1<tmp.size(); i++){
                cur.push_back(tmp[i+1]-tmp[i]);
                sum+=tmp[i+1]-tmp[i];
            }
            if(sum<0 ){
               for(int j=0; j<n-i; j++){
                cur[j]=-cur[j];
               }

                sum=-sum;
            }

            mx=max(mx, sum);

            tmp=cur;
            cur.clear();
        }
        cout<<mx<<endl;

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

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

using namespace std;
typedef int ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>
ll mn, n, cm, b, sat, pr[dim], c,  k, m, l, r, g, t;
ll vis[dim];
//string t;
string s;
ll dp[dim], a[dim];


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x, y, k;
    cin>>t;
    while(t--){
        cin>>n;
        vll tmp, cur;
        ll sum;
        sum=0;
        ll mx=-inf;
        for(int i=1; i<=n; i++){
            cin>>x;
            tmp.push_back(x);
            sum+=x;
        }
        mx=sum;
        for(int i=1; i<n; i++){
            sum=0;
            reverse(tmp.begin(), tmp.end());
            for(int i=0; i+1<tmp.size(); i++){
                cur.push_back(tmp[i+1]-tmp[i]);
                sum+=tmp[i+1]-tmp[i];
            }
            if(sum<0 ){
                reverse(cur.begin(), cur.end());
                sum=-sum;
            }

            mx=max(mx, sum);

            tmp=cur;
            cur.clear();
        }
        cout<<mx<<endl;

    }
    return 0;
}


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

using namespace std;
typedef int ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>
ll mn, n, cm, b, sat, pr[dim], c,  k, m, l, r, g, t;
ll vis[dim];
//string t;
string s;
ll dp[dim], a[dim];


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x, y, k;
    cin>>t;
    while(t--){
        cin>>n;
        vll tmp, cur;
        ll sum;
        sum=0;
        ll mx=-inf;
        for(int i=1; i<=n; i++){
            cin>>x;
            tmp.push_back(x);
            sum+=x;
        }
        mx=sum;
        for(int i=1; i<n; i++){
            sum=0;
            for(int i=0; i+1<tmp.size(); i++){
                cur.push_back(tmp[i+1]-tmp[i]);
                sum+=tmp[i+1]-tmp[i];
            }
            if(sum<0 ){
               for(int j=0; j<n-i; j++){
                cur[j]=-cur[j];
               }

                sum=-sum;
            }

            mx=max(mx, sum);

            tmp=cur;
            cur.clear();
        }
        cout<<mx<<endl;

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


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

using namespace std;
typedef int ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>
ll mn, n, cm, b, sat, pr[dim], c,  k, m, l, r, g, t;
ll vis[dim];
//string t;
string s;
ll dp[dim], a[dim];


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x, y, k;
    cin>>t;
    while(t--){
        cin>>n;
        vll tmp, cur;
        ll sum;
        sum=0;
        ll mx=-inf;
        for(int i=1; i<=n; i++){
            cin>>x;
            tmp.push_back(x);
            sum+=x;
        }
        mx=sum;
        for(int i=1; i<n; i++){
            sum=0;
            reverse(tmp.begin(), tmp.end());
            for(int i=0; i+1<tmp.size(); i++){
                cur.push_back(tmp[i+1]-tmp[i]);
                sum+=tmp[i+1]-tmp[i];
            }
            mx=max(mx, sum);

            tmp=cur;
            cur.clear();
        }
        cout<<mx<<endl;

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

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

using namespace std;
typedef int ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>
ll mn, n, cm, b, sat, pr[dim], c,  k, m, l, r, g, t;
ll vis[dim];
//string t;
string s;
ll dp[dim], a[dim];


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x, y, k;
    cin>>t;
    while(t--){
        cin>>n;
        vll tmp, cur;
        ll sum;
        sum=0;
        ll mx=-inf;
        for(int i=1; i<=n; i++){
            cin>>x;
            tmp.push_back(x);
            sum+=x;
        }
        mx=sum;
        for(int i=1; i<n; i++){
            sum=0;
            reverse(tmp.begin(), tmp.end());
            for(int i=0; i+1<tmp.size(); i++){
                cur.push_back(tmp[i+1]-tmp[i]);
                sum+=tmp[i+1]-tmp[i];
            }
            mx=max(mx, sum);

            tmp=cur;
            cur.clear();
        }
        cout<<mx<<endl;

    }
    return 0;
}


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

using namespace std;
typedef int ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>
ll mn, n, cm, b, sat, pr[dim], c,  k, m, l, r, g, t;
ll vis[dim];
//string t;
string s;
ll dp[dim], a[dim];


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x, y, k;
    cin>>t;
    while(t--){
        cin>>n;
        vll tmp, cur;
        ll sum;
        sum=0;
        ll mx=-inf;
        for(int i=1; i<=n; i++){
            cin>>x;
            tmp.push_back(x);
            sum+=x;
        }
        mx=sum;
        for(int i=1; i<n; i++){
            sum=0;
            reverse(tmp.begin(), tmp.end());
            for(int i=0; i+1<tmp.size(); i++){
                cur.push_back(tmp[i+1]-tmp[i]);
                sum+=tmp[i+1]-tmp[i];
            }
            if(sum<0 ){
                reverse(cur.begin(), cur.end());
                sum=-sum;
            }

            mx=max(mx, sum);

            tmp=cur;
            cur.clear();
        }
        cout<<mx<<endl;

    }
    return 0;
}
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;
#define int long long 
#define   mod             1000000007
#define test int t; cin>>t; while(t--)
int cntbit(int x){
    int cnt=0;
    while (x)
    {
        cnt++;
        x/=2;
    }
    return cnt;
    
}
void solve(){
    test{
        int l,r;
        cin>>l>>r;
        int bit = cntbit(r);
        int a=l;
        int c=r;
        int b=0;
        int f=0;
        int ff=0;
        //cout<<bit<<endl;
        for(int i=bit-1;i>=0;i--){
            if(f && ff){
                if((a&(1<<i))==0)
                 b|=(1<<i);
                continue;
            }
            if(((1<<i)&a) && ((1<<i)&c) && f==0 && ff==0){
                b|=(1<<i);
            }
            else if((1<<i)&&a==0 && f){
                ff=1;
                 b|=(1<<i);
            }
            else if((((1<<i)&a)==0) && ((1<<i)&c)){
                //cout<<"Enter"<<endl;
                f=1;
                // zero rakhlam
            }
            else {
                b|=(1<<i);
            }
        }
        set<int>s;
        s.insert(a);
        s.insert(b);
        s.insert(c);
        //cout<<a<<" "<<b<<" "<<c<<endl;
        int ans=0;
        if(s.size()==3){
            ans = (a^b) + (b^c) + (c^a);
        }
        
        a=l;
        c=r;
        b=0;
        f=0;
        ff=0;
        for(int i=bit;i>=0;i--){
            if(f && ff){
                if((a&(1<<i))==0)
                 b|=(1<<i);
                continue;
            }
            if(((1<<i)&a) && ((1<<i)&c) && f==0 && ff==0){
                b|=(1<<i);
            }
            else if(((1<<i)&&c) && f){
                ff=1;
                 //b|=(1<<i);
            }
            else if((((1<<i)&a)==0) && ((1<<i)&c)){
                f=1;
                b|=(1<<i);
                // 1 rakhlam
            }
            // else {
            //     b|=(1<<i);
            // }
        }
        set<int>ss;
        ss.insert(a);
        ss.insert(b);
        ss.insert(c);
        int x=0;
        if(ss.size()==3){
             x = (a^b) + (b^c) + (c^a);
           
        }
        if(ans>=x){
            for(auto x:s) cout<<x<<" ";
            cout<<endl;
        }
        else {
            for(auto x:ss) cout<<x<<" ";
            cout<<endl;
        }


    }

}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();

}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


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

#define fr(i,s,e) for(ll i=s ; i<e ; i++)
#define rf(i,s,e) for(ll i=s ; i>=e ; i--)
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef vector<ll> vll;

ll MOD=998244353;

ll fastpow(ll base , ll power){
	ll ans=1;
	while(power>0){
		if(power&1){
			ans*=base;
			ans%=MOD;
		}
		power>>=1;
		base*=base;
		base%=MOD;
	}
	return ans;
}

void solve(){
	ll n;
	cin >> n;
	vector<vll> v(n+1);
	vll used(n+1);
	fr(i, 1, n+1) v[i].pb(i);
	fr(i, 0, n-1){
		ll a,b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	vector<vll> v1(v.begin(), v.end());
	sort(v.begin(), v.end(), [](vll a, vll b){return a.size() < b.size();});
	fr(i, 1, v[n].size()){
		v1[v[n][i]].erase( find(v1[v[n][i]].begin(), v1[v[n][i]].end(), v[n][0]) );
	}
	v1.erase(v1.begin() + v[n][0]);

	vector<vll> v2(v1.begin(), v1.end());
	sort(v1.begin(), v1.end(), [](vll a, vll b){return a.size() < b.size();});
	fr(i, 1, v1[n-1].size()){
		fr(j, 1, v2.size()){
			if(v2[j][0] == v1[n-1][i]) v2[j].erase( find(v2[v1[n-1][i]].begin(), v2[v1[n-1][i]].end(), v1[n-1][0]) );
		}
	}
	fr(j, 1, v2.size()){
		if(v2[j][0] == v1[n-1][0]) v2.erase( v2.begin() + j);
	}
	if(v2.size()==1){cout << "0\n"; return;}
	ll cnt = 0;
	fr(i, 1, v2.size()){
		if( !used[v2[i][0]] ){
			cnt++;
			for(auto x : v2[i]) used[x] = 1;;
		}
	}
	cout << cnt << endl;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	ll tt=1;
	cin >> tt;
	while(tt--){
		solve();
	}
}
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 fr(i,s,e) for(ll i=s ; i<e ; i++)
#define rf(i,s,e) for(ll i=s ; i>=e ; i--)
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef vector<ll> vll;

ll MOD=998244353;

ll fastpow(ll base , ll power){
	ll ans=1;
	while(power>0){
		if(power&1){
			ans*=base;
			ans%=MOD;
		}
		power>>=1;
		base*=base;
		base%=MOD;
	}
	return ans;
}

void solve(){
	ll n;
	cin >> n;
	vector<vll> v(n+1);
	vll used(n+1);
	fr(i, 1, n+1) v[i].pb(i);
	fr(i, 0, n-1){
		ll a,b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	vector<vll> v1(v.begin(), v.end());
	sort(v.begin()+1, v.end(), [](vll a, vll b){return a.size() < b.size();});
	fr(i, 1, v[n].size()){
		v1[v[n][i]].erase( find(v1[v[n][i]].begin(), v1[v[n][i]].end(), v[n][0]) );
	}
	v1[v[n][0]].erase(v1[v[n][0]].begin(),v1[v[n][0]].end());
	vector<vll> v2(v1.begin(), v1.end());
	sort(v1.begin()+1, v1.end(), [](vll a, vll b){return a.size() < b.size();});
	fr(i, 1, v1[n].size()){
		v2[v1[n][i]].erase( find(v2[v1[n][i]].begin(), v2[v1[n][i]].end(), v1[n][0]) );
	}
	v2[v1[n][0]].erase(v2[v1[n][0]].begin(),v2[v1[n][0]].end());
	ll c = 0;
	fr(i, 1, n) if(v2[i].size() != 0) c++; 
	if(c==0){cout << "0\n"; return;}
	ll cnt = 0;
	stack<ll> s;
	fr(i, 1, n+1){
		if(v2[i].empty()) continue;
		if( !used[v2[i][0]] ){
			s.push(v2[i][0]);
			cnt++;
			while(!s.empty()){
				ll j = s.top();
				s.pop();
				used[j]=1;
				for(auto x:v2[j]){
					if(!used[x]) s.push(x); 
					used[x] = 1;
				}
			}
		}
	}
	cout << cnt << endl;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	ll tt=1;
	cin >> tt;
	while(tt--){
		solve();
	}
}

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

#define fr(i,s,e) for(ll i=s ; i<e ; i++)
#define rf(i,s,e) for(ll i=s ; i>=e ; i--)
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef vector<ll> vll;

ll MOD=998244353;

ll fastpow(ll base , ll power){
	ll ans=1;
	while(power>0){
		if(power&1){
			ans*=base;
			ans%=MOD;
		}
		power>>=1;
		base*=base;
		base%=MOD;
	}
	return ans;
}

void solve(){
	ll n;
	cin >> n;
	vector<vll> v(n);
	vll si(n);
	fr(i, 0, n-1){
		ll a, b;
		cin >> a >> b;
		si[--a]++;
		si[--b]++;
		v[a].pb(b);
		v[b].pb(a);
	}
	sort(si.begin(), si.end());
	ll cnt = 0, k=0;
	fr(i, 0 , n) if(si[n-2] == v[i].size()) cnt++;
	fr(i, 0 , n){
		if(si[n-1] == v[i].size()){
			ll c = 0;
			for(auto x : v[i]){
				if(v[x].size() == si[n-2]) c++;
			}
			if(c == cnt) k = 1;
			if(si[n-1] == si[n-2] && c != cnt-1) k=-1; 
		}
	}
	cout << si[n-1] + si[n-2] - 1 - (si[n-1]==si[n-2]) - k << endl;

}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	ll tt=1;
	cin >> tt;
	while(tt--){
		solve();
	}
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

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

#define fr(i,s,e) for(ll i=s ; i<e ; i++)
#define rf(i,s,e) for(ll i=s ; i>=e ; i--)
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef vector<ll> vll;

ll MOD=998244353;

ll fastpow(ll base , ll power){
	ll ans=1;
	while(power>0){
		if(power&1){
			ans*=base;
			ans%=MOD;
		}
		power>>=1;
		base*=base;
		base%=MOD;
	}
	return ans;
}

void solve(){
	ll n;
	cin >> n;
	vector<vll> v(n+1);
	vll used(n+1);
	fr(i, 1, n+1) v[i].pb(i);
	fr(i, 0, n-1){
		ll a,b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	vector<vll> v1(v.begin(), v.end());
	sort(v.begin(), v.end(), [](vll a, vll b){return a.size() < b.size();});
	fr(i, 1, v[n].size()){
		v1[v[n][i]].erase( find(v1[v[n][i]].begin(), v1[v[n][i]].end(), v[n][0]) );
	}
	v1.erase(v1.begin() + v[n][0]);

	vector<vll> v2(v1.begin(), v1.end());
	sort(v1.begin(), v1.end(), [](vll a, vll b){return a.size() < b.size();});
	fr(i, 1, v1[n-1].size()){
		fr(j, 1, v2.size()){
			if(v2[j][0] == v1[n-1][i]) v2[j].erase( find(v2[v1[n-1][i]].begin(), v2[v1[n-1][i]].end(), v1[n-1][0]) );
		}
	}
	fr(j, 1, v2.size()){
		if(v2[j][0] == v1[n-1][0]) v2.erase( v2.begin() + j);
	}
	if(v2.size()==1){cout << "0\n"; return;}
	ll cnt = 0;
	fr(i, 1, v2.size()){
		if( !used[v2[i][0]] ){
			cnt++;
			for(auto x : v2[i]) used[x] = 1;;
		}
	}
	cout << cnt << endl;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	ll tt=1;
	cin >> tt;
	while(tt--){
		solve();
	}
}

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

#define fr(i,s,e) for(ll i=s ; i<e ; i++)
#define rf(i,s,e) for(ll i=s ; i>=e ; i--)
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef vector<ll> vll;

ll MOD=998244353;

ll fastpow(ll base , ll power){
	ll ans=1;
	while(power>0){
		if(power&1){
			ans*=base;
			ans%=MOD;
		}
		power>>=1;
		base*=base;
		base%=MOD;
	}
	return ans;
}

void solve(){
	ll n;
	cin >> n;
	vector<vll> v(n+1);
	vll used(n+1);
	fr(i, 1, n+1) v[i].pb(i);
	fr(i, 0, n-1){
		ll a,b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	vector<vll> v1(v.begin(), v.end());
	sort(v.begin(), v.end(), [](vll a, vll b){return a.size() < b.size();});
	fr(i, 1, v[n].size()){
		v1[v[n][i]].erase( find(v1[v[n][i]].begin(), v1[v[n][i]].end(), v[n][0]) );
	}
	v1.erase(v1.begin() + v[n][0]);
	vector<vll> v2(v1.begin(), v1.end());
	sort(v1.begin(), v1.end(), [](vll a, vll b){return a.size() < b.size();});
	fr(i, 1, v1[n-1].size()){
		fr(j, 1, v2.size()){
			if(v2[j][0] == v1[n-1][i]) v2[j].erase( find(v2[j].begin(), v2[j].end(), v1[n-1][0]) );
		}
	}
	fr(j, 1, v2.size()){
		if(v2[j][0] == v1[n-1][0]) v2.erase( v2.begin() + j);
	}
	if(v2.size()==1){cout << "0\n"; return;}
	ll cnt = 0;
	fr(i, 1, v2.size()){
		if( !used[v2[i][0]] ){
			cnt++;
			for(auto x : v2[i]) used[x] = 1;;
		}
	}
	cout << cnt << endl;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	ll tt=1;
	cin >> tt;
	while(tt--){
		solve();
	}
}