#include <bits/stdc++.h>
#include <array>
#include <string>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
const int MOD = 1e9 + 7;

int n, x, k;
int a[200007];
signed main()
{
    IOS
    //int t; cin >> t; while (t--)
    {
        cin >> n >> x >> k;
        int total = 0;
        for (int i = 0; i < n; ++i) cin >> a[i];
        for (int i = 0; i < n - k; ++i) {
            sort(a + i, a + k);
            if (a[i + k - 1] <= x) {
                ++total;
            }
        }
        cout << total << "\n";
    }
    return 0;
}


// Prison Transfer - 427B codeforces.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
int main()
{
	int n, Ntransfer, severity;

	cin >> n >> severity >> Ntransfer;

	vector<int> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int ans = 0;
	int c = 0;
	for (int i = 0; i < n; i++) {
		if (arr[i] <= severity)
			c++;
		else
		{
			if(c > Ntransfer)
				ans += c -( Ntransfer - 1);
			c = 0;
		}
	}
	if(c!=0)
		ans += c - (Ntransfer - 1);

	cout << ans;
}


// Prison Transfer - 427B codeforces.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
int main()
{
	int n, Ntransfer, severity;

	cin >> n >> severity >> Ntransfer;

	vector<int> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int ans = 0;
	int c = 0;
	for (int i = 0; i < n; i++) {
		if (arr[i] <= severity)
			c++;
		else
		{
			if(c >= Ntransfer)
				ans += c -( Ntransfer - 1);
			c = 0;
		}
	}
	if(c!=0)
		if (c >= Ntransfer)
			ans += c - (Ntransfer - 1);

	cout << ans;
}


// Prison Transfer - 427B codeforces.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
int main()
{
	int n, Ntransfer, severity;

	cin >> n >> severity >> Ntransfer;

	int i = 0, j = 0;

	vector<int> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];

	int c = 0 ,count = 0;
	bool flag = true;
	for (int i = 0; i < n - Ntransfer+1; i++) {
		flag = true;
		while (j < n && c < Ntransfer) {

			if (arr[j] > severity) {
				i = j + 1;
				flag = false;
				break;
			}
			c++;
			j++;
		}
		c = 0;
		j = i;
		if (flag)
			count++;
	}
	cout << count;
}


// Prison Transfer - 427B codeforces.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
int main()
{
	int n, Ntransfer, severity;

	cin >> n >> severity >> Ntransfer;

	vector<int> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int ans = 0;
	int c = 0;
	for (int i = 0; i < n; i++) {
		if (arr[i] <= severity)
			c++;
		else
		{
			ans += c -( Ntransfer - 1);
			c = 0;
		}
	}
	if(c!=0)
		ans += c - (Ntransfer - 1);

	cout << ans;
}


// Prison Transfer - 427B codeforces.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
int main()
{
	int n, Ntransfer, severity;

	cin >> n >> severity >> Ntransfer;

	vector<int> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int ans = 0;
	int c = 0;
	for (int i = 0; i < n; i++) {
		if (arr[i] <= severity)
			c++;
		else
		{
			if(c >= Ntransfer)
				ans += c -( Ntransfer - 1);
			c = 0;
		}
	}
	if(c!=0)
		ans += c - (Ntransfer - 1);

	cout << ans;
}


