Loading [MathJax]/jax/output/HTML-CSS/jax.js

Similarity of Subtrees

Define the depth of a node in a rooted tree by applying the following rules recursively:

Let S(T,d) be the number of nodes of T with depth d. Two rooted trees T and T are similar if and only if S(T,d) equals S(T,d) for all non-negative integer d.

You are given a rooted tree T with N nodes. The nodes of T are numbered from 1 to N. Node 1 is the root node of T. Let Ti be the rooted subtree of T whose root is node i. Your task is to write a program which calculates the number of pairs (i,j) such that Ti and Tj are similar and i<j.

Input

The input consists of a single test case.

N
a1 b1
a2 b2
...
aN1 bN1

The first line contains an integer N (1N100,000), which is the number of nodes in a tree. The following N1 lines give information of branches: the i-th line of them contains ai and bi, which indicates that a node ai is a parent of a node bi. (1ai,biN,aibi) The root node is numbered by 1. It is guaranteed that a given graph is a rooted tree, i.e. there is exactly one parent for each node except the node 1, and the graph is connected.

Output

Print the number of the pairs (x,y) of the nodes such that the subtree with the root x and the subtree with the root y are similar and x<y.

Sample Input 1

5
1 2
1 3
1 4
1 5

Output for the Sample Input 1

6

Sample Input 2

6
1 2
2 3
3 4
1 5
5 6

Output for the Sample Input 2

2

Sample Input 3

13
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
6 10
7 11
8 12
11 13

Output for the Sample Input 3

14