ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


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

using i64 = long long;
using ld = long double;
using u64 = unsigned long long;
const int maxn = 1e5 + 7, mod = 1e9 + 7;

void solve()
{
    int l, r;
    std::cin >> l >> r;

    int a[35] = {}, c[35] = {}, b = 0;

    int aa = l, cc = r, n = 0, max = 0;
    while (aa != 0)
    {
        a[++n] = aa & 1;
        aa >>= 1;
    }

    max = n;
    n = 0;
    while (cc != 0)
    {
        c[++n] = cc & 1;
        cc >>= 1;
    }

    max = std::max(n, max);

    while (max > 0 && a[max] == c[max])
    {
        b += (1 << (max - 1));
        max--;
    }

    for (int i = max; i > 0; i--)
    {
        if (a[i] == c[i])
        {
            b += (a[i] & 1) << (i - 1);
        }
        else
        {
            b += 1 << (i - 1);
            if (b >= r)
            {
                b -= 1 << (i - 1);
            }
        }
    }

    std::cout << l << " " << b << " " << r << "\n";

    return;
}

void baoli()
{
    int l, r;
    std::cin >> l >> r;

    int a = l, b = l, c = l, ans = 0;

    for (int i = l; i <= r; i++)
    {
        for (int j = l; j <= r; j++)
        {
            for (int k = l; k <= r; k++)
            {
                if ((i ^ j) + (i ^ k) + (j ^ k) > ans)
                {
                    ans = (i ^ j) + (i ^ k) + (j ^ k);
                    a = i;
                    b = j;
                    c = k;
                }
            }
        }
    }

    std::cout << a << " " << b << " " << c << " " << ans << "\n";
}

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

    // std::cout << std::bitset<10>(98) << "\n";
    // std::cout << std::bitset<10>(69) << "\n";
    // std::cout << (98 ^ 93) + (98 ^ 93) + (93 ^ 93) << "\n";
    int T = 1;
    std::cin >> T;
    while (T--)
    {
        solve();
    }

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


Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define x first
#define y second
#define int long long

const int MAXN = 2e5 + 100;
vector<int> g[MAXN];
int dp[MAXN][2];

void dfs(int v, int p) {
    int c = 0;
    int mx1 = -1e9;
    int mx2 = -1e9;
    for (int u : g[v]) {
        if (u != p) {
            dfs(u, v);
            c++;
            if (dp[v][0] >= mx2) {
                mx1 = mx2;
                mx2 = dp[v][0];
            } else if (dp[v][0] >= mx1) {
                mx1 = dp[v][0];
            }
            dp[v][1] = max(dp[v][1], dp[u][1]);
            dp[v][0] = max(dp[v][0], dp[u][0]);
        }
    }
    dp[v][0] = max(dp[v][0], c + (p != -1));
    dp[v][1] = max(dp[v][1], mx1 + mx2);
    dp[v][1] = max(dp[v][1], c + (p != -1) + mx2 - 1);
}

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        g[i].clear();
        dp[i][0] = dp[i][1] = 0;
    }
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0, -1);
    cout << dp[0][1] << '\n';
}

signed main() {
    ios ::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define x first
#define y second
#define int long long

const int MAXN = 2e5 + 100;
vector<int> g[MAXN];

int power[MAXN];
int used[MAXN];

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        g[i].clear();
        power[i] = 0;
    }
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    set<pair<int, int>> s;
    for (int i = 0; i < n; i++) {
        power[i] = g[i].size();
        s.insert({power[i], i});
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int u : g[i]) {
            s.erase({-power[u], u});
            power[u]--;
            s.insert({-power[u], u});
        }
        s.erase({-power[i], i});
        ans = max(ans, power[i] + -(s.begin()->x) - 1);
        s.insert({power[i], i});
        for (int u : g[i]) {
            s.erase({-power[u], u});
            power[u]++;
            s.insert({-power[u], u});
        }
    }
    cout << ans << '\n';
}

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

Submission (verdict: Accepted):
#include <iostream>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define x first
#define y second
#define int long long

const int MAXN = 2e5 + 100;
vector<int> g[MAXN];

int power[MAXN];
int used[MAXN];

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        g[i].clear();
        power[i] = 0;
    }
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    set<pair<int, int>> s;
    for (int i = 0; i < n; i++) {
        power[i] = g[i].size();
        s.insert({power[i], i});
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int u : g[i]) {
            s.erase({-power[u], u});
            power[u]--;
            s.insert({-power[u], u});
        }
        s.erase({-power[i], i});
        ans = max(ans, power[i] + -(s.begin()->x) - 1);
        s.insert({-power[i], i});
        for (int u : g[i]) {
            s.erase({-power[u], u});
            power[u]++;
            s.insert({-power[u], u});
        }
    }
    cout << ans << '\n';
}