#include<bits/stdc++.h>
#define S second
#define F first
using namespace std;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,t,c,ans=0;
	cin>>n>>t>>c;
	int a[n+1];
	int cnt[n+1]= {0};
	for(int i = 1;i <= n;i++){
		cin>>a[i];
		if(a[i] <= t){
			cnt[i] = cnt[i-1] + 1;
		}
	}
	for(int i = c;i <= n;i++){
		if(cnt[i] >= c) ans++;
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define S second
#define F first
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,t,c,x,f=1,ans=0;
	cin>>n>>t>>c;
	deque<int> a;
	for(int i = 0;i < n;i++){
		cin>>x;
		a.push_back(x);
	}
	while(a.size() >= c){
		for(int i = 0;i < c;i++){
			if(a[i] > t){
				f=0;
				break;
			}
		}
		if(f) ans++;
		f=1;
		a.pop_front();
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define S second
#define F first
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,t,c;
	cin>>n>>t>>c;
	int a[n];
	for(int i = 0;i < n;i++){
		cin>>a[i];
	}
	int l = 0,r = c,f=1,ans=0;
	while(r <= n){
		for(int i = l;i < r;i++){
			if(a[i] > t){
				f = 0;
				break;
			}
		}
		if(f) ans++;
		f=1;
		l++;
		r++;
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,t,c,ans=0;
	cin>>n>>t>>c;
	int a[n];
	int cnt[n+1];
	for(int i = 1;i < n;i++){
		cin>>a[i];
		if(a[i] <= t){
			cnt[i] = cnt[i-1] + 1;
		}
		else{
			cnt[i] = 0;
		}
	}
	for(int i = c;i <= n;i++){
		if(cnt[i] >= c) ans++;
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define f first
#define pb push_back
#define WrongAnswer 0
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define bye exit(0)
#define cheetah ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef tree <ll ,null_type,less <ll> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int N = (int)(1e5) + 15, maxn = 1e5 + 55, mod = 1e9 + 7;

ll n, t[N * 4],c  , q , a[N] , cnt = 0;

vector <pll> ans;

void build(ll a[],ll v , ll tl , ll tr){
   if(tr - tl == 1){
     t[v] = a[tl];
     return;
   }
   else{
     int tm = (tl + tr) / 2;
     build(a,v * 2 + 1, tl , tm );
     build(a,v * 2 + 2 , tm , tr);
     t[v] = max(t[v * 2 + 1] , t[v * 2 + 2]);
   }
}

ll get(ll v , ll tl , ll tr , ll l , ll r){
   if(l >= tr || tl >= r){
     return -1e9;
   }
   if(l <= tl && tr <= r){
     return t[v];
   }
   ll tm = (tl + tr) / 2;
   return max(get(v * 2 + 1, tl , tm, l , r), get(v * 2 + 2, tm, tr, l , r));
}
signed main(){
   cheetah;
   cin >> n >> q >> c;
   for(int i = 0 ;i < n ; ++i){
      cin >> a[i];
   }
   build(a, 0 , 0 , n );
   for(ll i = 0; i < n - c + 1 ; ++i){
      if(get(0 , 0 , n , i , i + c ) <= q){
	    ++cnt;
      }
   }
   cout << cnt;
   return false;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define f first
#define pb push_back
#define WrongAnswer 0
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define bye exit(0)
#define cheetah ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef tree <ll ,null_type,less <ll> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int N = (int)(1e5) + 15, maxn = 1e5 + 55, mod = 1e9 + 7;

ll n, t[N * 4],c  , q , a[N] , cnt = 0;

vector <pll> ans;

void build(ll a[],ll v , ll tl , ll tr){
   if(tr - tl == 1){
     t[v] = a[tl];
     return;
   }
   else{
     int tm = (tl + tr) / 2;
     build(a,v * 2 , tl , tm );
     build(a,v * 2 + 1 , tm , tr);
     t[v] = max(t[v * 2] , t[v * 2 + 1]);
   }
}

ll get(ll v , ll tl , ll tr , ll l , ll r){
   if(l >= tr || tl >= r){
     return -1e9;
   }
   if(l <= tl && tr <= r){
     return t[v];
   }
   ll tm = (tl + tr) / 2;
   return max(get(v * 2, tl , tm, l , r), get(v * 2 + 1, tm, tr, l , r));
}
signed main(){
   cheetah;
   cin >> n >> q >> c;
   for(int i = 0 ;i < n ; ++i){
      cin >> a[i];
   }
   build(a, 0 , 0 , n );
   for(ll i = 0; i < n - c + 1 ; ++i){
      if(get(0 , 0 , n , i , i + c - 1) <= q){
	    ++cnt;
      }
   }
   cout << cnt;
   return false;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define f first
#define pb push_back
#define WrongAnswer 0
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define bye exit(0)
#define cheetah ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef tree <ll ,null_type,less <ll> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int N = (int)(1e6) + 15, maxn = 1e5 + 55, mod = 1e9 + 7;

ll n, t[N * 4],c  , q , a[N] , cnt = 0;

vector <pll> ans;

void build(ll a[],ll v , ll tl , ll tr){
   if(tr - tl == 1){
     t[v] = a[tl];
     return;
   }
   else{
     int tm = (tl + tr) / 2;
     build(a,v * 2 + 1, tl , tm );
     build(a,v * 2 + 2 , tm , tr);
     t[v] = max(t[v * 2 + 1] , t[v * 2 + 2]);
   }
}

ll get(ll v , ll tl , ll tr , ll l , ll r){
   if(l >= tr || tl >= r){
     return -1e9;
   }
   if(l <= tl && tr <= r){
     return t[v];
   }
   ll tm = (tl + tr) / 2;
   return max(get(v * 2 + 1, tl , tm, l , r), get(v * 2 + 2, tm, tr, l , r));
}
signed main(){
   cheetah;
   cin >> n >> q >> c;
   for(int i = 0 ;i < n ; ++i){
      cin >> a[i];
   }
   build(a, 0 , 0 , n );
   for(ll i = 0; i < n - c + 1 ; ++i){
      if(get(0 , 0 , n , i , i + c ) <= q){
	    ++cnt;
      }
   }
   cout << cnt;
   return false;
}


// 15.11.19 , 9:01
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define f first
#define pb push_back
#define WrongAnswer 0
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define bye exit(0)
#define sz() size()

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef tree <ll ,null_type,less <ll> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int N = (int)(1e6) + 15, inf = 1e9, mod = 1e9 + 7;

ll n , ans ,t ,c ,a[N] ,cnt = 0;

signed main(){
   scanf("%lld%lld%lld" , &n , &t , &c);
   for(int i = 1; i <= n ; ++i)
      scanf("%lld", &a[i]);
   for(int i = 1 ;i <= n ; ++i){
      if(t >= a[i])
        ++cnt;
      else
        ans += max(cnt - c + 1 , 0ll),cnt = 0;
   }
   ans += max(cnt - c + 1 , 0ll);
   printf("%d" , ans);
   return false;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define f first
#define pb push_back
#define WrongAnswer 0
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define bye exit(0)
#define cheetah ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef tree <ll ,null_type,less <ll> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int N = (int)(1e5) + 15, maxn = 1e5 + 55, mod = 1e9 + 7;

ll n, t[N * 4],c  , q , a[N] , cnt = 0;

vector <pll> ans;

void build(ll v , ll tl , ll tr){
   if(tr - tl == 1){
     t[v] = a[tl];
     return;
   }
   else{
     int tm = (tl + tr) / 2;
     build(v * 2 , tl , tm );
     build(v * 2 + 1 , tm + 1 , tr);
     t[v] = max(t[v * 2] , t[v * 2 + 1]);
   }
}
ll get(ll v , ll tl , ll tr , ll l , ll r){
   if(l >= tl || tl >= r){
     return -1e9;
   }
   if(l <= tl && tr <= r){
     return t[v];
   }
   ll tm = (tl + tr) / 2;
   return max(get(v * 2, tl , tm, l , r), get(v * 2 + 1, tm + 1 , tr, l , r));
}
signed main(){
   cheetah;
   cin >> n >> q >> c;
   for(int i = 1 ;i <= n ; ++i){
      cin >> a[i];
   }
   build(1 , 1 , n);
   for(ll i = 1; i <= n - c + 1 ; ++i){
      if(get(1 , 1 , n , i , i + c) <= q){
	++cnt;
      }
   }
   cout << cnt;
   return false;
}


#include<bits/stdc++.h>
using namespace std;
#define tr(container,it)\
for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
typedef long long ll;
int main(){
    ll n,t,c; cin>>n>>t>>c;
    vector<ll> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    ll p1=0,p2=0,count=0; bool nolarge=true;
    for(int i=0;i<n;i++){
        if(v[i]>t){
            p1=p2;
            p2=i;
            if(i>0&&p2-p1-c+1>0) count+=(p2-p1-c+1);
            nolarge=false;
        }
    }
    if(nolarge) cout<<(n-c+1)<<"\n";
    else cout<<count<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define tr(container,it)\
for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
typedef long long ll;
int main(){
    ll n,t,c; cin>>n>>t>>c;
    vector<ll> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    ll p1=0,p2=0,count=0; bool nolarge=true;
    for(int i=1;i<=n;i++){
        if(v[i-1]>t){
            p1=p2;
            p2=i;
            if(i>0&&p2-p1-c>0) count+=(p2-p1-c);
            // if(i>0&&p2-p1-c+1>0) count+=(p2-p1-c+1);
            nolarge=false;
        }
    }
    if(p2<n&&n-p2-c+1>0) count+=(n-p2-c+1);
    if(nolarge) cout<<(n-c+1)<<"\n";
    else cout<<count<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define tr(container,it)\
for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
typedef long long ll;
int main(){
    ll n,t,c; cin>>n>>t>>c;
    vector<ll> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    ll p1=-1,p2=0,count=0; bool nolarge=true;
    for(int i=0;i<n;i++){
        if(v[i]>t){
            p1=p2;
            p2=i;
            if(i>0&&p2-p1-c>0) count+=(p2-p1-c);
            // if(i>0&&p2-p1-c+1>0) count+=(p2-p1-c+1);
            nolarge=false;
        }
    }
    if(p2<n-1&&n-p2-c+1>0) count+=(n-p2-c+1);
    if(nolarge) cout<<(n-c+1)<<"\n";
    else cout<<count<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define tr(container,it)\
for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
typedef long long ll;
int main(){
    ll n,t,c; cin>>n>>t>>c;
    vector<ll> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    ll p1=0,p2=0,count=0; bool nolarge=true;
    for(int i=0;i<n;i++){
        if(v[i]>t){
            p1=p2;
            p2=i;
            if(i>0) count+=(p2-p1-c+1);
            nolarge=false;
        }
    }
    if(nolarge) cout<<(n-c+1)<<"\n";
    else cout<<count<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,c,t,d=0;
	cin>>n>>t>>c;
	int a[n];
	bool b[n-c+1];
	for(int i=0;i<=n-c;i++){
		b[i]=true;
	}
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<=n-c;i++){
		if(a[i]>t){
			for(int j=0;j<c;j++){
				b[i-j]=false;
			}
		}
	}
	for(int i=n-c+1;i<n;i++){
		if(a[i]>t){
			b[n-c]=false;
			break;
		}
	}
	for(int i=0;i<=n-c;i++){
		if(b[i]==true){
			d++;
		}
	}
	cout<<d;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,c,t,d=0;
	cin>>n>>t>>c;
	int a[n];
	bool b[n+1];
	for(int i=0;i<=n-c;i++){
		b[i]=true;
	}
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<=n-c;i++){
		if(a[i]>t&&b[i]==true){
			for(int j=0;j<c;j++){
				b[i-j]=false;
				b[i+j]=false;
			}
		}
	}
	for(int i=n-c+1;i<n;i++){
		if(a[i]>t){
			b[n-c]=false;
			break;
		}
	}
	for(int i=0;i<=n-c;i++){
		if(b[i]==true){
			d++;
		}
	}
	for(int i=0;i<=n-c;i++){
		cout<<b[i]<<" ";
	}
	cout<<d;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,c,t,d=0;
	cin>>n>>t>>c;
	int a[n];
	bool b[n+1];
	for(int i=0;i<=n-c;i++){
		b[i]=true;
	}
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<=n-c;i++){
		if(a[i]>t&&b[i]==true){
			for(int j=0;j<c;j++){
				b[i-j]=false;
				b[i+j]=false;
			}
		}
	}
	for(int i=n-c+1;i<n;i++){
		if(a[i]>t){
			b[n-c]=false;
			break;
		}
	}
	for(int i=0;i<=n-c;i++){
		if(b[i]==true){
			d++;
		}
	}
	cout<<d;
	return 0;
}


#include <stdio.h>
#include <map>
#include <algorithm>
inline int F() { register int aa , bb , ch;
	while(ch = getchar() , (ch<'0'||ch>'9') && ch != '-'); ch == '-' ? aa=bb=0 : (aa=ch-'0',bb=1);
	while(ch = getchar() , ch>='0'&&ch<='9') aa = aa*10 + ch-'0'; return bb ? aa : -aa;
}
const int Maxn = 200005;
const int Maxm = 2*Maxn;
int n , rt = 0 , ans = 0 , sans = 0 , sum = 0 , fa[Maxn] , size[Maxn] , f[Maxn] , Ha[Maxn] , H[Maxn] , len = 0 , a[Maxn] , sz = 1;
int to[Maxm] , next[Maxm] , g[Maxn] , ecnt = 0;
inline void ins(const int&a , const int&b) {
	to[++ecnt] = b; next[ecnt] = g[a]; g[a] = ecnt;
	to[++ecnt] = a; next[ecnt] = g[b]; g[b] = ecnt;
}
#define R register
std::map<int,int> c[Maxn];
int insert() {
	int now = 1;
	for(R int i=1; i<=len; ++i) {
		if(!c[now][a[i]]) c[now][a[i]] = ++sz;
		now = c[now][a[i]];
	} return now;
}
inline void modify(const int&x , const int&val) {
	if(H[x]) --sum;
	H[x] += val;
	if(H[x]) ++sum;
}
void getrt(int x) {
	size[x] = 1;
	for(R int i=g[x]; i; i=next[i]) {
		if(to[i] == fa[x]) continue;
		fa[to[i]] = x;
		getrt(to[i]);
		size[x] += size[to[i]];
		if(size[to[i]] > f[x]) f[x] = size[to[i]];
	}
	if(n-size[x] > f[x]) f[x] = n-size[x];
	if(f[rt] > f[x]) rt = x;
}
void dfs(int x) {
	for(R int i=g[x]; i; i=next[i]) {
		if(to[i] == fa[x]) continue;
		fa[to[i]] = x; dfs(to[i]);
	}
	len = 0;
	for(R int i=g[x]; i; i=next[i]) {
		if(to[i] == fa[x]) continue;
		a[++len] = Ha[to[i]];
	} a[++len] = 1;
	std::sort(a+1,a+len+1);
	Ha[x] = insert();
	if(x != rt) modify(Ha[x],1);
}
void getans(int x , int d) {
	if(sum+d >= sans) sans = sum+d , ans = x;
	for(R int i=g[x]; i; i=next[i]) {
		if(to[i] == fa[x]) continue;
		modify(Ha[x],-1);
		getans(to[i],d+1);
		modify(Ha[x],1);
	}
}
int main() {
	n = F();
	for(R int i=1 , a , b; i<n; ++i) {
		a = F() , b = F();
		ins(a,b);
	}
	f[0] = n; getrt(1);
	fa[rt] = 0; dfs(rt);
	getans(rt,0);
	printf("%d\n",ans);
}


//   Author:Arturia
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<string>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#include<bitset>
#include<vector>
#define rep(x,a,b) for (int x=a;x<=(int)b;x++)
#define drp(x,a,b) for (int x=a;x>=(int)b;x--)
#define cross(x,a) for (int x=hd[a];~x;x=nx[x])
#define ll long long
#define inf (1<<29)
#define PII pair<int,int>
#define PDD pair<double,double>
#define mk(a,b) make_pair(a,b)
#define fs first
#define sc second
#define pb push_back
#define VI vector<int>
#define VS vector<string>
#define MC(a,b) memcpy(a,b,sizeof b)
#define MS(a,b) memset(a,b,sizeof a)
using namespace std;
inline ll rd(){
	ll x=0;int ch=getchar(),f=1;
	while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();
	if (ch=='-'){f=-1;ch=getchar();}
	while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
inline void rt(ll x){
	if (x<0) putchar('-'),x=-x;
	if (x>=10) rt(x/10),putchar(x%10+'0');
		else putchar(x+'0');
}
#define mod 1000000007
#define mod2 1000007
const int maxn=100005;
int to[maxn<<1],nx[maxn<<1],hd[maxn],cnt;
void addedge(int u,int v){
	to[cnt]=v;nx[cnt]=hd[u];hd[u]=cnt++;
}
int HD[mod2],val[maxn<<1],NX[maxn<<1],num[maxn<<1],CNT;
int n,hs[maxn];
#define CROSS(i,u) for (int i=HD[u];~i;i=NX[i])
int nv=0;
void add(int x){
	int u=x%mod2;
	CROSS(i,u){
		int v=val[i];
		if (v==x){num[i]++;if (num[i]==1) nv++;return;}
	}
	val[CNT]=x;num[CNT]=1;NX[CNT]=HD[u];HD[u]=CNT++;nv++;
}
void del(int x){
	int u=x%mod2;
	CROSS(i,u){
		int v=val[i];
		if (v==x){num[i]--;if (!num[i]) nv--;return;}
	}
}
int ans=0,mx=0;
void dfs(int u,int fa){
	hs[u]=1;
	cross(i,u){
		int v=to[i];
		if (v==fa) continue;
		dfs(v,u);
		hs[u]=(3ll*hs[v]*hs[v]*hs[v]+hs[u])%mod;
	}
	add(hs[u]);
}
void findans(int u,int fa){
	if (nv>mx) mx=nv,ans=u;
	cross(i,u){
		int v=to[i];
		if (v==fa) continue;
		int t1=hs[u],t2=hs[v];
		del(hs[u]),del(hs[v]);
		hs[u]=(hs[u]+mod-3ll*hs[v]*hs[v]*hs[v]%mod)%mod;
		hs[v]=(hs[v]+3ll*hs[u]*hs[u]*hs[u])%mod;
		add(hs[u]),add(hs[v]);
		findans(v,u);
		del(hs[u]),del(hs[v]);
		hs[u]=t1,hs[v]=t2;
		add(hs[u]),add(hs[v]);
	}
}
int main(){
	n=rd();
	memset(hd,-1,sizeof hd);
	rep(i,1,n-1){
		int u=rd(),v=rd();
		addedge(u,v),addedge(v,u);
	}
	memset(HD,-1,sizeof HD);
	dfs(1,0);
	findans(1,0);
	rt(ans);
}


//   Author:Arturia
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<string>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#include<bitset>
#include<vector>
#define rep(x,a,b) for (int x=a;x<=(int)b;x++)
#define drp(x,a,b) for (int x=a;x>=(int)b;x--)
#define cross(x,a) for (int x=hd[a];~x;x=nx[x])
#define ll long long
#define inf (1<<29)
#define PII pair<int,int>
#define PDD pair<double,double>
#define mk(a,b) make_pair(a,b)
#define fs first
#define sc second
#define pb push_back
#define VI vector<int>
#define VS vector<string>
#define MC(a,b) memcpy(a,b,sizeof b)
#define MS(a,b) memset(a,b,sizeof a)
using namespace std;
inline ll rd(){
	ll x=0;int ch=getchar(),f=1;
	while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();
	if (ch=='-'){f=-1;ch=getchar();}
	while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
inline void rt(ll x){
	if (x<0) putchar('-'),x=-x;
	if (x>=10) rt(x/10),putchar(x%10+'0');
		else putchar(x+'0');
}
#define mod 1000000007
#define mod2 1000007
const int maxn=100005;
int to[maxn<<1],nx[maxn<<1],hd[maxn],cnt;
void addedge(int u,int v){
	to[cnt]=v;nx[cnt]=hd[u];hd[u]=cnt++;
}
int HD[mod2],val[maxn<<1],NX[maxn<<1],num[maxn<<1],CNT;
int n,hs[maxn];
#define CROSS(i,u) for (int i=HD[u];~i;i=NX[i])
int nv=0;
void add(int x){
	int u=x%mod2;
	CROSS(i,u){
		int v=val[i];
		if (v==x){num[i]++;if (num[i]==1) nv++;return;}
	}
	val[CNT]=x;num[CNT]=1;NX[CNT]=HD[u];HD[u]=CNT++;nv++;
}
void del(int x){
	int u=x%mod2;
	CROSS(i,u){
		int v=val[i];
		if (v==x){num[i]--;if (!num[i]) nv--;return;}
	}
}
int ans=0,mx=0;
void dfs(int u,int fa){
	hs[u]=1;
	cross(i,u){
		int v=to[i];
		if (v==fa) continue;
		dfs(v,u);
		hs[u]=(hs[u]+3ll*hs[v]*hs[v]%mod*hs[v])%mod;
	}
	add(hs[u]);
}
void findans(int u,int fa){
	if (nv>mx) mx=nv,ans=u;
	cross(i,u){
		int v=to[i];
		if (v==fa) continue;
		int t1=hs[u],t2=hs[v];
		del(hs[u]),del(hs[v]);
		hs[u]=(hs[u]+mod-3ll*hs[v]*hs[v]%mod*hs[v]%mod)%mod;
		hs[v]=(hs[v]+3ll*hs[u]*hs[u]%mod*hs[u])%mod;
		add(hs[u]),add(hs[v]);
		findans(v,u);
		del(hs[u]),del(hs[v]);
		hs[u]=t1,hs[v]=t2;
		add(hs[u]),add(hs[v]);
	}
}
int main(){
	n=rd();
	memset(hd,-1,sizeof hd);
	rep(i,1,n-1){
		int u=rd(),v=rd();
		addedge(u,v),addedge(v,u);
	}
	memset(HD,-1,sizeof HD);
	dfs(1,0);
	findans(1,0);
	rt(ans);
}


#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int getint(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
#define N 112345
int head[N],etot;
struct edge{
	int to,next;
}e[N<<1];
void insert(int x,int y){
	e[++etot].to=y; e[etot].next=head[x]; head[x]=etot;
	e[++etot].to=x; e[etot].next=head[y]; head[y]=etot;
}
ull f[N],h[N];
int fa[N];
ull hash(ull x){
	return x*x*x*x*ull("Orz_st_nec!!!")+x*x*x*ull("asdasdasdasdfwe")+x*x*ull("Rp+++++")+x*ull("heartstonebuchucheng")+ull("ShiTianShou and QiaoGe!!!!!!");
}
void dfs(int x){
	for(int i=head[x];i;i=e[i].next){
		int y=e[i].to;
		if(y!=fa[x]){
			fa[y]=x; dfs(y); f[x]+=f[y];
		}
	}
	f[x]=hash(f[x]);
//	cout<<x<<" "<<f[x]<<endl;
	return ;
}
void dfs2(int x){
	ull sum=h[x];
//	cout<<x<<" "<<h[x]<<endl;
	for(int i=head[x];i;i=e[i].next) {
		int y=e[i].to;
		if(y!=fa[x]){ sum+=f[y]; }
	}
	for(int i=head[x];i;i=e[i].next){
		int y=e[i].to;
		if(y!=fa[x]){
			h[y]=hash(sum-f[y]);
			dfs2(y);
		}
	}
}
map<ull,int> mp;
int cnt=0;
int ans,ansi;
void add(ull x){ if(mp[x]==0) cnt++; mp[x]++; }
void del(ull x){ if(mp[x]==1) cnt--; mp[x]--; }
void dfs3(int x){
	if(cnt>ans) ansi=x,ans=cnt;
	for(int i=head[x];i;i=e[i].next) {
		int y=e[i].to;
		if(y!=fa[x]){
			del(f[y]); add(h[y]);
			dfs3(y);
			add(f[y]); del(h[y]);
		}
	}
	return ;
}
int main(){
	int n=getint();
	for(int i=1;i<n;i++) {
		insert(getint(),getint());
	}
	dfs(1); dfs2(1);
	for(int i=2;i<=n;i++) add(f[i]);
	ans=-1;
	dfs3(1);
	cout<<ansi<<endl;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define N 100010
#define k 1000003
#define ull unsigned long long
using namespace std;

struct edge{int x, y, next;}a[N*2];
struct bb{int id, size; ull x;}b[N];
int n, p[N], l, x, y, size[N], s1[N], ans, mx, mxp;
ull hash[N][2], s[N], bin[N];
map<ull, ull>mp;

bool cmp(bb a, bb b){return a.x<b.x;}

void add(int x, int y){a[++l].x=x; a[l].y=y; a[l].next=p[x]; p[x]=l;}

void dfs1(int x, int fa){
	size[x]=1;
	for(int i=p[x]; i; i=a[i].next)if(fa!=a[i].y){dfs1(a[i].y, x); size[x]+=size[a[i].y];}
	int l=0, sum=size[x]-1;
	for(int i=p[x]; i; i=a[i].next)if(fa!=a[i].y){b[++l].x=hash[a[i].y][0]; b[l].id=a[i].y;}
	sort(b+1, b+1+l, cmp);
	hash[x][0]=l*bin[sum];
	for(int i=1; i<=l; i++){
		sum-=size[b[i].id];
		hash[x][0]+=b[i].x*bin[sum];
	}
}

void dfs2(int x, int fa){
	int l=0, sum=n-1;
	for(int i=p[x]; i; i=a[i].next)
		if(fa!=a[i].y){b[++l].x=hash[a[i].y][0]; b[l].id=a[i].y; b[l].size=size[a[i].y];}
		else if(a[i].y){b[++l].x=hash[x][1]; b[l].id=fa; b[l].size=n-size[x];}
	sort(b+1, b+1+l, cmp);
	s[0]=s1[0]=0;
	for(int i=1; i<=l; i++)s[i]=s[i-1]*bin[b[i].size]+b[i].x;
	for(int i=1; i<=l; i++)s1[i]=s1[i-1]+b[i].size;
	for(int i=1; i<=l; i++){
		sum-=b[i].size; if(fa==b[i].id)continue;
		hash[b[i].id][1]=(l-1)*bin[n-1-b[i].size];
		hash[b[i].id][1]+=s[i-1]*bin[sum]+(s[l]-s[i]*bin[s1[l]-s1[i]]);
	}
	for(int i=p[x]; i; i=a[i].next)if(fa!=a[i].y)dfs2(a[i].y, x);
}

void dfs(int x, int fa){
	int ans1=ans;
	for(int i=p[x]; i; i=a[i].next)if(fa!=a[i].y){
		mp[hash[a[i].y][0]]--; if(!mp[hash[a[i].y][0]])ans--;
		mp[hash[a[i].y][1]]++; if(mp[hash[a[i].y][1]]==1)ans++;
		if(mx<ans){mx=ans; mxp=a[i].y;}
		dfs(a[i].y, x);
		mp[hash[a[i].y][0]]++; mp[hash[a[i].y][1]]--; ans=ans1;
	}
}

int main(){
	scanf("%d", &n);
	bin[0]=1; for(int i=1; i<=n; i++)bin[i]=bin[i-1]*k;
	l=0; memset(p, 0, sizeof(p));
	for(int i=1; i<=n-1; i++){
		scanf("%d%d", &x, &y); add(x, y); add(y, x);
	}
	dfs1(1, 0);
	dfs2(1, 0);
	mp.clear();
	ans=0;
	for(int i=1; i<=n; i++){
		mp[hash[i][0]]++;
		if(mp[hash[i][0]]==1)ans++;
	}
	mx=ans; mxp=1;
	dfs(1, 0);
	printf("%d", mxp);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int hash = 13,MOD = 1e9+7,maxn = 1e5+5;
#define LL long long

inline int read(){
	int x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	while(ch <= '9' && ch >= '0') x = x*10+ch-'0',ch = getchar();
	return x;
}

int hed[maxn],to[maxn<<1],nxt[maxn<<1];
int ret[maxn],HS[maxn],sz[maxn],Pow[maxn];
vector<int>G[maxn]; int N,cnt,Rt,ans,sum;
map<int , int> S;

void Addedge(int x,int y){
	nxt[++cnt] = hed[x]; to[cnt] = y; hed[x] = cnt;
	nxt[++cnt] = hed[y]; to[cnt] = x; hed[y] = cnt;
}

int Centriod(int x,int p){
	int tmp = 0,res = 0,mx = 0; sz[x] = 1;
	for(int i = hed[x],v; i ; i = nxt[i])
		if((v = to[i]) != p){
			tmp = Centriod(v , x);
			if(tmp) res = tmp;
			sz[x] += sz[v];
			mx = max(mx , sz[v]);
		}
	if(max(mx,N-sz[x]) <= N/2) res = x;
	return res;
}

bool cmp(int x,int y){return HS[x] < HS[y];}

void Insert(int x){
	int k = S[x];
	if(!k) ++sum;
	S[x]++;
}

void Modify(int x){
	int k = S[x];
	if(k == 1) --sum;
	S[x]--;
}

void DFS(int x,int p){
	sz[x] = 1;
	for(int i = hed[x],v ; i ; i = nxt[i])
		if((v = to[i]) != p){
			G[x].push_back(v);
			DFS(v , x); sz[x] += sz[v];
		}
	sort(G[x].begin(), G[x].end(),cmp);
	HS[x] = 1;
	for(int i = 0 ; i < G[x].size() ; ++i)
		HS[x] = ((LL)HS[x]*Pow[sz[G[x][i]]] + HS[G[x][i]]) % MOD;
	HS[x] = ((LL)HS[x]*hash + 2)%MOD;
	Insert(HS[x]);
}

void Solve(int x,int p){
	Modify(HS[x]); sum++; ret[x] = sum;
	for(int i = hed[x] ; i  ; i = nxt[i])
		if(to[i] != p) Solve(to[i],x);
	Insert(HS[x]); sum--;
}

int main(){
	N = read(); Pow[0] = 1;
	for(int i = 1 ; i <= N ; ++i) Pow[i] = (LL)Pow[i-1]*hash%MOD;
	for(int i = 1 ; i < N ; ++i)
		Addedge(read(),read());
	Rt = Centriod(1 , 0); DFS(Rt , 0);
	Solve(Rt,0);
	for(int i = 1 ; i <= N ; ++i)
		if(ret[i] > ret[ans]) ans = i;
	return printf("%d\n",ans),0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1000*100+10;
const int MOD = 1000*1000*1000+7;
const int POD = 983;

vector <int> Graf[N];
long long SubtreeHash[N];
long long Pot[N];
int Size[N];
map <long long,int> Rozne;

int diff;
pair <int,int> result;

void Wczytaj(int &n){
	int i,v,u;
	scanf("%d", &n);
	for(i=0; i<n-1; i++){
		scanf("%d%d", &v,&u);
		Graf[v].push_back(u);
		Graf[u].push_back(v);
	}
	Pot[0] = 1;
	for(i=1; i<N; i++) Pot[i] = (Pot[i-1]*POD)%MOD;
}

long long DFSInicjuj(int v,int ojciec){
	int i,suma;
	long long aktualny_hasz;
	vector < pair < long long, pair <int,int> > > Hasze;
	Size[v] = 1;
	Hasze.push_back( make_pair( (long long)'(', make_pair(1,-1) ) );
	for(i=0; i<Graf[v].size(); i++){
		if( Graf[v][i] != ojciec ) {
			SubtreeHash[ Graf[v][i] ] = DFSInicjuj(Graf[v][i],v);
			Hasze.push_back( make_pair( SubtreeHash[ Graf[v][i] ], make_pair( 2*Size[ Graf[v][i] ],Graf[v][i] ) ) );
			Size[v] += Size[ Graf[v][i] ];
		}
	}
	Hasze.push_back( make_pair( (long long)')', make_pair(1,-1) ) );
	sort( Hasze.begin()+1, Hasze.end()-1 );
	aktualny_hasz = 0;
	suma = 0;
	for(i=0; i<Hasze.size(); i++){
		aktualny_hasz = (aktualny_hasz+Pot[suma]*Hasze[i].first)%MOD;
		suma += Hasze[i].second.first;
	}
	return aktualny_hasz;
}

void Update(int v,long long nowy,long long stary){
	Rozne[stary]--;
	if(Rozne[stary] == 0) diff--;
	Rozne[nowy]++;
	if(Rozne[nowy] == 1) diff++;
	//printf("%d %d\n", diff,v);
	result = max(result, make_pair(diff,v));
}

void DFSPopraw(int v,int ojciec,long long upper_hash,int n){
	int i,suma;
	long long aktualny_hasz,new_upper;
	vector <int> Suma_Pref;
	vector < long long > DiffHasze,Hasze_Pref;
	vector < pair < long long, pair <int,int> > > Hasze;
	Hasze.push_back( make_pair( (long long)'(', make_pair(1,-1) ) );
	for(i=0; i<Graf[v].size(); i++){
		if( Graf[v][i] != ojciec ){
			Hasze.push_back( make_pair( SubtreeHash[ Graf[v][i] ], make_pair( 2*Size[ Graf[v][i] ],Graf[v][i] ) ) );
			DiffHasze.push_back( SubtreeHash[ Graf[v][i] ] );
		}
	}
	if(upper_hash != -1) {
		DiffHasze.push_back(upper_hash);
		Hasze.push_back( make_pair( upper_hash, make_pair( 2*(n-Size[v]), ojciec ) ) );
	}
	Hasze.push_back( make_pair( (long long)')', make_pair(1,-1) ) );
	sort( Hasze.begin()+1, Hasze.end()-1 );
	Hasze_Pref.push_back(0); Suma_Pref.push_back(0); suma = 0;
	//printf("%d\n", v);
	for(i=0; i<Hasze.size(); i++){
		//printf("%lld : %d %d |", Hasze[i].first,Hasze[i].second.first,Hasze[i].second.second);
		Hasze_Pref.push_back( (Hasze_Pref.back()+Pot[suma]*Hasze[i].first)%MOD );
		suma += Hasze[i].second.first;
		Suma_Pref.push_back(suma);
	}
	//printf("\n");
	aktualny_hasz = Hasze.back().first;
	//printf("%d\n", v);
	for(i=Hasze.size()-2; i>=1; i--){
		new_upper = (Hasze_Pref[i]+Pot[ Suma_Pref[i] ]*aktualny_hasz)%MOD;
		if( Hasze[i].second.second != ojciec ) {
			Update( Hasze[i].second.second,new_upper, SubtreeHash[ Hasze[i].second.second ] );
			DFSPopraw( Hasze[i].second.second,v,new_upper,n );
			Update( v,SubtreeHash[ Hasze[i].second.second ],new_upper );
		}
		aktualny_hasz = (aktualny_hasz*Pot[ Hasze[i].second.first ]+Hasze[i].first)%MOD;
	}

}

int main(){
	int n,i;
	Wczytaj(n);
	SubtreeHash[1] = DFSInicjuj(1,1);
	for(i=2; i<=n; i++){
		Rozne[ SubtreeHash[i] ]++;
		if(Rozne[ SubtreeHash[i] ] == 1) diff++;
	}
	result = make_pair(diff,1);
	DFSPopraw(1,1,-1,n);
	printf("%d\n", result.second);
	return 0;
}


#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>

const int modulo[2] = {1000000007,1000000009};

int n;
int base;
int edges[100010],to[200020],next[200020];
std::map<std::pair<int,int>,int> map;
std::vector<int> children[100010];
int total[200020];
int id[100010];
int power[100010][2];
int prefix[200020][2],suffix[200020][2];
int tail;
int answer,maximum,current;

void edge_add(int u,int v)
{
    static int count = 1;

    to[count] = v;
    next[count] = edges[u];
    edges[u] = count++;
}

bool compare(int x,int y)
{
    return id[x] < id[y];
}

inline int get_id(const std::pair<int,int> &pair)
{
    static int count = 2;
    int id;

    if(map[pair])
        id = map[pair];
    else
        id = map[pair] = count++;

    return id;
}

inline void increase(int x)
{
    ++total[x];
    if(total[x] > 1)
        --current;
}

inline void decrease(int x)
{
    --total[x];
    if(total[x] >= 1)
        ++current;
}

void work(int x,int y)
{
    int e;
    int i;
    int p,q;
    std::pair<int,int> pair;

    for(e = edges[x];e;e = next[e])
    {
        if(to[e] == y)
            continue;
        work(to[e],x);
        children[x].push_back(to[e]);
    }

    if(x == 1)
        return;

    if(children[x].size() == 0){
        id[x] = 1;
        increase(id[x]);
        return;
    }

    std::sort(children[x].begin(),children[x].end(),compare);

    p = q = 0;
    for(i = 0;i < children[x].size();++i)
    {
        p = (1ll * p * base + id[children[x][i]]) % modulo[0];
        q = (1ll * q * base + id[children[x][i]]) % modulo[1];
    }

    pair.first = p;
    pair.second = q;

    id[x] = get_id(pair);

    increase(id[x]);
}

void solve(int x,int y)
{
    int i,z;
    int p,q,w;
    int begin = tail;
    std::pair<int,int> pair;

    //printf("%d %d\n",x,current);

    if(current > maximum)
        maximum = current,answer = x;

    if(!children[x].size())
        return;

    if(y)
        children[x].push_back(y);
    std::sort(children[x].begin(),children[x].end(),compare);

    prefix[begin + 0][0] = prefix[begin + 0][1] = id[children[x][0]];
    suffix[begin + children[x].size() - 1][0] = suffix[begin + children[x].size() - 1][1] = id[children[x][children[x].size() - 1]];
    for(i = 1;i < children[x].size();++i)
        prefix[begin + i][0] = (1ll * prefix[begin + i - 1][0] * base + id[children[x][i]]) % modulo[0],
        prefix[begin + i][1] = (1ll * prefix[begin + i - 1][1] * base + id[children[x][i]]) % modulo[1];
    for(i = children[x].size() - 2;i >= 0;--i)
        suffix[begin + i][0] = (suffix[begin + i + 1][0] + 1ll * power[children[x].size() - i - 1][0] * id[children[x][i]]) % modulo[0],
        suffix[begin + i][1] = (suffix[begin + i + 1][1] + 1ll * power[children[x].size() - i - 1][1] * id[children[x][i]]) % modulo[1];

    tail += children[x].size();

    z = id[x];
    for(i = 0;i < children[x].size();++i)
    {
        if(children[x][i] == y && (w = i,true))
            continue;
        decrease(id[children[x][i]]);

        p = q = 0;
        if(i)
            p += 1ll * prefix[begin + i - 1][0] * power[children[x].size() - i - 1][0] % modulo[0],
            q += 1ll * prefix[begin + i - 1][1] * power[children[x].size() - i - 1][1] % modulo[1];
        if(i != children[x].size() - 1)
            (p += suffix[begin + i + 1][0]) % modulo[0],(q += suffix[begin + i + 1][1]) % modulo[1];
        if(children[x].size() != 1)
            pair.first = p,pair.second = q,id[x] = get_id(pair),increase(id[x]);
        else
            id[x] = 1,increase(id[x]);

        solve(children[x][i],x);

        decrease(id[x]);
        id[x] = z;

        increase(id[children[x][i]]);
    }

    if(y)
        std::swap(children[x][w],children[x][children[x].size() - 1]),children[x].pop_back();
}

int main(void)
{
    int i;
    int u,v;

    //freopen("x.in","r",stdin);

    scanf("%d",&n);
    base = 3 + (n << 1);

    for(i = 1;i < n;++i)
        scanf("%d %d",&u,&v),edge_add(u,v),edge_add(v,u);

    power[0][0] = power[0][1] = 1;
    for(i = 1;i <= n;++i)
        power[i][0] = 1ll * power[i - 1][0] * base % modulo[0],power[i][1] = 1ll * power[i - 1][1] * base % modulo[1];

    answer = 1;
    current = n;
    work(1,0);
    maximum = current;
    solve(1,0);

    printf("%d\n",answer);

    return 0;
}


#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>

const int modulo[2] = {1000000007,1000000009};

int n;
int base;
int edges[100010],to[200020],next[200020];
std::map<std::pair<int,int>,int> map;
std::vector<int> children[100010];
int total[200020];
int id[100010];
int power[100010][2];
int prefix[200020][2],suffix[200020][2];
int tail;
int answer,maximum,current;

void edge_add(int u,int v)
{
    static int count = 1;

    to[count] = v;
    next[count] = edges[u];
    edges[u] = count++;
}

bool compare(int x,int y)
{
    return id[x] < id[y];
}

inline int get_id(const std::pair<int,int> &pair)
{
    static int count = 2;
    int id;

    if(map[pair])
        id = map[pair];
    else
        id = map[pair] = count++;

    return id;
}

inline void increase(int x)
{
    ++total[x];
    if(total[x] == 2)
        current -= 2;
    else if(total[x] != 1)
        --current;
}

inline void decrease(int x)
{
    --total[x];
    if(total[x] == 1)
        current += 2;
    else if(total[x] != 0)
        ++current;
}

void work(int x,int y)
{
    int e;
    int i;
    int p,q;
    std::pair<int,int> pair;

    for(e = edges[x];e;e = next[e])
    {
        if(to[e] == y)
            continue;
        work(to[e],x);
        children[x].push_back(to[e]);
    }

    if(x == 1)
        return;

    if(children[x].size() == 0){
        id[x] = 1;
        increase(id[x]);
        return;
    }

    std::sort(children[x].begin(),children[x].end(),compare);

    p = q = 0;
    for(i = 0;i < children[x].size();++i)
    {
        p = (1ll * p * base + id[children[x][i]]) % modulo[0];
        q = (1ll * q * base + id[children[x][i]]) % modulo[1];
    }

    pair.first = p;
    pair.second = q;

    id[x] = get_id(pair);

    increase(id[x]);
}

void solve(int x,int y)
{
    int i,z;
    int p,q,w;
    int begin = tail;
    std::pair<int,int> pair;

    //printf("%d %d\n",x,current);

    if(current > maximum)
        maximum = current,answer = x;

    if(!children[x].size())
        return;

    if(y)
        children[x].push_back(y);
    std::sort(children[x].begin(),children[x].end(),compare);

    prefix[begin + 0][0] = prefix[begin + 0][1] = id[children[x][0]];
    suffix[begin + children[x].size() - 1][0] = suffix[begin + children[x].size() - 1][1] = id[children[x][children[x].size() - 1]];
    for(i = 1;i < children[x].size();++i)
        prefix[begin + i][0] = (1ll * prefix[begin + i - 1][0] * base + id[children[x][i]]) % modulo[0],
        prefix[begin + i][1] = (1ll * prefix[begin + i - 1][1] * base + id[children[x][i]]) % modulo[1];
    for(i = children[x].size() - 2;i >= 0;--i)
        suffix[begin + i][0] = (suffix[begin + i + 1][0] + 1ll * power[children[x].size() - i - 1][0] * id[children[x][i]]) % modulo[0],
        suffix[begin + i][1] = (suffix[begin + i + 1][1] + 1ll * power[children[x].size() - i - 1][1] * id[children[x][i]]) % modulo[1];

    tail += children[x].size();

    z = id[x];
    for(i = 0;i < children[x].size();++i)
    {
        if(children[x][i] == y && (w = i,true))
            continue;
        decrease(id[children[x][i]]);

        p = q = 0;
        if(i)
            p += 1ll * prefix[begin + i - 1][0] * power[children[x].size() - i - 1][0] % modulo[0],
            q += 1ll * prefix[begin + i - 1][1] * power[children[x].size() - i - 1][1] % modulo[1];
        if(i != children[x].size() - 1)
            (p += suffix[begin + i + 1][0]) % modulo[0],(q += suffix[begin + i + 1][1]) % modulo[1];
        if(children[x].size() != 1)
            pair.first = p,pair.second = q,id[x] = get_id(pair),increase(id[x]);
        else
            id[x] = 1,increase(id[x]);

        solve(children[x][i],x);

        decrease(id[x]);
        id[x] = z;

        increase(id[children[x][i]]);
    }

    if(y)
        std::swap(children[x][w],children[x][children[x].size() - 1]),children[x].pop_back();
}

int main(void)
{
    int i;
    int u,v;

    //freopen("x.in","r",stdin);

    scanf("%d",&n);
    base = 3 + (n << 1);

    for(i = 1;i < n;++i)
        scanf("%d %d",&u,&v),edge_add(u,v),edge_add(v,u);

    power[0][0] = power[0][1] = 1;
    for(i = 1;i <= n;++i)
        power[i][0] = 1ll * power[i - 1][0] * base % modulo[0],power[i][1] = 1ll * power[i - 1][1] * base % modulo[1];

    answer = 1;
    current = n;
    work(1,0);
    maximum = current;
    solve(1,0);

    printf("%d\n",answer);

    return 0;
}


#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=100005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T> inline void read(T &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
template<class T> inline void print(T x){
	if(!x){puts("0");return;}
	if(x<0){putchar('-');x=-x;}
	int a[20],m=0;
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');puts("");
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

struct node{int to,next;}p[N<<1];
int n,tot,res,ans,id,root,head[N],si[N];
bool vis[N],tag[N];
ull dp[N];
map<ull,int> cnt;
void add(int x,int y){
	p[++tot]=(node){y,head[x]};head[x]=tot;
	p[++tot]=(node){x,head[y]};head[y]=tot;
}
void getroot(int x,int fa){
	si[x]=1;
	int tmp=0;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(y==fa) continue;
		getroot(y,x);
		si[x]+=si[y];gmax(tmp,si[y]);
	}
	gmax(tmp,n-si[x]);
	if(tmp<res) res=tmp,root=x;
}
void dfs(int x){
	si[x]=vis[x]=dp[x]=1;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(vis[y]) continue;
		dfs(y);
		dp[x]=dp[x]*dp[y];
		si[x]+=si[y];
	}
	dp[x]+=(ll)si[x]*si[x]*si[x]%mod;
	cnt[dp[x]]++;
}
void dfs(int x,int now){
	vis[x]=1;now+=tag[x];
	if(mp(now,-x)>mp(ans,-id)) ans=now,id=x;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(vis[y]) continue;
		dfs(y,now);
	}
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
	srand(time(0));
#endif
	ios::sync_with_stdio(0);
	read(n);
	for(int i=1;i<n;i++){
		int x,y;read(x);read(y);
		add(x,y);
	}
	res=n;
	getroot(1,0);
	dfs(root);
	for(int i=1;i<=n;i++)
		if(cnt[dp[i]]>1) tag[i]=1;
	clr(vis,0);
	ans=-1;dfs(root,0);
	printf("%d\n",id);
#ifdef rqgao2014
	time_tester(1);
#endif
	return 0;
}


#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=100005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T> inline void read(T &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
template<class T> inline void print(T x){
	if(!x){puts("0");return;}
	if(x<0){putchar('-');x=-x;}
	int a[20],m=0;
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');puts("");
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

struct node{int to,next;}p[N<<1];
int n,tot,res,ans,id,root,head[N],si[N];
bool vis[N],tag[N];
ull dp[N];
map<ull,int> cnt;
void add(int x,int y){
	p[++tot]=(node){y,head[x]};head[x]=tot;
	p[++tot]=(node){x,head[y]};head[y]=tot;
}
void getroot(int x,int fa){
	si[x]=1;
	int tmp=0;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(y==fa) continue;
		getroot(y,x);
		si[x]+=si[y];gmax(tmp,si[y]);
	}
	gmax(tmp,n-si[x]);
	if(tmp<res) res=tmp,root=x;
}
void dfs(int x){
	si[x]=vis[x]=dp[x]=1;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(vis[y]) continue;
		dfs(y);
		dp[x]=dp[x]*dp[y];
		si[x]+=si[y];
	}
	dp[x]-=si[x]*571943359871019ll;
	dp[x]^=(ll)si[x]*si[x]*si[x]*si[x];
	cnt[dp[x]]++;
}
void dfs(int x,int now){
	vis[x]=1;now+=tag[x];
	if(mp(now,-x)>mp(ans,-id)) ans=now,id=x;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(vis[y]) continue;
		dfs(y,now);
	}
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
	srand(time(0));
#endif
	ios::sync_with_stdio(0);
	read(n);
	for(int i=1;i<n;i++){
		int x,y;read(x);read(y);
		add(x,y);
	}
	res=n;
	getroot(1,0);
	dfs(root);
	for(int i=1;i<=n;i++)
		if(cnt[dp[i]]>1) tag[i]=1;
	clr(vis,0);
	ans=-1;dfs(root,0);
	printf("%d\n",id);
#ifdef rqgao2014
	time_tester(1);
#endif
	return 0;
}


#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=100005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T> inline void read(T &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
template<class T> inline void print(T x){
	if(!x){puts("0");return;}
	if(x<0){putchar('-');x=-x;}
	int a[20],m=0;
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');puts("");
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

struct node{int to,next;}p[N<<1];
int n,tot,res,ans,id,root,head[N],si[N];
bool vis[N],tag[N];
ull dp[N];
map<ull,int> cnt;
void add(int x,int y){
	p[++tot]=(node){y,head[x]};head[x]=tot;
	p[++tot]=(node){x,head[y]};head[y]=tot;
}
void getroot(int x,int fa){
	si[x]=1;
	int tmp=0;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(y==fa) continue;
		getroot(y,x);
		si[x]+=si[y];gmax(tmp,si[y]);
	}
	gmax(tmp,n-si[x]);
	if(tmp<res) res=tmp,root=x;
}
void dfs(int x){
	si[x]=vis[x]=dp[x]=1;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(vis[y]) continue;
		dfs(y);
		dp[x]=dp[x]*dp[y];
		si[x]+=si[y];
	}
	dp[x]-=si[x]*12057194353019ll;
	dp[x]^=(ll)si[x]*si[x]*si[x]*si[x];
	cnt[dp[x]]++;
}
void dfs(int x,int now){
	vis[x]=1;now+=tag[x];
	if(mp(now,-x)>mp(ans,-id)) ans=now,id=x;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(vis[y]) continue;
		dfs(y,now);
	}
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
	srand(time(0));
#endif
	ios::sync_with_stdio(0);
	read(n);
	for(int i=1;i<n;i++){
		int x,y;read(x);read(y);
		add(x,y);
	}
	res=n;
	getroot(1,0);
	dfs(root);
	for(int i=1;i<=n;i++)
		if(cnt[dp[i]]>1) tag[i]=1;
	clr(vis,0);
	ans=-1;dfs(root,0);
	printf("%d\n",id);
#ifdef rqgao2014
	time_tester(1);
#endif
	return 0;
}


#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=100005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T> inline void read(T &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
template<class T> inline void print(T x){
	if(!x){puts("0");return;}
	if(x<0){putchar('-');x=-x;}
	int a[20],m=0;
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');puts("");
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

struct node{int to,next;}p[N<<1];
int n,tot,res,ans,id,root,head[N],si[N];
bool vis[N],tag[N];
ull dp[N];
map<ull,int> cnt;
void add(int x,int y){
	p[++tot]=(node){y,head[x]};head[x]=tot;
	p[++tot]=(node){x,head[y]};head[y]=tot;
}
void getroot(int x,int fa){
	si[x]=1;
	int tmp=0;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(y==fa) continue;
		getroot(y,x);
		si[x]+=si[y];gmax(tmp,si[y]);
	}
	gmax(tmp,n-si[x]);
	if(tmp<res) res=tmp,root=x;
}
void dfs(int x){
	si[x]=vis[x]=dp[x]=1;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(vis[y]) continue;
		dfs(y);
		dp[x]=dp[x]*dp[y];
		si[x]+=si[y];
	}
	dp[x]+=(ll)si[x]*si[x]*si[x]%mod;
	cnt[dp[x]]++;
}
void dfs(int x,int now){
	vis[x]=1;now+=tag[x];
	if(mp(now,-x)>mp(ans,-id)) ans=now,id=x;
	for(int i=head[x];i;i=p[i].next){
		int y=p[i].to;
		if(vis[y]) continue;
		dfs(y,now);
	}
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
	srand(time(0));
#endif
	ios::sync_with_stdio(0);
	read(n);
	for(int i=1;i<n;i++){
		int x,y;read(x);read(y);
		add(x,y);
	}
	res=n;
	getroot(1,0);
	dfs(root);
	for(int i=1;i<=n;i++)
		if(cnt[dp[i]]>1) tag[i]=1;
	clr(vis,0);dfs(root,0);
	printf("%d\n",id);
#ifdef rqgao2014
	time_tester(1);
#endif
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define prt(x) cerr<<#x<<":"<<(x)<<endl
#define ep(...) fprintf(stderr,__VA_ARGS__)
typedef long long LL;
typedef unsigned long long ull;
const int maxn=100005;
int n;
int C[maxn<<1],Pre;
ull H[maxn<<1];
int ecnt,pt[maxn<<1],nt[maxn<<1],hd[maxn];
ull wt[maxn<<1];
void ins(int u,int v){ pt[++ecnt]=v;nt[ecnt]=hd[u];hd[u]=ecnt; }
ull Sol(int x,int f)
{
	int i,tot;
	vector<ull>hs;
	for(i=hd[x];i;i=nt[i])if(pt[i]!=f)
	{
		if(!wt[i])wt[i]=Sol(pt[i],x);
		hs.push_back(wt[i]);
	}
	tot=hs.size();
	sort(hs.begin(),hs.end());
	ull tmp=20170217;
	for(i=0;i<tot;i++)tmp=(tmp*55555+hs[i])^233333333;
	return tmp;
}
void dfs0(int x,int f)
{
	int i;
	for(i=hd[x];i;i=nt[i])
	if(pt[i]!=f)
	{
		if((C[wt[i]]++)==0)Pre++;
		dfs0(pt[i],x);
	}
}
int Ans,Rt;
void dfs1(int x,int f)
{
	int i;
	if(Pre>Ans)Ans=Pre,Rt=x;
	for(i=hd[x];i;i=nt[i])if(pt[i]!=f)
	{
		if((--C[wt[i]])==0)Pre--;
		if((C[wt[i^1]]++)==0)Pre++;
		dfs1(pt[i],x);
		if((C[wt[i]]++)==0)Pre++;
		if((--C[wt[i^1]])==0)Pre--;
	}
}
int main()
{
	int i,u,v,tot;
	scanf("%d",&n);
	for(ecnt=i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		ins(u,v);ins(v,u);
	}
	for(i=1;i<=n;i++)Sol(i,0);
	for(i=1;i<=ecnt;++i)H[i]=wt[i];
	sort(H+1,H+ecnt+1);
	tot=unique(H+1,H+ecnt+1)-H-1;
	for(i=1;i<=ecnt;i++)wt[i]=lower_bound(H+1,H+tot+1,wt[i])-H;
	dfs0(1,0);
	dfs1(1,0);
	printf("%d\n",Rt);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define prt(x) cerr<<#x<<":"<<(x)<<endl
#define ep(...) fprintf(stderr,__VA_ARGS__)
typedef long long LL;
typedef unsigned long long ull;
const int maxn=100005;
int n,sz[maxn],G,Gs;
int C[maxn<<1],Pre;
ull H[maxn<<1];
int ecnt,pt[maxn<<1],nt[maxn<<1],hd[maxn];
ull wt[maxn<<1];
void ins(int u,int v){ pt[++ecnt]=v;nt[ecnt]=hd[u];hd[u]=ecnt; }
void Max(int &x,int y){  if(x<y)x=y; }
void Dfs(int x,int f)
{
	int i,mx=0;sz[x]=1;
	for(i=hd[x];i;i=nt[i])if(pt[i]!=f)
	{
		Dfs(pt[i],x);
		Max(mx,sz[pt[i]]);
		sz[x]+=sz[pt[i]];
	}
	Max(mx,n-sz[x]);
	if(!G||mx<Gs)Gs=mx,G=x;
}
ull Sol(int x,int f)
{
	int i,tot;
	vector<ull>hs;
	for(i=hd[x];i;i=nt[i])if(pt[i]!=f)
	{
		if(!wt[i])wt[i]=Sol(pt[i],x);
		hs.push_back(wt[i]);
	}
	tot=hs.size();
	sort(hs.begin(),hs.end());
	ull tmp=20170217;
	for(i=0;i<tot;i++)tmp=(tmp*55555+hs[i])^233333333;
	return tmp;
}
void dfs0(int x,int f)
{
	int i;
	for(i=hd[x];i;i=nt[i])
	if(pt[i]!=f)
	{
		if((C[wt[i]]++)==0)Pre++;
		dfs0(pt[i],x);
	}
}
int Ans,Rt;
void dfs1(int x,int f)
{
	int i;
	if(Pre>Ans)Ans=Pre,Rt=x;
	for(i=hd[x];i;i=nt[i])if(pt[i]!=f)
	{
		++Pre;
		if((--C[wt[i]])==0)Pre--;
		dfs1(pt[i],x);
		--Pre;
		if((C[wt[i]]++)==0)Pre++;
	}
}
int main()
{
	int i,u,v,tot=0;
	scanf("%d",&n);
	for(ecnt=i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		ins(u,v);ins(v,u);
	}
	Dfs(1,0);
	Sol(G,0);
	for(i=1;i<=ecnt;++i)if(wt[i])H[++tot]=wt[i];
	sort(H+1,H+tot+1);
	tot=unique(H+1,H+ecnt+1)-H-1;
	for(i=1;i<=ecnt;i++)if(wt[i])wt[i]=lower_bound(H+1,H+tot+1,wt[i])-H;
	dfs0(G,0);
	Ans=-1;
	dfs1(G,0);
	printf("%d\n",Rt);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define prt(x) cerr<<#x<<":"<<(x)<<endl
#define ep(...) fprintf(stderr,__VA_ARGS__)
typedef long long LL;
typedef unsigned long long ull;
const int maxn=100005;
int n;
int C[maxn<<1],Pre;
ull H[maxn<<1];
int ecnt,pt[maxn<<1],nt[maxn<<1],hd[maxn];
ull wt[maxn<<1];
void ins(int u,int v){ pt[++ecnt]=v;nt[ecnt]=hd[u];hd[u]=ecnt; }
ull Sol(int x,int f)
{
	int i,tot;
	vector<ull>hs;
	for(i=hd[x];i;i=nt[i])if(pt[i]!=f)
	{
		if(!wt[i])wt[i]=Sol(pt[i],x);
		hs.push_back(wt[i]);
	}
	tot=hs.size();
	sort(hs.begin(),hs.end());
	ull tmp=20170217;
	for(i=0;i<tot;i++)tmp=(tmp*55555+hs[i])^233333333;
	return tmp;
}
void dfs0(int x,int f)
{
	int i;
	for(i=hd[x];i;i=nt[i])
	if(pt[i]!=f)
	{
		if((C[wt[i]]++)==0)Pre++;
		dfs0(pt[i],x);
	}
}
int Ans,Rt;
void dfs1(int x,int f)
{
	int i;
	if(Pre>Ans)Ans=Pre,Rt=x;
	for(i=hd[x];i;i=nt[i])if(pt[i]!=f)
	{
		if((--C[wt[i]])==0)Pre--;
		if((C[wt[i^1]]++)==0)Pre++;
		dfs1(pt[i],x);
		if((C[wt[i]]++)==0)Pre++;
		if((--C[wt[i^1]])==0)Pre--;
	}
}
int main()
{
	int i,u,v,tot;
	scanf("%d",&n);
	for(ecnt=i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		ins(u,v);ins(v,u);
	}
	for(i=1;i<=n;i++)Sol(i,0);
	for(i=1;i<=ecnt;++i)H[i]=wt[i];
	sort(H+1,H+ecnt+1);
	tot=unique(H+1,H+ecnt+1)-H-1;
	for(i=1;i<=ecnt;i++)wt[i]=lower_bound(H+1,H+tot+1,wt[i])-H;
	dfs0(1,0);
	Ans=-1;
	dfs1(1,0);
	printf("%d\n",Rt);
	return 0;
}


//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define pb	push_back
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define	n	200005

int		N, D, st[n], F[n];

int		GT, siz[n], Max[n];

int		tot, A[n];

int		Sum, Rt, Ans, H[n];

struct	Lin{
		int v, next;
}E[n];

void	Link(int u, int v)	{
		E[++ D]= (Lin){v, st[u]};	st[u]= D;
		E[++ D]= (Lin){u, st[v]};	st[v]= D;
}

namespace	Trie{
	int		C= 1;

	map<int, int>	trans[n];

	int		Get(){
		int x= 1;
		For(i, 1, tot)	{
			if	(! trans[x].count(A[i]))	trans[x][A[i]]= ++C;
			x= trans[x][A[i]];
		}
		return	x;
	}
};

void	Modify(int x, int v)	{
		if	(H[x])	Sum--;
		H[x]+= v;
		if	(H[x])	Sum++;
}

void	DFS1(int u, int f)	{
		siz[u]= 1;
		for (int i= st[u], v; i; i= E[i].next)
			if	((v= E[i].v) != f)	{
				DFS1(v, u);
				siz[u]+= siz[v];
				Max[u]= max(Max[u], siz[v]);
			}
		Max[u]= max(Max[u], N - siz[u]);

		if	(! GT || Max[u] < Max[GT])	GT= u;
}

void	DFS(int u, int f)	{
		for (int i= st[u], v; i; i= E[i].next)
			if	((v= E[i].v) != f)	DFS(v, u);

		tot= 0;
		for (int i= st[u], v; i; i= E[i].next)
			if	((v= E[i].v) != f)	A[++ tot]= F[v];
		A[++ tot]= 1;

		sort(A+1, A+tot+1);
		F[u]= Trie::Get();

		if	(u != GT)	Modify(F[u], 1);
}

void	Find(int u, int f, int d)	{
		if	(Sum + d >= Ans)	Ans= Sum + d, Rt= u;

		for (int i= st[u], v; i; i= E[i].next)
			if	((v= E[i].v) != f)	{
				Modify(F[v], -1);
				Find(v, u, d+1);
				Modify(F[v], 1);
			}
}

int		main(int argc, char* argv[]){
		N= IN();
		For(i, 2, N)	Link(IN(), IN());

		DFS1(1, 0);

		DFS(GT, 0);
		Find(GT, 0, 0);

		printf("%d\n", Rt);

		return	0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
typedef unsigned long long ull;
const int N = 1e5+5;
map<ull,ull>hmp;
ull Rand()
{
	return ((1ull*rand())<<40)|((1ull*rand())<<20)|rand();
}
ull getid(ull x)
{
	if(hmp.find(x)==hmp.end())return hmp[x]=Rand();
	else return hmp[x];
}
ull hash[N],rhash[N];
struct E
{
	int next,to;
}e[N<<1];
int head[N],tot,n;
void add(int x,int y)
{
	e[++tot].to = y;e[tot].next = head[x];head[x] = tot;
	e[++tot].to = x;e[tot].next = head[y];head[y] = tot;
}
void dfs(int x,int fa=-1)
{
	for(int i = head[x];i;i=e[i].next)
		if(e[i].to!=fa)
		{
			dfs(e[i].to,x);
			hash[x]+=hash[e[i].to];
		}
	hash[x] = getid(hash[x]);
}
void rdfs(int x,int fa=-1)
{
	ull sum= 0;
	if(x!=1)sum+=rhash[x];
	for(int i=head[x];i;i=e[i].next)
		if(e[i].to!=fa)
			sum+=hash[e[i].to];
	for(int i = head[x];i;i=e[i].next)
		if(e[i].to!=fa)
		{
			rhash[e[i].to] = getid(sum-hash[e[i].to]);
			rdfs(e[i].to,x);
		}
}
map<ull,int>mp;
int cur,ans,ansid = 1;
void Add(ull x){cur+=((mp[x]++)==0);}
void Del(ull x){cur-=((--mp[x])==0);}
void solve(int x,int fa=-1)
{
	if(cur>ans)ans = cur,ansid = x;
	for(int i = head[x];i;i=e[i].next)
		if(fa!=e[i].to)
		{
			Del(hash[e[i].to]);
			Add(rhash[e[i].to]);
			solve(e[i].to,x);
			Del(rhash[e[i].to]);
			Add(hash[e[i].to]);
		}
}
int main()
{
	srand(2037);
	hmp[0]=Rand();
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
	}
	dfs(1);
	rdfs(1);
	for(int i=2;i<=n;i++)Add(hash[i]);
	solve(1);
	printf("%d\n",ansid);
	return 0;
}


#include<cstdio>
#include<map>
using namespace std;
typedef long long ll;
const int N=100100,P=1000000007,Q=23333;
int i,j,k,n,m,En,ch,x,y,cnt,ma,ans;
int h[N],hs[N];
struct edge { int s,n;} E[N<<1];
map<int,int> Map;
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
void E_add(int x,int y) {
	E[++En].s=y;E[En].n=h[x];h[x]=En;
	E[++En].s=x;E[En].n=h[y];h[y]=En;
}
int calc(int x) {
	return (ll) x*x%P*x%P;
}
void dfs(int x,int F) {
	hs[x]=Q;
	for (int k=h[x];k;k=E[k].n) if (E[k].s!=F) {
		dfs(E[k].s,x);
		hs[x]=(hs[x]+calc(hs[E[k].s]))%P;
	}
	if (x!=1) {
		if (!Map[hs[x]]) cnt++;
		Map[hs[x]]++;
	}
}
void dfs(int x,int F,int Hs) {
	if (Map[hs[x]]==1) cnt--;
	Map[hs[x]]--;
	if (!Map[Hs]) cnt++;
	Map[Hs]++;
	int tmp=(hs[x]+calc(Hs))%P;
	if (cnt>ma) ma=cnt,ans=x;
	for (int k=h[x];k;k=E[k].n) if (E[k].s!=F) dfs(E[k].s,x,(tmp+P-calc(hs[E[k].s]))%P);
	if (!Map[hs[x]]) cnt++;
	Map[hs[x]]++;
	if (Map[Hs]==1) cnt--;
	Map[Hs]--;
}
int main() {
	R(n);
	for (i=1;i<n;i++) {
		R(x);R(y);
		E_add(x,y);
	}
	dfs(1,0);
	ans=1;ma=cnt;
	for (k=h[1];k;k=E[k].n) dfs(E[k].s,1,(hs[1]+P-calc(hs[E[k].s]))%P);
	printf("%d\n",ans);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long LL;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
#define ull unsigned long long
const int N=100005;
int n,pos,ans,tot;
ull hash[N],val[N<<1];
map<ull,int> M;
map<ull,ull> hh;
vector<int> v[N];
inline ull find(ull a){
	if(hh.find(a)==hh.end())return hh[a]=val[++tot];
	else return hh[a];
}
inline void dfs(int p,int fa){
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa){
		dfs(v[p][i],p);
	}
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa)hash[p]+=find(hash[v[p][i]]);
	M[hash[p]]++; //cout<<p<<" "<<hash[p]<<endl;
}
inline void change(ull a,ull b){
	if(--M[a]==0)M.erase(a);
	M[b]++;
}
inline void ddd(int p,int fa){
	if(fa){
		change(hash[fa],hash[fa]-find(hash[p]));
		hash[fa]-=find(hash[p]);
		change(hash[p],hash[p]+find(hash[fa]));
		hash[p]+=find(hash[fa]);
	}
	if(M.size()>ans){
		pos=p; ans=M.size();
	}
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa){
		ddd(v[p][i],p);
	}
	if(fa){
		hash[p]-=find(hash[fa]);
		change(hash[p]+find(hash[fa]),hash[p]);
		hash[fa]+=find(hash[p]);
		change(hash[fa]-find(hash[p]),hash[fa]);
	}
}
int main(){
	n=read();
	for(int i=1;i<=2*n;i++)val[i]=(1+rand())*23333LL+(rand()*7ll+129873123LL)+((rand()+1243)<<30);
	for(int i=1;i<n;i++){
		int s=read(),t=read();
		v[s].push_back(t); v[t].push_back(s);
	}
	dfs(1,0);
	ddd(1,0);
	writeln(pos);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long LL;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
#define ull unsigned long long
const int N=100005;
int n,pos,ans;
ull hash[N];
map<ull,int> M;
vector<int> v[N];
inline ull find(ull a){
	return (a<<7)+13;
}
inline void dfs(int p,int fa){
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa){
		dfs(v[p][i],p);
	}
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa)hash[p]+=find(hash[v[p][i]]);
	M[hash[p]]++; //cout<<p<<" "<<hash[p]<<endl;
}
inline void change(ull a,ull b){
	if(--M[a]==0)M.erase(a);
	M[b]++;
}
inline void ddd(int p,int fa){
	if(fa){
		change(hash[fa],hash[fa]-find(hash[p]));
		hash[fa]-=find(hash[p]);
		change(hash[p],hash[p]+find(hash[fa]));
		hash[p]+=find(hash[fa]);
	}
	//cout<<M.size()<<" "<<p<<endl;
	if(M.size()>ans){
		pos=p; ans=M.size();
	}
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa){
		ddd(v[p][i],p);
	}
	if(fa){
		hash[p]-=find(hash[fa]);
		change(hash[p]+find(hash[fa]),hash[p]);
		hash[fa]+=find(hash[p]);
		change(hash[fa]-find(hash[p]),hash[fa]);
	}
}
int main(){
	n=read();
	for(int i=1;i<n;i++){
		int s=read(),t=read();
		v[s].push_back(t); v[t].push_back(s);
	}
	dfs(1,0);
	ddd(1,0);
	writeln(pos);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long LL;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
#define ull unsigned long long
const int N=100005;
int n,pos,ans;
ull hash[N];
map<ull,int> M;
vector<int> v[N];
inline ull find(ull a){
	return (a<<7)+13;
}
inline void dfs(int p,int fa){
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa){
		dfs(v[p][i],p);
	}
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa)hash[p]+=find(hash[v[p][i]]);
	M[hash[p]]++; //cout<<p<<" "<<hash[p]<<endl;
}
inline void change(ull a,ull b){
	if(--M[a]==0)M.erase(a);
	M[b]++;
}
inline void ddd(int p,int fa){
	if(fa){
		change(hash[fa],hash[fa]-find(hash[p]));
		hash[fa]-=find(hash[p]);
		change(hash[p],hash[p]+find(hash[fa]));
		hash[p]+=find(hash[fa]);
	}
	if(p==27258)writeln(M.size());
	if(M.size()>ans){
		pos=p; ans=M.size();
	}
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa){
		ddd(v[p][i],p);
	}
	if(fa){
		hash[p]-=find(hash[fa]);
		change(hash[p]+find(hash[fa]),hash[p]);
		hash[fa]+=find(hash[p]);
		change(hash[fa]-find(hash[p]),hash[fa]);
	}
}
int main(){
	n=read();
	for(int i=1;i<n;i++){
		int s=read(),t=read();
		v[s].push_back(t); v[t].push_back(s);
	}
	dfs(1,0);
	ddd(1,0);
	writeln(pos);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long LL;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
#define ull unsigned long long
const int N=100005;
int n,pos,ans;
ull hash[N];
map<ull,int> M;
vector<int> v[N];
inline ull find(ull a){
	return (a<<7)+233;
}
inline void dfs(int p,int fa){
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa){
		dfs(v[p][i],p);
	}
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa)hash[p]+=find(hash[v[p][i]]);
	M[hash[p]]++; //cout<<p<<" "<<hash[p]<<endl;
}
inline void change(ull a,ull b){
	if(--M[a]==0)M.erase(a);
	M[b]++;
}
inline void ddd(int p,int fa){
	if(fa){
		change(hash[fa],hash[fa]-find(hash[p]));
		hash[fa]-=find(hash[p]);
		change(hash[p],hash[p]+find(hash[fa]));
		hash[p]+=find(hash[fa]);
	}
	if(M.size()>ans){
		pos=p; ans=M.size();
	}
	for(int i=0;i<v[p].size();i++)if(v[p][i]!=fa){
		ddd(v[p][i],p);
	}
	if(fa){
		hash[p]-=find(hash[fa]);
		change(hash[p]+find(hash[fa]),hash[p]);
		hash[fa]+=find(hash[p]);
		change(hash[fa]-find(hash[p]),hash[fa]);
	}
}
int main(){
	n=read();
	for(int i=1;i<n;i++){
		int s=read(),t=read();
		v[s].push_back(t); v[t].push_back(s);
	}
	dfs(1,0);
	ddd(1,0);
	writeln(pos);
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#include<set>
#define LL unsigned long long
using namespace std;
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int N=200005;
const int B=19433;
int n,sz[N];
struct e{int num,next;}map[N];
int head[N],len;
inline void link(int x,int y)
{
  len++;map[len].num=y;map[len].next=head[x];head[x]=len;
  len++;map[len].num=x;map[len].next=head[y];head[y]=len;
}
LL w[N],b[N],s[N],hx[N];
inline void dfs(int k,int p)
{
  int i,x,t=0,ss=1;LL r=0;
  for(i=head[k];i;i=map[i].next)
    if((x=map[i].num)!=p) dfs(x,k);
  for(i=head[k];i;i=map[i].next)
    if((x=map[i].num)!=p) s[++t]=hx[x],ss+=sz[x];
  sort(s+1,s+t+1);
  for(i=1;i<=t;i++) r=r*B+s[i];
  r=r*B+w[ss];hx[k]=r;sz[k]=ss;
}
struct ex{int id;LL v;}g[N];
inline bool operator < (const ex &a,const ex &b) {return a.v<b.v;}
LL F[N],pre[N],suf[N],rth[N];
inline void DFS(int k,int p)
{
  int i,x,t=0;
  for(i=head[k];i;i=map[i].next)
    if((x=map[i].num)!=p) g[++t]=(ex){x,hx[x]};
  if(p) g[++t]=(ex){p,F[k]};
  sort(g+1,g+t+1);suf[t+1]=0;
  for(i=1;i<=t;i++) pre[i]=pre[i-1]*B+g[i].v;
  for(i=t;i>=1;i--) suf[i]=suf[i+1]+b[t-i]*g[i].v;
  rth[k]=pre[t]*B+w[n];
  for(i=1;i<=t;i++)
    if((x=g[i].id)!=p) F[x]=(pre[i-1]*b[t-i]+suf[i+1])*B+w[n-sz[x]];
  for(i=head[k];i;i=map[i].next)
    if((x=map[i].num)!=p) DFS(x,k);
}
multiset<LL>S;int sum,ans,ait;
inline void ins(LL u)
{
  if(S.find(u)==S.end( )) sum++;
  S.insert(u);
}
inline void del(LL u)
{
  S.erase(S.find(u));
  if(S.find(u)==S.end( )) sum--;
}
inline void find(int k,int p)
{
  if(p)
    {
      del(rth[p]),del(hx[k]);
      ins(rth[k]),ins(F[k]);
      if(sum>ans) ans=sum,ait=k;
    }
  int i,x;
  for(i=head[k];i;i=map[i].next)
    if((x=map[i].num)!=p) find(x,k);
  if(p)
    {
      del(rth[k]),del(F[k]);
      ins(rth[p]),ins(hx[k]);
    }
}
int main( )
{
  srand(872191552);
  int i,x,y;
  n=read( );
  for(i=1;i<n;i++) x=read( ),y=read( ),link(x,y);
  for(i=1;i<=n;i++) w[i]=(LL)rand( )*rand( )+rand( );
  for(b[0]=1,i=1;i<=n;i++) b[i]=b[i-1]*B;
  dfs(1,0);DFS(1,0);
  for(i=1;i<=n;i++) ins(hx[i]);
  ans=sum;ait=1;find(1,0);
  printf("%d",ait);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

//#define MULTITEST

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD1 = int(1e9) + 7;
const int MOD2 = int(1e9) + 9;
const int BASE = 129;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 * 1000 + 13;

int n;
vector<int> g[N];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n)
		g[i].clear();
	forn(i, n - 1){
		int v, u;
		scanf("%d%d", &v, &u);
		--v, --u;
		g[v].pb(u);
		g[u].pb(v);
	}
	return true;
}

template<const int &MOD>
struct _m_int {
	int val;

	_m_int(int64_t v = 0) {
		if (v < 0) v = v % MOD + MOD;
		if (v >= MOD) v %= MOD;
		val = int(v);
	}

	_m_int(uint64_t v) {
		if (v >= MOD) v %= MOD;
		val = int(v);
	}

	_m_int(int v) : _m_int(int64_t(v)) {}
	_m_int(unsigned v) : _m_int(uint64_t(v)) {}

	static int inv_mod(int a, int m = MOD) {
		int g = m, r = a, x = 0, y = 1;

		while (r != 0) {
			int q = g / r;
			g %= r; swap(g, r);
			x -= q * y; swap(x, y);
		}

		return x < 0 ? x + m : x;
	}

	explicit operator int() const { return val; }
	explicit operator unsigned() const { return val; }
	explicit operator int64_t() const { return val; }
	explicit operator uint64_t() const { return val; }
	explicit operator double() const { return val; }
	explicit operator long double() const { return val; }

	_m_int& operator+=(const _m_int &other) {
		val -= MOD - other.val;
		if (val < 0) val += MOD;
		return *this;
	}

	_m_int& operator-=(const _m_int &other) {
		val -= other.val;
		if (val < 0) val += MOD;
		return *this;
	}

	static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
#if !defined(_WIN32) || defined(_WIN64)
		return unsigned(x % m);
#endif
		// Optimized mod for Codeforces 32-bit machines.
		// x must be less than 2^32 * m for this to work, so that x / m fits in an unsigned 32-bit int.
		unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
		unsigned quot, rem;
		asm("divl %4\n"
			: "=a" (quot), "=d" (rem)
			: "d" (x_high), "a" (x_low), "r" (m));
		return rem;
	}

	_m_int& operator*=(const _m_int &other) {
		val = fast_mod(uint64_t(val) * other.val);
		return *this;
	}

	_m_int& operator/=(const _m_int &other) {
		return *this *= other.inv();
	}

	friend _m_int operator+(const _m_int &a, const _m_int &b) { return _m_int(a) += b; }
	friend _m_int operator-(const _m_int &a, const _m_int &b) { return _m_int(a) -= b; }
	friend _m_int operator*(const _m_int &a, const _m_int &b) { return _m_int(a) *= b; }
	friend _m_int operator/(const _m_int &a, const _m_int &b) { return _m_int(a) /= b; }

	_m_int& operator++() {
		val = val == MOD - 1 ? 0 : val + 1;
		return *this;
	}

	_m_int& operator--() {
		val = val == 0 ? MOD - 1 : val - 1;
		return *this;
	}

	_m_int operator++(int) { _m_int before = *this; ++*this; return before; }
	_m_int operator--(int) { _m_int before = *this; --*this; return before; }

	_m_int operator-() const {
		return val == 0 ? 0 : MOD - val;
	}

	friend bool operator==(const _m_int &a, const _m_int &b) { return a.val == b.val; }
	friend bool operator!=(const _m_int &a, const _m_int &b) { return a.val != b.val; }
	friend bool operator<(const _m_int &a, const _m_int &b) { return a.val < b.val; }
	friend bool operator>(const _m_int &a, const _m_int &b) { return a.val > b.val; }
	friend bool operator<=(const _m_int &a, const _m_int &b) { return a.val <= b.val; }
	friend bool operator>=(const _m_int &a, const _m_int &b) { return a.val >= b.val; }

	_m_int inv() const {
		return inv_mod(val);
	}

	_m_int pow(int64_t p) const {
		if (p < 0)
			return inv().pow(-p);

		_m_int a = *this, result = 1;

		while (p > 0) {
			if (p & 1)
				result *= a;
			a *= a;
			p >>= 1;
		}

		return result;
	}

	friend ostream& operator<<(ostream &os, const _m_int &m) {
		return os << m.val;
	}
};

