You are given a weighted tree consisting of n vertices. Recall that a tree is a connected graph without cycles. Vertices u_i and v_i are connected by an edge with weight w_i.

You are given m queries. The i-th query is given as an integer q_i. In this query you need to calculate the number of pairs of vertices (u, v) (u < v) such that the maximum weight of an edge on a simple path between u and v doesn't exceed q_i.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of vertices in the tree and the number of queries.

Each of the next n - 1 lines describes an edge of the tree. Edge i is denoted by three integers u_i, v_i and w_i — the labels of vertices it connects (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i) and the weight of the edge (1 ≤ w_i ≤ 2 ⋅ 10^5). It is guaranteed that the given edges form a tree.

The last line of the input contains m integers q_1, q_2, ..., q_m (1 ≤ q_i ≤ 2 ⋅ 10^5), where q_i is the maximum weight of an edge in the i-th query.

Output

Print m integers — the answers to the queries. The i-th value should be equal to the number of pairs of vertices (u, v) (u < v) such that the maximum weight of an edge on a simple path between u and v doesn't exceed q_i.

Queries are numbered from 1 to m in the order of the input.

Examples

Input


7 5
1 2 1
3 2 3
2 4 1
4 5 2
5 7 4
3 6 2
5 2 3 4 1


Output


21 7 15 21 3 


Input


1 2
1 2


Output


0 0 


Input


3 3
1 2 1
2 3 2
1 3 2


Output


1 3 3 

Note

The picture shows the tree from the first example: <image>
import java.util.*;
import java.io.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    //    long mod = 998244353;
    long mod = (long)1e9+7;
    List<Integer>[] tree, rootTree;
    int num_cycle;
    int n, k;
    int[] a, maxHeight;
    int[][] dp;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        int t = sc.nextInt();
        int t = 1;
        /*
        while(t-->0){
            main.solve();
        }*/
        for(int i=1; i<=t; i++){
            main.solve();
        }
        out.flush();
    }

    void solve(){
        n = neInt(); k = neInt();
        a = new int[n+1]; maxHeight = new int[n+1];
        for(int i=0; i<n; i++) a[i] = neInt();
        tree = new List[n+1]; rootTree = new List[n+1];
        for(int i=0; i<=n; i++) {
            tree[i] = new LinkedList<>();
            rootTree[i] = new ArrayList<>();
        }
        for(int i=0; i<n-1; i++){
            int u = neInt()-1, v = neInt()-1;
            tree[u].add(v); tree[v].add(u);
        }
        dp = new int[n+1][n+1];
        buildRoot(0,0);
        dfs(0);
        int ans = dp[0][0];
        out.println(ans);
    }
    void dfs(int cur){
        for(int to:rootTree[cur]) {
            dfs(to);
        }
        for(int depth=maxHeight[cur]; depth>0; depth--){
            for(int i:rootTree[cur]){
                int curHead = dp[i][depth-1];
                for(int j:rootTree[cur]){
                    if(i==j) continue;
                    int target = Math.max(depth-1, k-depth);
                    curHead += dp[j][target];
                }
                dp[cur][depth] = Math.max(dp[cur][depth], curHead);
            }
            dp[cur][depth] = Math.max(dp[cur][depth], dp[cur][depth+1]);
        }
        // choose this vertex
        dp[cur][0] = a[cur];
        for(int to:rootTree[cur]){
            dp[cur][0] += dp[to][k];
        }
        dp[cur][0] = Math.max(dp[cur][0], dp[cur][1]);
    }
    int buildRoot(int cur, int from){
        int ans = 0;
        for(int to:tree[cur]){
            if(to==from) continue;
            rootTree[cur].add(to);
            ans = Math.max(ans, 1+buildRoot(to, cur));
        }
        return maxHeight[cur] = ans;
    }


    String neS(){
        return sc.next();
    }
    int neInt(){
        return Integer.parseInt(sc.next());
    }
    long neLong(){
        return Long.parseLong(sc.next());
    }

    int paIn(String s){return Integer.parseInt(s);}

}