signed main() {
    ios ::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
import sys
from collections import defaultdict,deque,Counter
from heapq import heappush,heappop,heapify
from math import inf,comb,ceil,log,lcm,gcd,isqrt
from functools import cache
from itertools import accumulate,combinations,permutations
from bisect import bisect_left,bisect_right,insort_left
from random import randint

input=lambda:sys.stdin.readline().rstrip()
inp=lambda:list(map(int,input().split()))
I=lambda:int(input())
fact=[cur:=1]+[cur:=(cur*i)for i in range(1,2000)]
def comb(n,k):
    return fact[n]//(fact[n-k]*fact[k])
def f(n,b):
    o=0
    for i in range(n):
        if b:
            if i%2:
                o-=comb(n-1,i)*a[i]
            else:
                o+=comb(n-1,i)*a[i]
        else:
            if i%2:
                o-=comb(n-1,i)*a[~i]
            else:
                o+=comb(n-1,i)*a[~i]

    return o
t=I()
for _ in range(t):
    n=I()
    a=inp()
    o=sum(a)
    for i in range(n-1):
        c1=f(i+1,1)
        c2=f(i+1,0)
        o=max(abs(c1)+abs(c2),o)
    #print(sum(abs(e)for e in a))
    print(o)


Submission (verdict: Wrong answer on test 2):
import sys
from collections import defaultdict,deque,Counter
from heapq import heappush,heappop,heapify
from math import inf,comb,ceil,log,lcm,gcd,isqrt
from functools import cache
from itertools import accumulate,combinations,permutations
from bisect import bisect_left,bisect_right,insort_left
from random import randint

input=lambda:sys.stdin.readline().rstrip()
inp=lambda:list(map(int,input().split()))
I=lambda:int(input())
fact=[cur:=1]+[cur:=(cur*i)for i in range(1,100)]
def comb(n,k):
    return fact[n]//(fact[n-k]*fact[k])
def f(n,b):
    o=0
    for i in range(n):
        if b:
            if i%2:
                o-=comb(n-1,i)*a[i]
            else:
                o+=comb(n-1,i)*a[i]
        else:
            if i%2:
                o-=comb(n-1,i)*a[~i]
            else:
                o+=comb(n-1,i)*a[~i]

    return o
t=I()
for _ in range(t):
    n=I()
    a=inp()
    o=sum(a)
    for i in range(n-1):
        c1=f(i+1,1)
        c2=f(i+1,0)
        o=max(abs(c1)+abs(c2),o)
    #print(sum(abs(e)for e in a))
    print(max(o,f(n,0),f(n,1)))
Problem: 2062C - Cirno and Operations
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
import sys
from collections import defaultdict,deque,Counter
from heapq import heappush,heappop,heapify
from math import inf,comb,ceil,log,lcm,gcd,isqrt
from functools import cache
from itertools import accumulate,combinations,permutations
from bisect import bisect_left,bisect_right,insort_left
from random import randint

input=lambda:sys.stdin.readline().rstrip()
inp=lambda:list(map(int,input().split()))
I=lambda:int(input())
fact=[cur:=1]+[cur:=(cur*i)for i in range(1,100)]
def comb(n,k):
    return fact[n]//(fact[n-k]*fact[k])
def f(n,b):
    o=0
    for i in range(n):
        if b:
            if i%2:
                o-=comb(n-1,i)*a[i]
            else:
                o+=comb(n-1,i)*a[i]
        else:
            if i%2:
                o-=comb(n-1,i)*a[~i]
            else:
                o+=comb(n-1,i)*a[~i]

    return o
t=I()
for _ in range(t):
    n=I()
    a=inp()
    o=sum(a)
    for i in range(n-1):
        c1=f(i+1,1)
        c2=f(i+1,0)
        o=max(abs(c1)+abs(c2),o)
    #print(sum(abs(e)for e in a))
    print(max(o,f(n,0),f(n,1)))


Submission (verdict: Accepted):
import sys
from collections import defaultdict,deque,Counter
from heapq import heappush,heappop,heapify
from math import inf,comb,ceil,log,lcm,gcd,isqrt
from functools import cache
from itertools import accumulate,combinations,permutations
from bisect import bisect_left,bisect_right,insort_left
from random import randint

input=lambda:sys.stdin.readline().rstrip()
inp=lambda:list(map(int,input().split()))
I=lambda:int(input())
fact=[cur:=1]+[cur:=(cur*i)for i in range(1,100)]
def comb(n,k):
    return fact[n]//(fact[n-k]*fact[k])
def f(n,b):
    o=0
    for i in range(n):
        if b:
            if i%2:
                o-=comb(n-1,i)*a[i]
            else:
                o+=comb(n-1,i)*a[i]
        else:
            if i%2:
                o-=comb(n-1,i)*a[~i]
            else:
                o+=comb(n-1,i)*a[~i]

    return o
"""def bf(ox):
    
    n=len(ox)
    o=sum(ox)

    for i in range(1<<(n-1)):
        x=ox.copy()
        for v in range(n-1):
            if (1<<v)&i:
                x=[x[ii]-x[ii+1]for ii in range(len(x)-1)]
            else:
                x=[x[ii+1]-x[ii]for ii in range(len(x)-1)]
            o=max(o,sum(x))
    return o"""

t=I()
for _ in range(t):
    n=I()
    a=inp()
    #n=randint(1,5)
    #a=[randint(-1000,1000)for _ in range(n)]
    o=sum(a)
    for i in range(n-1):
        c1=f(i+1,1)
        c2=f(i+1,0)
        if i==0:
            o=max(o,abs(a[-1]-a[0]))
        else:
            o=max(abs(c1)+abs(c2),o)
    #print(sum(abs(e)for e in a))
    o=max(o,f(n,0),f(n,1))
    print(o)
    #assert o==bf(a),(bf(a),o,a)
Problem: 2062C - Cirno and Operations
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 2):
import sys
from collections import defaultdict,deque,Counter
from heapq import heappush,heappop,heapify
from math import inf,comb,ceil,log,lcm,gcd,isqrt
from functools import cache
from itertools import accumulate,combinations,permutations
from bisect import bisect_left,bisect_right,insort_left
from random import randint

