There are N cat towers, numbered from 1 to N. The height of Tower i (1≤i≤N) is P_i. The heights of the towers are distinct integers between 1 and N, inclusive. There are N−1 adjacent pairs of towers. For each j (1≤j≤N−1), Tower A_j and Tower B_j are adjacent to each other. In the beginning, it is possible to travel from a tower to any other tower by repeating moves from towers to adjacent towers.
In the beginning, a cat stays in a tower of height N.
Then we perform cat exercises. In cat exercises, we repeatedly choose a tower and put an obstacle on it. However, we cannot put an obstacle on a tower where we already put an obstacle on it. During the process, the following will happen.
Given information of the heights of the towers and pairs of adjacent towers, write a program which calculates the maximum possible sum of the number of moves of the cat from towers to adjacent towers if we put obstacles suitably
Read the following data from the standard input.
N
P_1 P_2 ⋯ P_N
A_1 B_1
A_2 B_2
⋮
A_N−1 B_N−1
Write one line to the standard output. The output should contain the maximum possible sum of the number of moves of the cat from towers to adjacent towers.