Lookout Towers

A kingdom has NN villages connected by N−1N-1 two-way roads, so that it is possible to travel between any two villages using the roads. The distance between two villages is the minimum number of roads needed to travel from one village to the other.

Some villages have a watchtower, and there are at least two watchtowers in the kingdom. The king wants to know how close the two nearest watchtowers are, and how many pairs of watchtowers are that close.

Input

The first line contains an integer NN (2≤N≤2×1052 \leq N \leq 2 \times 10^{5}) indicating the number of villages. Each village is identified by a distinct integer from 11 to NN.

The second line contains NN integers W1,W2,…,WN{W_1}, {W_2}, \ldots, {W_N}, where Wi=1W_i=1 if village ii has a watchtower, and Wi=0W_i=0 otherwise. At least two of these values are 11.

Each of the next N−1N-1 lines contains two integers UU and VV (1≤U,V≤N1 \leq U,V \leq N and U≠VU \neq V), indicating that there is a two-way road between villages UU and VV. It is guaranteed that it is possible to travel between any two villages using the roads.

Output

Output a single line with two integers: the minimum distance between two different watchtowers, followed by the number of unordered pairs of watchtowers at that distance.

Examples

Input

5
1 0 1 0 1
5 4
4 3
3 2
2 1

Output

2 2

Explanation

In this sample we have N = 5 villages connected in a line, with watchtowers at both ends and in the middle (1–2–3–4–5). The minimum distance is 2, with pairs {1, 3} and {3, 5} at that distance.

Input

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

Output

2 4

Explanation

Now we have N = 6 villages, with watchtowers at villages 1, 4, 5 and 6. The pairs {1, 4}, {1, 5}, {1, 6} and {4, 5} are all at distance 2. No other pair is at that distance or closer.