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.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Div3_582_G {
	
	static int[] id, sz = null;
	
	class edge{
		int u,v,w;
		edge(int u, int v, int w) {
			this.u = u;
			this.v = v;
			this.w = w;
		}
	}
	
	class query{
		int w, ind;
		long ans;
		public query(int w, int ind) {
			this.w = w;
			this.ind = ind;
		}
	}
	
	public static int root (int p) {
		while(id[p]!=p) {
			id[p] = id[id[p]];
			p = id[p];
		}
		return p;
	}
	
	public static long numPairs (int p) {
		long n = (long)p;
		return n*(n-1)/2;
	}
	
	public static long merge(int u, int v, long res) {
		if(root(v)!=root(u)) {
			int u_root = root(u);
			int v_root = root(v);
			res = res - numPairs(sz[u_root]) - numPairs(sz[v_root]);
			if(sz[u_root] < sz[v_root]) {
				id[u_root] = v_root;
				sz[v_root] += sz[u_root]; 
			}else {
				id[v_root] = id[u_root];
				sz[u_root] += sz[v_root];
			}
			res += numPairs(sz[root(v)]);
		}
		return res;
	}
	
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		List<edge> edges = new ArrayList<>();
		List<query> wc = new ArrayList<>();
		int n = Integer.parseInt(str[0]), q = Integer.parseInt(str[1]);
		for(int i=0; i<n-1; i++) {
			str = br.readLine().split(" ");
			edges.add(new Div3_582_G().new edge(Integer.parseInt(str[0])-1, Integer.parseInt(str[1])-1, Integer.parseInt(str[2])));
			
		}
		str = br.readLine().split(" ");
		for(int i=0; i<q; i++) wc.add(new Div3_582_G().new query(Integer.parseInt(str[i]), i));
		Collections.sort(edges, new Comparator<edge>() {
			@Override
			public int compare(edge e1, edge e2) {
				return e1.w-e2.w;
			}
		});
		Collections.sort(wc, new Comparator<query>() {
			public int compare(query q1, query q2) {
				return q1.w-q2.w;
			}
		});
		id = new int[n];
		sz = new int[n];
		for(int i=0; i<n; i++) {
			id[i] = i;
			sz[i] = 1;
		}
		int ind = 0;
		long res = 0;
		for(int i=0; i<q; i++) {
			while(ind<n-1 && edges.get(ind).w <= wc.get(i).w) {
				res = merge(edges.get(ind).u, edges.get(ind).v, res);
				ind++;
			}
			wc.get(i).ans = res;
		}
		Collections.sort(wc, new Comparator<query>() {
			public int compare(query q1, query q2) {
				return q1.ind-q2.ind;
			}
		});
		for(int i=0; i<q; i++) System.out.print(wc.get(i).ans+" ");
	}
}