#D7201. Similarity of Subtrees

    ID: 5979 Type: Default 2000ms 536MiB

Similarity of Subtrees

Similarity of Subtrees

Example

Input

5 1 2 1 3 1 4 1 5

Output

6

inputFormat

Input

5 1 2 1 3 1 4 1 5

outputFormat

Output

6

样例

5
1 2
1 3
1 4
1 5
6