Example

Input

5
1 2
1 3
1 4
1 5


Output

6
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<bitset>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const ll base = 999983;
const int maxn = 1e5+5;
int n,ind[maxn];
vector<ll> htable;
vector<int> G[maxn];

ll dfs(int u)
{
    ll temp = 0;
    for(int i=0;i<G[u].size();++i){
        temp += dfs(G[u][i]);
    }
    htable.push_back(temp*base+G[u].size());
    return temp*base+G[u].size();
}

inline ll work(ll m)
{
    return m*(m-1)>>1;
}

int main()
{
    while(~scanf("%d",&n)){
        htable.clear();
        memset(ind,0,sizeof ind);
        for(int i=0;i<=n;++i) G[i].clear();
        for(int i=0;i<n-1;++i){
            int u,v; scanf("%d%d",&u,&v);
            G[u].push_back(v);
            ++ind[v];
        }
        int s = 0;
        for(int i=1;i<=n && !s;++i){
            if(ind[i] == 0) s = i;
        }
        dfs(s);
        sort(htable.begin(),htable.end());
        ll num = 1;
        ll ans = 0;
        for(int i=1;i<htable.size();++i){
            if(htable[i] != htable[i-1]){
                ans += work(num);
                num = 1;
            }
            else ++num;
        }
        if(htable.size() > 1 && htable[htable.size()-1] == htable[htable.size()-2]) ans += work(num);
        printf("%lld\n",ans);
    }
    return 0;
}