- Time limit: 2.00 s
- Memory limit: 512 MB
Uolevi is visiting a foreign country with lots of tulips, windmills and of course, canals. Even on vacation Uolevi can't help but come up with tasks, and as such, he decided to count the number of canals in the country.
The country's waterways can be represented as a connected graph with nodes and edges (that is, as a tree).
Uolevi calls a path from node to node in this graph a canal, if the minimum index of any node on the path is , and the maximum index of any node on the path is .
Given the graph representing the waterways, output how many canals it contains. That is, output the number of ordered pairs such that the minimum index of a node on the path from to is , and the maximum index is .
With this definition, pairs are always counted once.
Input
The first line of input contains a single integer : the number of nodes.
After this, lines follow, the 'th containing two integers and : nodes and are connected by an edge.
Output
Output a single integer: The number of canals.
Constraints
Example
Input:
5 1 2 2 3 3 4 4 5
Output:
15
Explanation:
All 15 pairs where are canals
Example 2
Input:
4 3 2 2 1 4 2
Output:
9
Explanation:
The canals are
(1 1), (1 2), (1 3), (1 4), (2 2), (2 3), (2 4), (3 3), (4 4).