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.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Path_Queries_CF_582_DIV3 {
static PrintWriter pw =new PrintWriter(System.out);
public static void main(String[] args) throws Exception{
	BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer st;
	st= new StringTokenizer(bf.readLine());
	int n=Integer.parseInt(st.nextToken());
	int m=Integer.parseInt(st.nextToken());
	Edge[] arr=new Edge[n-1];
	for(int i=0;i<n-1;i++) {
		st=new StringTokenizer(bf.readLine());
		int u=Integer.parseInt(st.nextToken())-1;
		int v=Integer.parseInt(st.nextToken())-1;
		int w=Integer.parseInt(st.nextToken());
		arr[i]=new Edge(u,v,w);
	}
	
	Arrays.sort(arr);
	Edge[] q=new Edge[m];
	st=new StringTokenizer(bf.readLine());
	for(int i=0;i<m;i++) {	
		int num=Integer.parseInt(st.nextToken());
		q[i]=new Edge(0, i, num);
	}
	Arrays.sort(q);
	UDS uds =new UDS(n);
	int i=0;
	long[] ans=new long[m];
	for(int j=0;j<m;j++) {
		int query=(q[j].w);
	while(i<(n-1)&&arr[i].w<=query) {
		uds.union(arr[i].u, arr[i].v);
		i++;
	}
	ans[q[j].v]=uds.r;
}
	for(long a:ans)
		pw.print(a+" ");
	pw.println();
	pw.flush();
}
public static void shuffle(int[] a)
{
	int n = a.length;
	for(int i = 0; i < n; i++)
	{
		int r = i + (int)(Math.random() * (n - i));
		int tmp = a[i];
		a[i] = a[r];
		a[r] = tmp;
	}
}


static class UDS{
	int[] p,rank;
	int[] setSize;
	int n;
	long r=0;
	
public UDS(int n) {
		this.n=n;
		p=new int[n];
		rank=new int[n];
		
		for(int i=0;i<n;i++)
		{	p[i]=i;
		rank[i]=1;
		}		
		setSize=new int[n];
		Arrays.fill(setSize, 1);
	}
	public int findSet(int i) {
		if(p[i]==i)return i;
		return p[i]=findSet(p[i]);
	}
	public int setSize(int i) {
		return setSize[findSet(i)];
	}
	
public void union(int i, int j) {
		int p1=findSet(i);
		int p2=findSet(j);
		if(p1!=p2) {
			if(rank[p1]>rank[p2]) {
				long pSize=setSize[p1];
				r-=(pSize*(pSize-1))/2;
				 pSize=setSize[p2];
				r-=(pSize*(pSize-1))/2;
				p[p2]=p1;
				setSize[p1]+=setSize[p2];

				pSize=setSize[p1];
				r+=(pSize*(pSize-1))/2;
			
			}else {
				long pSize=setSize[p1];
				r-=(pSize*(pSize-1))/2;
				 pSize=setSize[p2];
				r-=(pSize*(pSize-1))/2;
				
				p[p1]=p2;
				setSize[p2]+=setSize[p1];
			
				
				pSize=setSize[p2];
				r+=(pSize*(pSize-1))/2;
				
				if(rank[p1]==rank[p2]) {
					rank[p2]++;
				}
			}
		}
	}
}
static class Edge implements Comparable<Edge>{
	int u,v,w;
	public Edge(int a,int b, int c) {
		u=a;v=b;w=c;
	}
	@Override
	public int compareTo(Edge o) {
		// TODO Auto-generated method stub
		return w-o.w;
	}

}
}
