#P1083A. The Fair Nut and the Best Path

The Fair Nut and the Best Path

Description

The Fair Nut is going to travel to the Tree Country, in which there are nn cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car in the city uu and go by a simple path to city vv. He hasn't determined the path, so it's time to do it. Note that chosen path can consist of only one vertex.

A filling station is located in every city. Because of strange law, Nut can buy only wiw_i liters of gasoline in the ii-th city. We can assume, that he has infinite money. Each road has a length, and as soon as Nut drives through this road, the amount of gasoline decreases by length. Of course, Nut can't choose a path, which consists of roads, where he runs out of gasoline. He can buy gasoline in every visited city, even in the first and the last.

He also wants to find the maximum amount of gasoline that he can have at the end of the path. Help him: count it.

The first line contains a single integer nn (1n31051 \leq n \leq 3 \cdot 10^5) — the number of cities.

The second line contains nn integers w1,w2,,wnw_1, w_2, \ldots, w_n (0wi1090 \leq w_{i} \leq 10^9) — the maximum amounts of liters of gasoline that Nut can buy in cities.

Each of the next n1n - 1 lines describes road and contains three integers uu, vv, cc (1u,vn1 \leq u, v \leq n, 1c1091 \leq c \leq 10^9, uvu \ne v), where uu and vv — cities that are connected by this road and cc — its length.

It is guaranteed that graph of road connectivity is a tree.

Print one number — the maximum amount of gasoline that he can have at the end of the path.

Input

The first line contains a single integer nn (1n31051 \leq n \leq 3 \cdot 10^5) — the number of cities.

The second line contains nn integers w1,w2,,wnw_1, w_2, \ldots, w_n (0wi1090 \leq w_{i} \leq 10^9) — the maximum amounts of liters of gasoline that Nut can buy in cities.

Each of the next n1n - 1 lines describes road and contains three integers uu, vv, cc (1u,vn1 \leq u, v \leq n, 1c1091 \leq c \leq 10^9, uvu \ne v), where uu and vv — cities that are connected by this road and cc — its length.

It is guaranteed that graph of road connectivity is a tree.

Output

Print one number — the maximum amount of gasoline that he can have at the end of the path.

Sample Input 1

3
1 3 3
1 2 2
1 3 2

Sample Output 1

3

Sample Input 2

5
6 3 2 5 0
1 2 10
2 3 3
2 4 1
1 5 1

Sample Output 2

7

Note

The optimal way in the first example is 2132 \to 1 \to 3.

The optimal way in the second example is 242 \to 4.