Hongjun and the Possible Sets

Count the nonempty connected vertex subsets of a weighted tree whose maximum minus minimum weight is at most d.

Hard8TreeDFSDivide and conquerDynamic programmingNo attempts yetTime limit3sMemory limit512 MB

Problem

There is a tree with NN vertices. Vertex ii carries a weight a(i)a(i). Given one integer dd, a set SS of tree vertices is a "possible set" when it satisfies all of the following conditions.

  1. SS is not empty.
  2. The vertices in SS are connected. That is, for any two vertices uu and vv in SS, every vertex on the path joining them belongs to SS.
  3. maxuSa(u)minvSa(v)d\max_{u \in S} a(u) - \min_{v \in S} a(v) \le d

Write a program that counts the possible sets SS. The count can be very large, so print it modulo 109+710^9+7.

Input

The first line contains dd and NN. (0d200000 \le d \le 20000, 1N200001 \le N \le 20000)

The second line contains NN integers, a(1)a(1) through a(N)a(N) in order. (1a(i)200001 \le a(i) \le 20000)

Each of the next N1N-1 lines contains two integers uu and vv, an edge of the tree. (1u,vN1 \le u, v \le N)

Output

Print the number of possible sets modulo 109+710^9+7 on the first line.

Hint

In the first example the eight possible sets are {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}.