Under construction

Still being built. Things may change

Tree Reading

Interview

Time limit1sMemory limit1024 MB

Summary
Given a tree whose vertices each hold a digit from 1 to 9, sum the numbers read along the path for every ordered pair of vertices, modulo 1,000,000,007.
Level

Medium6 of 10

Topics
Tree, Dynamic programming, DFS
Solved
No attempts yet

Problem

A tree with VV vertices is given. The vertices are numbered from 11 to VV. Vertex ii has a digit SiS_i, which is one of the numbers from 11 to 99.

For vertices aa and bb of the tree, let f(a,b)f(a, b) be the decimal integer formed by writing down the digits on the vertices of the shortest path from vertex aa to vertex bb, in path order. For example, if vertices 11, 22, and 33 have the numbers 33, 44, and 11, and the shortest path from vertex 11 to vertex 22 is 1→3→21 \rightarrow 3 \rightarrow 2, then f(1,2)=314f(1, 2) = 314.

Find the sum of f(a,b)f(a, b) over all possible integer pairs (a,b)(a, b) (1≤a,b≤V1 \le a, b \le V), modulo 1 000 000 0071\,000\,000\,007.

Input

The first line contains VV. (1≤V≤200 0001 \le V \le 200\,000)

The second line contains S1,⋯ ,SVS_1, \cdots, S_V, separated by spaces. (1≤Si≤91 \le S_i \le 9)

Each of the next V−1V-1 lines contains two vertex numbers xx and yy, separated by a space, meaning that vertices xx and yy are connected by an edge. (1≤x,y≤V1 \le x, y \le V)

All numbers in the input are integers.

Output

Print the answer on the first line.

Examples1

  1. Example 1

    Input
    5
    3 1 4 1 5
    1 2
    1 3
    2 4
    2 5
    
    Expected output
    17560