In the country Treeland there are n cities and n−1 bidirectional roads. Each road connects some pair of cities and from any city you can get to any other one using only the given roads. City 1 is the root of the tree. There is a value ai associated with each city i. For any city i, there exists a set Si which contains the distinct values of all cities j such that j lies in sub-tree rooted at city i and it's distance from city i is divisible by magic number m. Hence no element of set Si repeats. Strength of city i is the number of elements in above defined set Si whose value is strictly less than ai. Find ∑ai∗xi where xi is Strength of city i.
First line contains two integers n - number of cities and m - magic number. Next n−1 line contains two integers u and v denoting edge between city u and city v. Next line contains n integers - where each integer ai is value of city i.
Print single integer which is answer of the problem - ∑ai∗xi.
1 <= n <= 105
1 <= m <= 13
1 <= u,v <= n
1 <= ai <= 106
Setter : Tanmay Patel