typedef pair<_m_int<MOD1>, _m_int<MOD2>> hs;

hs val[N];
int siz[N];
hs pw[2 * N], rpw[2 * N];
map<hs, int> cnt;

void init(int v, int p = -1){
	vector<pair<hs, int>> cur;
	for (int u : g[v]) if (u != p){
		init(u, v);
		cur.pb(mp(val[u], u));
	}
	sort(all(cur));
	val[v] = mp('(', '(');
	siz[v] = 1;
	for (auto it : cur){
		val[v].x += it.x.x * pw[siz[v]].x;
		val[v].y += it.x.y * pw[siz[v]].y;
		siz[v] += siz[it.y];
	}
	val[v].x += ')' * pw[siz[v]].x;
	val[v].y += ')' * pw[siz[v]].y;
	++siz[v];
}

int ans;
int bst;

void dfs(int v, int p = -1){
	//cerr << v + 1 << " " << sz(cnt) << endl;

	if (sz(cnt) > bst){
		bst = sz(cnt);
		ans = v + 1;
	}

	vector<pair<hs, int>> cur;
	for (int u : g[v]) if (u != p)
		cur.pb(mp(val[u], u));
	sort(all(cur));

	vector<hs> pr(1, mp(0, 0));
	int tmp = 0;
	forn(i, sz(cur)){
		pr.pb(mp(pr.back().x + cur[i].x.x * pw[tmp].x, pr.back().y + cur[i].x.y * pw[tmp].y));
		tmp += siz[cur[i].y];
	}

	vector<hs> su(1, mp(0, 0));
	for (int i = sz(cur) - 1; i >= 0; --i){
		tmp -= siz[cur[i].y];
		su.pb(mp(su.back().x + cur[i].x.x * pw[tmp].x, su.back().y + cur[i].x.y * pw[tmp].y));
	}
	reverse(all(su));

	forn(i, sz(cur)){
		int u = cur[i].y;

		if (cnt[val[v]] == 1) cnt.erase(val[v]);
		else --cnt[val[v]];
		if (cnt[val[u]] == 1) cnt.erase(val[u]);
		else --cnt[val[u]];
		int sizv = siz[v];
		int sizu = siz[u];
		hs valv = val[v];
		hs valu = val[u];

		siz[v] -= siz[u];
		val[v].x = '(' + (pr[i].x + rpw[siz[u]].x * su[i + 1].x) * pw[1].x + ')' * pw[siz[v] - 1].x;
		val[v].y = '(' + (pr[i].y + rpw[siz[u]].y * su[i + 1].y) * pw[1].y + ')' * pw[siz[v] - 1].y;
		++cnt[val[v]];

		vector<pair<hs, int>> nw;
		for (int w : g[u]) nw.pb(mp(val[w], w));
		sort(all(nw));
		val[u] = mp('(', '(');
		siz[u] = 1;
		for (auto it : nw){
			val[u].x += it.x.x * pw[siz[u]].x;
			val[u].y += it.x.y * pw[siz[u]].y;
			siz[u] += siz[it.y];
		}
		val[u].x += ')' * pw[siz[u]].x;
		val[u].y += ')' * pw[siz[u]].y;
		++siz[u];
		++cnt[val[u]];

		dfs(u, v);

		if (cnt[val[v]] == 1) cnt.erase(val[v]);
		else --cnt[val[v]];
		if (cnt[val[u]] == 1) cnt.erase(val[u]);
		else --cnt[val[u]];
		siz[v] = sizv;
		siz[u] = sizu;
		val[v] = valv;
		val[u] = valu;
		++cnt[val[v]];
		++cnt[val[u]];
	}
}