input=lambda:sys.stdin.readline().rstrip()
inp=lambda:list(map(int,input().split()))
I=lambda:int(input())
fact=[cur:=1]+[cur:=(cur*i)for i in range(1,2000)]
def comb(n,k):
    return fact[n]//(fact[n-k]*fact[k])
def f(n,b):
    o=0
    for i in range(n):
        if b:
            if i%2:
                o-=comb(n-1,i)*a[i]
            else:
                o+=comb(n-1,i)*a[i]
        else:
            if i%2:
                o-=comb(n-1,i)*a[~i]
            else:
                o+=comb(n-1,i)*a[~i]

    return o
t=I()
for _ in range(t):
    n=I()
    a=inp()
    o=sum(a)
    for i in range(n-1):
        c1=f(i+1,1)
        c2=f(i+1,0)
        o=max(abs(c1)+abs(c2),o)
    #print(sum(abs(e)for e in a))
    print(o)
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int main(){
fast();
int t;
cin>>t;
while(t--){
ll n,m;
cin>>n>>m;
vector<ll> a,b;
for(ll i=0;i<n;i++){
    ll x;
    cin>>x;
    a.push_back(x);
}
for(ll i=0;i<m;i++){
    ll x;
    cin>>x;
    b.push_back(x);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
if(b==a){
    cout<<"Yes"<<endl;
    continue;
}
if(b.size()>=a.size()){
    cout<<"No"<<endl;
    continue;
}
ll fg=0;
map<ll,ll> aa,bb;
for(ll i=0;i<n;i++){
  aa[a[i]]++;
}
for(ll i=0;i<m;i++){
    bb[b[i]]++;
}
for(auto &e : bb){
    if(aa[e.first]>0){
        int pk = aa[e.first],kp=bb[e.first];
        aa[e.first]-=min(kp,pk);
        bb[e.first]-=min(kp,pk);
    }
}
a.clear(),b.clear();
for(auto &e : aa){
    while(e.second!=0){
        a.push_back(e.first);
        e.second--;
    }
}
for(auto &e : bb){
    while(e.second!=0){
        b.push_back(e.first);
        e.second--;
    }
}
// for(auto & e : a){
//     cout<<e<<" ";
// }
// cout<<endl;
// for(auto & e : b){
//     cout<<e<<" ";
// }
//cout<<endl;
m=b.size();
n=a.size();
for(ll i=0;i<m;i++){
    if(i+1==a.size()){
        fg=1;
        break;
    }
    if(a[i]!=b[i]){
        if(abs(a[i]-a[i+1])>=2){
            fg=1;
            break;
        }else{
            a[i]+=a[i+1];
            a.erase(find(a.begin(),a.end(),a[i+1]));
            i--;
        }
    }
}
if(a==b){
    cout<<"Yes"<<endl;
    continue;
}
if(fg || a.size()!=m){
    cout<<"No"<<endl;
}else{
    cout<<"Yes"<<endl;
}





}
return 0;
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int main(){
fast();
int t;
cin>>t;
while(t--){
ll n,m;
cin>>n>>m;
vector<ll> a,b;
for(ll i=0;i<n;i++){
    ll x;
    cin>>x;
    a.push_back(x);
}
for(ll i=0;i<m;i++){
    ll x;
    cin>>x;
    b.push_back(x);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
if(b==a){
    cout<<"Yes"<<endl;
    continue;
}
if(b.size()>=a.size()){
    cout<<"No"<<endl;
    continue;
}
ll fg=0;
map<ll,ll> aa;
for(auto &e : a){
    aa[e]++;
}
queue<ll> q;
for(auto &e : b){
    q.push(e);
}
ll c=0;
while(!q.empty() && q.size()+c<=n){
    ll val=q.front();
    if(aa[val]>0){
        aa[val]--;
        q.pop();
        c++;
    }else{
        ll pk = val/2,kp=val-pk;
        q.pop();
        if(aa[pk]>1){
            aa[pk]--;
            c++;
        }else{
            q.push(pk);
        }
        if(aa[kp]>1){
            aa[kp]--;
            c++;
        }else{
            q.push(kp);
        }
    }
}
ll f=0;
for(auto &e : aa){
    if(e.second>0){
        f=1;
        break;
    }
}
if(q.empty() && f==0){
    cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}


}
return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int main(){
fast();
int t;
cin>>t;
while(t--){
ll n,m;
cin>>n>>m;
vector<ll> a,b;
for(ll i=0;i<n;i++){
    ll x;
    cin>>x;
    a.push_back(x);
}
for(ll i=0;i<m;i++){
    ll x;
    cin>>x;
    b.push_back(x);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
if(b==a){
    cout<<"Yes"<<endl;
    continue;
}
if(b.size()>=a.size()){
    cout<<"No"<<endl;
    continue;
}
ll fg=0;
map<ll,ll> aa,bb;
for(ll i=0;i<n;i++){
  aa[a[i]]++;
}
for(ll i=0;i<m;i++){
    bb[b[i]]++;
}
for(auto &e : bb){
    if(aa[e.first]>0){
        aa[e.first]-=min(aa[e.first],bb[e.first]);
        bb[e.first]-=min(aa[e.first],bb[e.first]);
    }
}
a.clear(),b.clear();
for(auto &e : aa){
    while(e.second!=0){
        a.push_back(e.first);
        e.second--;
    }
}
for(auto &e : bb){
    while(e.second!=0){
        b.push_back(e.first);
        e.second--;
    }
}
// for(auto & e : a){
//     cout<<e<<" ";
// }
// cout<<endl;
// for(auto & e : b){
//     cout<<e<<" ";
// }
// cout<<endl;
m=b.size();
n=a.size();
for(ll i=0;i<m;i++){
    if(i+1==a.size()){
        fg=1;
        break;
    }
    if(a[i]!=b[i]){
        if(abs(a[i]-a[i+1])>=2){
            fg=1;
            break;
        }else{
            a[i]+=a[i+1];
            a.erase(find(a.begin(),a.end(),a[i+1]));
            i--;
        }
    }
}
if(a==b){
    cout<<"Yes"<<endl;
    continue;
}
if(fg || a.size()!=m){
    cout<<"No"<<endl;
}else{
    cout<<"Yes"<<endl;
}





}
return 0;
}
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64


Submission (verdict: Runtime error on test 1):
for t in range(int(input())):
    n = int(input())
    s = str(n)

    mod = sum(s)%9

    if mod==0:
        print('YES')
    
    else:
        count2 = 0
        count3 = 0
        for char in s:
            if char=='2':
                count2 += 1
            elif char=='3':
                count3 += 1

        if mod==1:
            if count2>=4 or (count2>=1 and count3>=2):
                print('YES')

        elif mod==2:
            if (count2>=2 and count3>=2) or (count2>=5 and count3>=1):
                print('YES')

        elif mod==3:
            if (count3>=1) or (count2>=3):
                print('YES')

        elif mod==4:
            if (count2>=4 and count3>=1) or (count2>=1 and count3>=2):
                print('YES')

        elif mod==5:
            if (count2>=2):
                print('YES')

        elif mod==6:
            if (count2>=6) or (count2>=3 and count3>=1) or (count3>=2):
                print('YES')

        elif mod==7:
            if (count2>=1):
                print('YES')

        elif mod==8:
            if (count2>=5) or (count2>=2 and count3>=1):
                print('YES')
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64

Previous submission (verdict: Runtime error on test 1):
for t in range(int(input())):
    n = int(input())
    s = str(n)

    mod = sum(s)%9

    if mod==0:
        print('YES')
    
    else:
        count2 = 0
        count3 = 0
        for char in s:
            if char=='2':
                count2 += 1
            elif char=='3':
                count3 += 1

        if mod==1:
            if count2>=4 or (count2>=1 and count3>=2):
                print('YES')

        elif mod==2:
            if (count2>=2 and count3>=2) or (count2>=5 and count3>=1):
                print('YES')

        elif mod==3:
            if (count3>=1) or (count2>=3):
                print('YES')

        elif mod==4:
            if (count2>=4 and count3>=1) or (count2>=1 and count3>=2):
                print('YES')

        elif mod==5:
            if (count2>=2):
                print('YES')

        elif mod==6:
            if (count2>=6) or (count2>=3 and count3>=1) or (count3>=2):
                print('YES')

        elif mod==7:
            if (count2>=1):
                print('YES')

        elif mod==8:
            if (count2>=5) or (count2>=2 and count3>=1):
                print('YES')

Submission (verdict: Wrong answer on test 2):
for t in range(int(input())):
    s = input()
    sm = 0
    for i in s:
        sm += int(i)

    mod = sm%9

    if mod==0:
        print('YES')
    
    else:
        count2 = 0
        count3 = 0
        for char in s:
            if char=='2':
                count2 += 1
            elif char=='3':
                count3 += 1

        if mod==1:
            if count2>=4 or (count2>=1 and count3>=2):
                print('YES')
            else:
                print('NO')

        elif mod==2:
            if (count2>=2 and count3>=2) or (count2>=5 and count3>=1):
                print('YES')
            else:
                print("NO")

        elif mod==3:
            if (count3>=1) or (count2>=3):
                print('YES')
            else:
                print("NO")

        elif mod==4:
            if (count2>=4 and count3>=1) or (count2>=1 and count3>=2):
                print('YES')
            else:
                print("NO")

        elif mod==5:
            if (count2>=2):
                print('YES')
            else:
                print("NO")

        elif mod==6:
            if (count2>=6) or (count2>=3 and count3>=1) or (count3>=2):
                print('YES')
            else:
                print("NO")

        elif mod==7:
            if (count2>=1):
                print('YES')
            else:
                print("NO")

        elif mod==8:
            if (count2>=5) or (count2>=2 and count3>=1):
                print('YES')
            else:
                print("NO")
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;

        vector<unordered_set<int>> adj(n + 1);
        for (int i = 0; i < n - 1; i++)
        {
            int first, second;
            cin >> first >> second;
            adj[first].insert(second);
            adj[second].insert(first);
        }
        int maxi = 0, index = 0;

        for (int i = 1; i <= n; i++)
        {
            int key = i;
            unordered_set<int> &neighbors = adj[i];
            if (neighbors.size() > maxi)
            {
                maxi = neighbors.size();
                index = key;
            }
        }
        unordered_set<int> &byebye = adj[index];
        // cout << index << endl;
        for (auto a : byebye)
        {
            int currele = a;
            adj[currele].erase(index);
        }
        byebye.clear();
        byebye.insert(-1);

        maxi = -1, index = 0;

        for (int i = 1; i <= n; i++)
        {
            int key = i;
            unordered_set<int> &neighbors = adj[i];
            if (neighbors.count(-1))
            {
                // cout << i << endl;
                continue;
            }

            if ((int)neighbors.size() > maxi)
            {

                maxi = neighbors.size();
                index = i;
            }
        }

        unordered_set<int> &byebye2 = adj[index];
        // cout << index << endl;
        for (auto a : byebye2)
        {
            int currele = a;
            adj[currele].erase(index);
        }
        byebye2.clear();
        byebye2.insert(-1);
        int res = 0;
        unordered_set<int> selected;
        for (int i = 1; i <= n; i++)
        {
            unordered_set<int> &neighbors = adj[i];
            if (neighbors.count(-1) || selected.count(i))
                continue;
            selected.insert(i);
            for (auto a : neighbors)
            {
                selected.insert(a);
            }
            res++;
        }
        cout << res << endl;
    }
    return 0;
}