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 
{
	
	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int m=s.nextInt();
		Node ar[]=new Node[n-1];
		for(int i=0;i<n-1;i++) {
			int u=s.nextInt();
			int v=s.nextInt();
			int w=s.nextInt();
			u--;
			v--;
			ar[i]=new Node(u,v,w);
		}
		
		Pair br[]=new Pair[m];
		for(int i=0;i<m;i++) {
			br[i]=new Pair(s.nextInt(),i);
		}
		Arrays.sort(ar,(a,b)->a.ti-b.ti);
		Arrays.sort(br,(a,b)->a.fi-b.fi);
//		for(int i=0;i<n-1;i++)
//			System.out.println(ar[i].fi+" "+ar[i].si+" "+ar[i].ti);
//		
//		for(int i=0;i<m;i++)
//			System.out.println(br[i].fi+" "+br[i].si);
		long ans[]=new long[m];
		long leader[]=new long[n];
		Arrays.fill(leader, 1);
		DSU dsu=new DSU(n);
		int j=0;
		long res=0;
		for(int i=0;i<m;i++) {
			while(j<n-1 && ar[j].ti<=br[i].fi) {
				int u=ar[j].fi;
				int v=ar[j].si;
				int w=ar[j].ti;
				u=dsu.get(u);
				v=dsu.get(v);
				
				// if(leader[u]<leader[v]) {
				// 	long tmp=leader[u];   
				// 	leader[u]=leader[v];
				// 	leader[v]=tmp;
				// }
				dsu.union(u, v);
				res-=get(leader[u]);
				res-=get(leader[v]);
				
				leader[u]+=leader[v];
				
				res+=get(leader[u]);
			//	System.out.println("res :"+res+" and j :"+j);
				j++;
			}
			ans[br[i].si]=res;
		}
		
		for(int i=0;i<m;i++) 
			System.out.print(ans[i]+" ");
		System.out.println();
		
	}

	private static long get(long u) {
		// TODO Auto-generated method stub
		return (u*(u-1))/2;
	}
	
}
class DSU {
	int parent[];
	int rank[];
	int totalComponents;
	public DSU(int n) {
		parent=new int[n];
		rank=new int[n];
		for(int i=0;i<n;i++) {
			parent[i]=i;
			
		}
		totalComponents=n;
	}
	
	int get(int a) {
		
		if(a==parent[a])
			return a;
		
		return  parent[a]= get(parent[a]);
	}
	
	void union(int a, int b) {
		a=this.get(a); 
		b=this.get(b); 
		if(a!=b) {
			if(rank[a]<rank[b]) {
				int tmp=rank[a];   
				rank[a]=rank[b];
				rank[b]=tmp;
			}
			parent[b]=a;
			
			
			if(rank[a]==rank[b]) 
				rank[a]++;

			totalComponents--;   
		}
	}
	
}
class Node{
	int fi;
	int si;
	int ti;
	public Node(int fi,int si,int ti) {
		if(fi>si) {
			this.fi=si;
			this.si=fi;
			this.ti=ti;
		}else {
			this.fi=fi;
			this.si=si;
			this.ti=ti;
		}
	}
	
}
class Pair{
	int fi;
	int si;

	public Pair(int fi,int si) {
			this.fi=fi;
			this.si=si;
	}
	
}