void solve() {
	pw[0] = mp(1, 1);
	fore(i, 1, 2 * N) pw[i] = mp(pw[i - 1].x * BASE, pw[i - 1].y * BASE);
	rpw[0] = mp(1, 1);
	rpw[1] = mp(pw[1].x.inv(), pw[1].y.inv());
	fore(i, 2, 2 * N) rpw[i] = mp(rpw[i - 1].x * BASE, rpw[i - 1].y * BASE);

	init(0);
	bst = 0;
	ans = -1;
	cnt.clear();
	forn(i, n) ++cnt[val[i]];
	dfs(0);

	printf("%d\n", ans);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int tt = clock();

#endif

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef MULTITEST
	int tc;
	scanf("%d", &tc);
	while(tc--){
		read();
#else
	while(read()) {
#endif
		solve();

#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}


#include <bits/stdc++.h>

using namespace std;

//#define MULTITEST

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD1 = int(1e9) + 7;
const int MOD2 = 998244353;
const int BASE = 467353;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 * 1000 + 13;

int n;
vector<int> g[N];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n)
		g[i].clear();
	forn(i, n - 1){
		int v, u;
		scanf("%d%d", &v, &u);
		--v, --u;
		g[v].pb(u);
		g[u].pb(v);
	}
	return true;
}

template<const int &MOD>
struct _m_int {
	int val;

	_m_int(int64_t v = 0) {
		if (v < 0) v = v % MOD + MOD;
		if (v >= MOD) v %= MOD;
		val = int(v);
	}

	_m_int(uint64_t v) {
		if (v >= MOD) v %= MOD;
		val = int(v);
	}

	_m_int(int v) : _m_int(int64_t(v)) {}
	_m_int(unsigned v) : _m_int(uint64_t(v)) {}

	static int inv_mod(int a, int m = MOD) {
		int g = m, r = a, x = 0, y = 1;

		while (r != 0) {
			int q = g / r;
			g %= r; swap(g, r);
			x -= q * y; swap(x, y);
		}

		return x < 0 ? x + m : x;
	}

	explicit operator int() const { return val; }
	explicit operator unsigned() const { return val; }
	explicit operator int64_t() const { return val; }
	explicit operator uint64_t() const { return val; }
	explicit operator double() const { return val; }
	explicit operator long double() const { return val; }

	_m_int& operator+=(const _m_int &other) {
		val -= MOD - other.val;
		if (val < 0) val += MOD;
		return *this;
	}

	_m_int& operator-=(const _m_int &other) {
		val -= other.val;
		if (val < 0) val += MOD;
		return *this;
	}

	static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
#if !defined(_WIN32) || defined(_WIN64)
		return unsigned(x % m);
#endif
		// Optimized mod for Codeforces 32-bit machines.
		// x must be less than 2^32 * m for this to work, so that x / m fits in an unsigned 32-bit int.
		unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
		unsigned quot, rem;
		asm("divl %4\n"
			: "=a" (quot), "=d" (rem)
			: "d" (x_high), "a" (x_low), "r" (m));
		return rem;
	}

	_m_int& operator*=(const _m_int &other) {
		val = fast_mod(uint64_t(val) * other.val);
		return *this;
	}

	_m_int& operator/=(const _m_int &other) {
		return *this *= other.inv();
	}

	friend _m_int operator+(const _m_int &a, const _m_int &b) { return _m_int(a) += b; }
	friend _m_int operator-(const _m_int &a, const _m_int &b) { return _m_int(a) -= b; }
	friend _m_int operator*(const _m_int &a, const _m_int &b) { return _m_int(a) *= b; }
	friend _m_int operator/(const _m_int &a, const _m_int &b) { return _m_int(a) /= b; }

	_m_int& operator++() {
		val = val == MOD - 1 ? 0 : val + 1;
		return *this;
	}

	_m_int& operator--() {
		val = val == 0 ? MOD - 1 : val - 1;
		return *this;
	}

	_m_int operator++(int) { _m_int before = *this; ++*this; return before; }
	_m_int operator--(int) { _m_int before = *this; --*this; return before; }

	_m_int operator-() const {
		return val == 0 ? 0 : MOD - val;
	}

	friend bool operator==(const _m_int &a, const _m_int &b) { return a.val == b.val; }
	friend bool operator!=(const _m_int &a, const _m_int &b) { return a.val != b.val; }
	friend bool operator<(const _m_int &a, const _m_int &b) { return a.val < b.val; }
	friend bool operator>(const _m_int &a, const _m_int &b) { return a.val > b.val; }
	friend bool operator<=(const _m_int &a, const _m_int &b) { return a.val <= b.val; }
	friend bool operator>=(const _m_int &a, const _m_int &b) { return a.val >= b.val; }

	_m_int inv() const {
		return inv_mod(val);
	}

	_m_int pow(int64_t p) const {
		if (p < 0)
			return inv().pow(-p);

		_m_int a = *this, result = 1;

		while (p > 0) {
			if (p & 1)
				result *= a;
			a *= a;
			p >>= 1;
		}

		return result;
	}

	friend ostream& operator<<(ostream &os, const _m_int &m) {
		return os << m.val;
	}
};

