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.*;
import java.util.*;
public class d3prac implements Runnable 
{
	private boolean console=false;

	int par[],size[]; long max; 
	public void solve() 
	{
		int i; int n=in.ni(); int q=in.ni(); edge a[]=new edge[n-1];par=new int[n]; size=new int [n]; long qu[][]=new long[q][3];
		for(i=0;i<n;i++)
		{
			par[i]=i; size[i]=1;
		}
		for(i=0;i<n-1;i++)
		{
			int u=in.ni()-1;  int v=in.ni()-1; int w=in.ni(); a[i]= new edge(u,v,w);
		}
		Arrays.sort(a, (p,r)-> p.w-r.w);
		for(i=0;i<q;i++)
		{
			qu[i][0]=in.ni(); qu[i][1]=i;
		}
		Arrays.sort(qu, (p,r)-> (int) (p[0]-r[0]));
		int k=0;
		for(i=0;i<q;i++)
		{
			while(k<n-1&&a[k].w<=qu[i][0])
			{
				union(a[k].u,a[k].v); k++;
			}
			qu[i][2]=max;
		}
		Arrays.sort(qu, (p,r)-> (int) (p[1]-r[1]));
		for(long val[]:qu)
		{
			out.print(val[2]+" ");
		}
	}
	public int find(int a)
	{
		return (par[a]==a)?a:(par[a]=find(par[a]));
	}
	public void union(int a,int b)
	{
		a=find(a); b=find(b);
		if(a==b) return;
		if(size[a]<size[b])
		{
			int t=a; a=b; b=t; 
		}
		par[b]=a;
		max-= calc(size[a]); max-= calc(size[b]);
		size[a]+=size[b]; max+= calc(size[a]);
	}
	long calc(long c)
	{
		return c*(c-1)/2;
	}
	@Override
	public void run() {
		try {  init();  } 
		catch (FileNotFoundException e) {  e.printStackTrace();   }

		int t= 1;

		while (t-->0) {
			solve();
			out.flush(); }
	}
	private FastInput in;    private PrintWriter out;
	public static void main(String[] args) throws Exception {	 new d3prac().run();	 }

	private void init() throws FileNotFoundException {
		InputStream inputStream = System.in; 	 OutputStream outputStream = System.out;
		try {  if (!console && System.getProperty("user.name").equals("sachan")) {
			outputStream = new FileOutputStream("/home/sachan/Desktop/output.txt");
			inputStream = new FileInputStream("/home/sachan/Desktop/input.txt");   	}
		}	catch (Exception ignored) {	}
		out = new PrintWriter(outputStream); 	 in = new FastInput(inputStream);
	}
	static class FastInput { InputStream obj;
	public FastInput(InputStream obj) {	this.obj = obj;	}
	byte inbuffer[] = new byte[1024];  int lenbuffer = 0, ptrbuffer = 0;
	int readByte() { if (lenbuffer == -1) throw new InputMismatchException();
	if (ptrbuffer >= lenbuffer) { ptrbuffer = 0;
	try { lenbuffer = obj.read(inbuffer);  }
	catch (IOException e) { throw new InputMismatchException(); } }    
	if (lenbuffer <= 0) return -1;return inbuffer[ptrbuffer++]; }

	String ns() { int b = skip();StringBuilder sb = new StringBuilder();
	while (!(isSpaceChar(b)))	  { sb.appendCodePoint(b);b = readByte(); }return sb.toString();}

	int ni() { int num = 0, b;boolean minus = false;
	while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	if (b == '-') { minus = true;b = readByte(); }
	while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else {
		return minus ? -num : num; }b = readByte(); }}

	long nl() { long num = 0;int b;boolean minus = false;
	while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	if (b == '-') { minus = true;b = readByte(); }
	while (true) { if (b >= '0' && b <= '9') { num = num * 10L + (b - '0'); } else {
		return minus ? -num : num; }b = readByte(); } }

	boolean isSpaceChar(int c) { return (!(c >= 33 && c <= 126)); }
	int skip() { int b;while ((b = readByte()) != -1 && isSpaceChar(b)) ;return b; }
	float nf() {return Float.parseFloat(ns());}
	double nd() {return Double.parseDouble(ns());}
	char nc() {return (char) skip();}
	}
}
class edge
{
	int u,v,w;
	edge(int u,int v,int w)
	{
		this.u=u; this.v=v; this.w=w;
	}
}
