Example

Input

5
1 2
1 3
1 4
1 5


Output

6
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
const int N= 100005;
int fa[N];
unsigned long long value[N];
int sons[N];
int rsons[N];
vector<int> now;
bool vis[N];
map<unsigned long long,int> times;


int main(int argc, char const *argv[])
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        int start,end;
        scanf("%d%d",&start,&end);
        fa[end] = start;
        sons[start]++;
        rsons[start]++;
    }

    for(int i=1;i<=n;i++){
        if(sons[i] == 0){
            now.push_back(i);
        }
    }

    int now_size = now.size();
    while(now_size>0){
        int new_index = 0;
        for(int i=0;i<now_size ;i++){
            //printf("do %d\n",now[i] );
            int f = fa[now[i]];
            if(rsons[now[i]]==0 ){
                value[now[i]]++;
                times[value[now[i]]]++;
                value[f] += value[now[i]]*13131;
                rsons[f]--;
                //printf("test %d\n",now[i] );
                
                if(rsons[f]==0 && !vis[f]){
                    vis[f] = true;
                    now[new_index++] =f;
                }
                
                
            }
        }
        now_size = new_index;
    }
    long long result = 0;
    for(auto it = times.begin();it!= times.end();it++){
        long long n = (*it).second;
        result+=n*(n-1)/2;
        //printf("id:%lld value:%d\n",(*it).first,(*it).second );
    }
    //printf("v:%lld\n",value[0] );
    printf("%lld\n",result );


    return 0;
}