typedef pair<_m_int<MOD1>, _m_int<MOD2>> hs;

hs val[N];
int siz[N];
hs pw[2 * N], rpw[2 * N];
map<hs, int> cnt;

void init(int v, int p = -1){
	vector<pair<hs, int>> cur;
	for (int u : g[v]) if (u != p){
		init(u, v);
		cur.pb(mp(val[u], u));
	}
	sort(all(cur));
	val[v] = mp('(', '(');
	siz[v] = 1;
	for (auto it : cur){
		val[v].x += it.x.x * pw[siz[v]].x;
		val[v].y += it.x.y * pw[siz[v]].y;
		siz[v] += siz[it.y];
	}
	val[v].x += ')' * pw[siz[v]].x;
	val[v].y += ')' * pw[siz[v]].y;
	++siz[v];
}

int ans;
int bst;

void dfs(int v, int p = -1){
	//cerr << v + 1 << " " << sz(cnt) << endl;

	if (sz(cnt) > bst){
		bst = sz(cnt);
		ans = v + 1;
	}

	vector<pair<hs, int>> cur;
	for (int u : g[v]) if (u != p)
		cur.pb(mp(val[u], u));
	sort(all(cur));

	vector<hs> pr(1, mp(0, 0));
	int tmp = 0;
	forn(i, sz(cur)){
		pr.pb(mp(pr.back().x + cur[i].x.x * pw[tmp].x, pr.back().y + cur[i].x.y * pw[tmp].y));
		tmp += siz[cur[i].y];
	}

	vector<hs> su(1, mp(0, 0));
	for (int i = sz(cur) - 1; i >= 0; --i){
		tmp -= siz[cur[i].y];
		su.pb(mp(su.back().x + cur[i].x.x * pw[tmp].x, su.back().y + cur[i].x.y * pw[tmp].y));
	}
	reverse(all(su));

	forn(i, sz(cur)){
		int u = cur[i].y;

		if (cnt[val[v]] == 1) cnt.erase(val[v]);
		else --cnt[val[v]];
		if (cnt[val[u]] == 1) cnt.erase(val[u]);
		else --cnt[val[u]];
		int sizv = siz[v];
		int sizu = siz[u];
		hs valv = val[v];
		hs valu = val[u];

		siz[v] -= siz[u];
		val[v].x = '(' + (pr[i].x + rpw[siz[u]].x * su[i + 1].x) * pw[1].x + ')' * pw[siz[v] - 1].x;
		val[v].y = '(' + (pr[i].y + rpw[siz[u]].y * su[i + 1].y) * pw[1].y + ')' * pw[siz[v] - 1].y;
		++cnt[val[v]];

		vector<pair<hs, int>> nw;
		for (int w : g[u]) nw.pb(mp(val[w], w));
		sort(all(nw));
		val[u] = mp('(', '(');
		siz[u] = 1;
		for (auto it : nw){
			val[u].x += it.x.x * pw[siz[u]].x;
			val[u].y += it.x.y * pw[siz[u]].y;
			siz[u] += siz[it.y];
		}
		val[u].x += ')' * pw[siz[u]].x;
		val[u].y += ')' * pw[siz[u]].y;
		++siz[u];
		++cnt[val[u]];

		dfs(u, v);

		if (cnt[val[v]] == 1) cnt.erase(val[v]);
		else --cnt[val[v]];
		if (cnt[val[u]] == 1) cnt.erase(val[u]);
		else --cnt[val[u]];
		siz[v] = sizv;
		siz[u] = sizu;
		val[v] = valv;
		val[u] = valu;
		++cnt[val[v]];
		++cnt[val[u]];
	}
}

