The village of Byteville has n houses joined by n−1 roads. Between any two houses there is exactly one route. The houses are numbered from 1 to n, and house 1 belongs to Byteasar, who runs the village.
A rural technology programme has delivered n computers to Byteasar's house. Every house gets one computer, and Byteasar has to hand them out. The villagers have already agreed to start the latest version of FarmCraft together as soon as they have their machines.
Byteasar loads all the computers onto his pickup truck and sets off. He has exactly enough fuel to drive along each road twice. When he reaches a house he drops off one computer and drives on immediately. A household starts installing FarmCraft the moment its computer arrives. The install time differs from house to house and is known in advance. Byteasar installs the game on his own computer only after he has delivered everything and driven back home. Driving along one road takes 1 minute, and unloading a computer takes no time.
Find the earliest moment at which every villager, Byteasar included, can start playing. That is, choose the delivery order that makes the last install finish as early as possible, and report that finishing time.
The first line contains the number of houses in Byteville, n. (2≤n≤500000)
The second line contains the integers c1,c2,…,cn separated by single spaces. ci is the install time in minutes for house i. (1≤ci≤109)
Each of the next n−1 lines describes one road. Such a line contains two integers a and b separated by a single space (1≤a<b≤n), meaning that a road runs directly between house a and house b.
Print one integer on the first line: the earliest time, in minutes, at which the install has finished in every house, Byteasar's included.
The picture below shows the village from the example.

If Byteasar delivers the computers in the order 3,2,4,5,6 and then drives home, the installs in houses 1 to 6 finish after 11,10,10,10,8,9 minutes. Everyone starts playing after 11 minutes.
If he delivers them in the order 3,4,5,6,2, the installs finish after 11,16,10,8,6,7 minutes, so nobody can start together until 16 minutes have passed.