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

public class PathQueries {

	public static class Pair implements Comparable<Pair>{
		int id;
		int q;
		public Pair(int id,int q) {
			this.id=id;
			this.q=q;
		}
		
		public int compareTo(Pair x) {
			return this.q-x.q;
		}
		
	}
	
	public static class Triplet implements Comparable<Triplet>{
		int u;
		int v;
		int w;
		public Triplet(int u,int v,int w) {
			this.u=u;
			this.v=v;
			this.w=w;
		}
		
		public int compareTo(Triplet x) {
			return this.w-x.w;
		}
	}

	
	public static int[] parent;
	public static int[] size;
	
	public static void make_set(int v) {
		parent[v]=v;
		size[v]=1;
	}
	
	public static int find_set(int u) {
		if(parent[u]==u) {
			return u;
		}
		return parent[u]=find_set(parent[u]);
	}
	
	public static void Union_set(int u,int v) {
		if( u==v) {
			return;
		}
		if(size[u]>size[v]) {
			parent[v]=u;
			size[u]+=size[v];
		}else if(size[u]<=size[v]) {
			parent[u]=v;
			size[v]+=size[u];
		}
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		out = new PrintWriter(new BufferedOutputStream(System.out));
		FastReader s=new FastReader();
		int n=s.nextInt();
		parent=new int[n];
		size=new int[n];
		for(int i=0;i<n;i++) {
			make_set(i);
		}
		int m=s.nextInt();
		Triplet[] edges =new Triplet[n-1];
		for(int i=0;i<n-1;i++) {
			edges[i]=new Triplet(s.nextInt()-1,s.nextInt()-1,s.nextInt());
		}
		Arrays.sort(edges);
		Pair[] query=new Pair[m];
		for(int i=0;i<m;i++) {
			query[i]=new Pair(i,s.nextInt());
		}
		Arrays.sort(query);
		long[] ans =new long[m];
		int j=0;
		long a=0;
		for(int i=0;i<m;i++) {
			while(j<n-1 && edges[j].w<=query[i].q) {
				int k =edges[j].u;
				int t=edges[j].v;
				int u_=find_set(k);
				int v_=find_set(t);
				long u=size[u_];
				long v =size[v_];
				long sub= ((u*(u-1))/2)+((v*(v-1))/2);
				Union_set(u_,v_);
				a-=sub;
				long sum = u+v;
				a+= (sum*(sum-1))/2;
				j++;
			}
			ans[i]=a;
		}
		long[] finalans=new long[m];
		for(int i=0;i<m;i++) {
			finalans[query[i].id]=ans[i];
		}
		for(int i=0;i<m;i++) {
			out.print(finalans[i]+" ");
		}
		out.close();
	}

	public static PrintWriter out;
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			//InputStream reads the data and decodes in character stream
			//It acts as bridge between byte stream and character stream
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}
	
}