void solve() {
	pw[0] = mp(1, 1);
	fore(i, 1, 2 * N) pw[i] = mp(pw[i - 1].x * BASE, pw[i - 1].y * BASE);
	rpw[0] = mp(1, 1);
	rpw[1] = mp(pw[1].x.inv(), pw[1].y.inv());
	fore(i, 2, 2 * N) rpw[i] = mp(rpw[i - 1].x * BASE, rpw[i - 1].y * BASE);

	init(0);
	bst = 0;
	ans = -1;
	cnt.clear();
	forn(i, n) ++cnt[val[i]];
	dfs(0);
	printf("%d\n", ans);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int tt = clock();

#endif

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef MULTITEST
	int tc;
	scanf("%d", &tc);
	while(tc--){
		read();
#else
	while(read()) {
#endif
		solve();

#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}


#include <bits/stdc++.h>

using namespace std;

//#define MULTITEST

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD1 = int(1e9) + 7;
const int MOD2 = int(1e9) + 9;
const int MOD3 = 998244353;
const int BASE = 4833;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 * 1000 + 13;

int n;
vector<int> g[N];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n)
		g[i].clear();
	forn(i, n - 1){
		int v, u;
		scanf("%d%d", &v, &u);
		--v, --u;
		g[v].pb(u);
		g[u].pb(v);
	}
	return true;
}

template<const int &MOD>
struct _m_int {
	int val;

	_m_int(int64_t v = 0) {
		if (v < 0) v = v % MOD + MOD;
		if (v >= MOD) v %= MOD;
		val = int(v);
	}

	_m_int(uint64_t v) {
		if (v >= MOD) v %= MOD;
		val = int(v);
	}

	_m_int(int v) : _m_int(int64_t(v)) {}
	_m_int(unsigned v) : _m_int(uint64_t(v)) {}

	static int inv_mod(int a, int m = MOD) {
		int g = m, r = a, x = 0, y = 1;

		while (r != 0) {
			int q = g / r;
			g %= r; swap(g, r);
			x -= q * y; swap(x, y);
		}

		return x < 0 ? x + m : x;
	}

	explicit operator int() const { return val; }
	explicit operator unsigned() const { return val; }
	explicit operator int64_t() const { return val; }
	explicit operator uint64_t() const { return val; }
	explicit operator double() const { return val; }
	explicit operator long double() const { return val; }

	_m_int& operator+=(const _m_int &other) {
		val -= MOD - other.val;
		if (val < 0) val += MOD;
		return *this;
	}

	_m_int& operator-=(const _m_int &other) {
		val -= other.val;
		if (val < 0) val += MOD;
		return *this;
	}

	static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
#if !defined(_WIN32) || defined(_WIN64)
		return unsigned(x % m);
#endif
		// Optimized mod for Codeforces 32-bit machines.
		// x must be less than 2^32 * m for this to work, so that x / m fits in an unsigned 32-bit int.
		unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
		unsigned quot, rem;
		asm("divl %4\n"
			: "=a" (quot), "=d" (rem)
			: "d" (x_high), "a" (x_low), "r" (m));
		return rem;
	}

	_m_int& operator*=(const _m_int &other) {
		val = fast_mod(uint64_t(val) * other.val);
		return *this;
	}

	_m_int& operator/=(const _m_int &other) {
		return *this *= other.inv();
	}

	friend _m_int operator+(const _m_int &a, const _m_int &b) { return _m_int(a) += b; }
	friend _m_int operator-(const _m_int &a, const _m_int &b) { return _m_int(a) -= b; }
	friend _m_int operator*(const _m_int &a, const _m_int &b) { return _m_int(a) *= b; }
	friend _m_int operator/(const _m_int &a, const _m_int &b) { return _m_int(a) /= b; }

	_m_int& operator++() {
		val = val == MOD - 1 ? 0 : val + 1;
		return *this;
	}

	_m_int& operator--() {
		val = val == 0 ? MOD - 1 : val - 1;
		return *this;
	}

	_m_int operator++(int) { _m_int before = *this; ++*this; return before; }
	_m_int operator--(int) { _m_int before = *this; --*this; return before; }

	_m_int operator-() const {
		return val == 0 ? 0 : MOD - val;
	}

	friend bool operator==(const _m_int &a, const _m_int &b) { return a.val == b.val; }
	friend bool operator!=(const _m_int &a, const _m_int &b) { return a.val != b.val; }
	friend bool operator<(const _m_int &a, const _m_int &b) { return a.val < b.val; }
	friend bool operator>(const _m_int &a, const _m_int &b) { return a.val > b.val; }
	friend bool operator<=(const _m_int &a, const _m_int &b) { return a.val <= b.val; }
	friend bool operator>=(const _m_int &a, const _m_int &b) { return a.val >= b.val; }

	_m_int inv() const {
		return inv_mod(val);
	}

	_m_int pow(int64_t p) const {
		if (p < 0)
			return inv().pow(-p);

		_m_int a = *this, result = 1;

		while (p > 0) {
			if (p & 1)
				result *= a;
			a *= a;
			p >>= 1;
		}

		return result;
	}

	friend ostream& operator<<(ostream &os, const _m_int &m) {
		return os << m.val;
	}
};

