Problem: 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>

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class path_queries {
	public static void main(String args[])throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        
        StringBuilder sb = new StringBuilder();
        
        String s[] = in.readLine().split(" ");
        
        int n = Integer.parseInt(s[0]);
        int q = Integer.parseInt(s[1]);
        int i, e[][] = new int[n-1][2];
        
        PriorityQueue<Pair> pq=new PriorityQueue<>(new Comparator<Pair>() {
            @Override
            public int compare(Pair o1, Pair o2) {
                if (o1.w > o2.w) return 1;
                else if (o1.w==o2.w) return o1.i>o2.i?1:-1;
                else return -1;
            }});
        
        for (i = 0; i < n-1; i++) {
            s = in.readLine().split(" ");
            e[i][0] = Integer.parseInt(s[0])-1;
            e[i][1] = Integer.parseInt(s[1])-1;
            pq.add(new Pair(i,Integer.parseInt(s[2])));
        }
 
        long ans[] = new long[q];
        int par[] = new int[n], sz[] = new int[n], qr[][] = new int[q][2];
        
        for (i = 0; i < n; i++) {
            par[i] = i; sz[i] = 1;
        }
        
        s = in.readLine().split(" ");
        for (i = 0; i < q; i++) {
            qr[i][0] = Integer.parseInt(s[i]); qr[i][1] = i;
        }
        
        Arrays.sort(qr, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[0]>o2[0]) return 1;
                else if (o1[0]==o2[0]) return o1[1]>o2[1]?1:-1;
                else return -1;
            }});
 
        long cur = 0;
        
        for (i = 0; i < q; i++) {
            while (!pq.isEmpty() && pq.peek().w <= qr[i][0]) {
                int a = e[pq.peek().i][0],b = e[pq.peek().i][1];
                a = parent(par,a); 
                b = parent(par,b);
                pq.poll();
                if (a == b) {
                	continue;
                }
                cur -= 1l*sz[a]*(sz[a]-1)/2;
                cur -= 1l*sz[b]*(sz[b]-1)/2;
                sz[a] += sz[b];
                par[b] = a;
                cur += 1l*sz[a]*(sz[a]-1)/2;
            }
            ans[qr[i][1]] = cur;
        }
        
        for (i = 0; i < q; i++) {
        	sb.append(ans[i] + " ");
        }
        System.out.println(sb);
       
        in.close();
    }
 
    static int parent(int p[],int n) {
        if (p[n] != n) {
        	p[n] = parent(p,p[n]);
        } 
        return p[n];
    }
 
    static class Pair {
        int i, w;
        Pair(int a,int b) {
            i = a;
            w = b;
        }
    }
	
}