Example

Input

5
1 2
1 3
1 4
1 5


Output

6
#include <bits/stdc++.h>
  
using namespace std;
  
const int mod = 1e9 + 7;
  
int N;
vector< int > tree[100000];
unordered_map< int, int > val;
long long ret;
  
int dfs(int idx, int par = -1)
{
  int hashed = 1;
  for(int to : tree[idx]) {
    if(to != par) (hashed += 1LL * dfs(to, idx) * 1003 % mod) %= mod;
  }
  ret += val[hashed]++;
  return(hashed);
}
  
int main()
{
  cin >> N;
  for(int i = 0; i < N - 1; i++) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    tree[A].push_back(B);
    tree[B].push_back(A);
  }
  dfs(0, -1);
  cout << ret << endl;
}