struct hs{
	_m_int<MOD1> x;
	_m_int<MOD2> y;
	_m_int<MOD3> z;
};

bool operator <(const hs &a, const hs &b){
	if (a.x != b.x) return a.x < b.x;
	if (a.y != b.y) return a.y < b.y;
	return a.z < b.z;
}

hs val[N];
int siz[N];
hs pw[2 * N], rpw[2 * N];
map<hs, int> cnt;

void init(int v, int p = -1){
	vector<pair<hs, int>> cur;
	for (int u : g[v]) if (u != p){
		init(u, v);
		cur.pb(mp(val[u], u));
	}
	sort(all(cur));
	val[v] = {'(', '(', '('};
	siz[v] = 1;
	for (auto it : cur){
		val[v].x += it.x.x * pw[siz[v]].x;
		val[v].y += it.x.y * pw[siz[v]].y;
		val[v].z += it.x.z * pw[siz[v]].z;
		siz[v] += siz[it.y];
	}
	val[v].x += ')' * pw[siz[v]].x;
	val[v].y += ')' * pw[siz[v]].y;
	val[v].z += ')' * pw[siz[v]].z;
	++siz[v];
}

int ans;
int bst;

void dfs(int v, int p = -1){
	//cerr << v + 1 << " " << sz(cnt) << endl;

	if (sz(cnt) > bst){
		bst = sz(cnt);
		ans = v + 1;
	}

	vector<pair<hs, int>> cur;
	for (int u : g[v]) if (u != p)
		cur.pb(mp(val[u], u));
	sort(all(cur));

	vector<hs> pr(1, {0, 0, 0});
	int tmp = 0;
	forn(i, sz(cur)){
		pr.pb({pr.back().x + cur[i].x.x * pw[tmp].x, pr.back().y + cur[i].x.y * pw[tmp].y, pr.back().z + cur[i].x.z * pw[tmp].z});
		tmp += siz[cur[i].y];
	}

	vector<hs> su(1, {0, 0, 0});
	for (int i = sz(cur) - 1; i >= 0; --i){
		tmp -= siz[cur[i].y];
		su.pb({su.back().x + cur[i].x.x * pw[tmp].x, su.back().y + cur[i].x.y * pw[tmp].y, su.back().z + cur[i].x.z * pw[tmp].z});
	}
	reverse(all(su));

	forn(i, sz(cur)){
		int u = cur[i].y;

		if (cnt[val[v]] == 1) cnt.erase(val[v]);
		else --cnt[val[v]];
		if (cnt[val[u]] == 1) cnt.erase(val[u]);
		else --cnt[val[u]];
		int sizv = siz[v];
		int sizu = siz[u];
		hs valv = val[v];
		hs valu = val[u];

		siz[v] -= siz[u];
		val[v].x = '(' + (pr[i].x + rpw[siz[u]].x * su[i + 1].x) * pw[1].x + ')' * pw[siz[v] - 1].x;
		val[v].y = '(' + (pr[i].y + rpw[siz[u]].y * su[i + 1].y) * pw[1].y + ')' * pw[siz[v] - 1].y;
		val[v].z = '(' + (pr[i].z + rpw[siz[u]].z * su[i + 1].z) * pw[1].z + ')' * pw[siz[v] - 1].z;
		++cnt[val[v]];

		vector<pair<hs, int>> nw;
		for (int w : g[u]) nw.pb(mp(val[w], w));
		sort(all(nw));
		val[u] = {'(', '(', '('};
		siz[u] = 1;
		for (auto it : nw){
			val[u].x += it.x.x * pw[siz[u]].x;
			val[u].y += it.x.y * pw[siz[u]].y;
			val[u].z += it.x.z * pw[siz[u]].z;
			siz[u] += siz[it.y];
		}
		val[u].x += ')' * pw[siz[u]].x;
		val[u].y += ')' * pw[siz[u]].y;
		val[u].z += ')' * pw[siz[u]].z;
		++siz[u];
		++cnt[val[u]];

		dfs(u, v);

		if (cnt[val[v]] == 1) cnt.erase(val[v]);
		else --cnt[val[v]];
		if (cnt[val[u]] == 1) cnt.erase(val[u]);
		else --cnt[val[u]];
		siz[v] = sizv;
		siz[u] = sizu;
		val[v] = valv;
		val[u] = valu;
		++cnt[val[v]];
		++cnt[val[u]];
	}
}

void solve() {
	pw[0] = {1, 1, 1};
	fore(i, 1, 2 * N) pw[i] = {pw[i - 1].x * BASE, pw[i - 1].y * BASE, pw[i - 1].z * BASE};
	rpw[0] = {1, 1, 1};
	rpw[1] = {pw[1].x.inv(), pw[1].y.inv(), pw[1].z.inv()};
	fore(i, 2, 2 * N) rpw[i] = {rpw[i - 1].x * BASE, rpw[i - 1].y * BASE, rpw[i - 1].z * BASE};

	init(0);
	bst = 0;
	ans = -1;
	cnt.clear();
	forn(i, n) ++cnt[val[i]];
	dfs(0);

	printf("%d\n", ans);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int tt = clock();

#endif

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef MULTITEST
	int tc;
	scanf("%d", &tc);
	while(tc--){
		read();
#else
	while(read()) {
#endif
		solve();

#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}