One-Way Whiskers
There are cats living at the vertices of a tree. Cat lives at vertex and has ability . Each edge has a difficulty.
A cat may traverse an edge if and only if its ability is at least the difficulty of that edge. To visit another cat, it must traverse every edge on the unique path to that cat's vertex.
For two distinct cats and , call the unordered pair a one-way acquaintance if exactly one of the following statements is true:
- cat can visit cat ;
- cat can visit cat .
Count the number of one-way acquaintance pairs.
Input
The first line contains an integer (), the number of vertices and cats.
The second line contains integers (), where is the ability of the cat at vertex .
Output
Print one integer: the number of unordered one-way acquaintance pairs.
Samples
Sample 1
Input
5 2 7 4 6 1 1 2 3 2 3 5 2 4 6 4 5 2
Output
6
The one-way acquaintance pairs are , , , , , and .