#878. SWW and Probability

SWW and Probability

Background

  SWW is a master of Probability. One day, she thought of a problem in her dream and she wants to challenge you.

  She gives you a tree TT with nn nodes, labeled from 11 to nn. Each node of the tree has a positive integer weight aia_i . For any connected subgraph of TT, denoted as SS, you could collect the weights of all nodes in SS and calculate the variance of these weights.

  Now, SWW wants you to calculate the sum of variances of all connected subgraphs of T. Since the answer may be very large, you should print your result modulo 998244353998244353.

  Recall that for a given set of numbers x1,x2,,xnx_1, x_2, · · · , x_n, the mean µx and variance σ2xσ\frac{2}{x} is defined as

µx=x1+x2++xnnµ_x = \frac{x_1 + x_2 + · · · + x_n}{n} $$σ^2_x=\frac{(x_1 − µ_x)^2 + (x_2 − µ_x)^2 + · · · + (x_n − µ_x)^2}{n} $$

Input

The first line contains an integer n(1n300)n (1 ≤ n ≤ 300), representing the number of tree nodes.

The second line contains nn integers a1,a2,,an(1ai998244352)a_1, a_2, · · · , a_n (1 ≤ a_i ≤ 998244352), representing the weights of each node.

Each line of the next n1n − 1 lines contains two integers u,v(1u,vn)u, v (1 ≤ u, v ≤ n), representing an edge (u,v)(u, v) in the tree. It is guaranteed that the given graph is a tree.

Output

Output a single integer, representing the answer modulo 998244353998244353.

Samples

3
1 2 3
1 2
2 3
166374060

Note

The tree in the example has six different connected subgraphs: 1,2,3,1,2,2,3,1,2,3{1}, {2}, {3}, {1, 2}, {2, 3}, {1, 2, 3}.

Their variance is 0,0,0,14,14,230, 0, 0,\frac{1}{4},\frac{1}{4},\frac{2}{3}. So the answer is76\frac{7}{6}, i.e. 7×617 × 6 ^{−1} mod 998244353=166374060998244353 = 166374060.