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.*;

public class main{
	static int MAX = 100010;
	static long mod = 998244353;
	static ArrayList<Integer>[]  bmp;
    static boolean b[];
    static Scanner sc = new Scanner(System.in);
    static ArrayList<Pair>[] amp = new ArrayList[200010];
    static int[] arr, parent, size;
	public static void main(String[] args){
		int n = sc.nextInt(), m = sc.nextInt();
        for(int i = 0; i<amp.length; i++) amp[i] = new ArrayList<>();
        for(int i = 0; i < n-1; i++){
            int x = sc.nextInt(), y = sc.nextInt(), z = sc.nextInt();
            amp[z].add(new Pair(x,y));
        }
        arr = new int[n+1];
        parent = new int[n+1];
        size = new int[n+1];
        Arrays.fill(size,1);
	    for(int i = 1; i<=n; i++){
            parent[i] = i;
        }
        long ans[] = new long[200010];
        for(int i = 1;i <=200000; i++){
            long val = 0;
            for(Pair p : amp[i]){
                int x = p.x, y = p.y;
                int a = findParent(x), b = findParent(y);
                parent[a] = b;
                val += size[a]*1l*size[b];
                size[b] += size[a];
                parent[x] = parent[y] = b;
            }
            ans[i] = ans[i-1] + val;
        }
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i<m; i++){
            sb.append(ans[sc.nextInt()]+" ");
        }
        System.out.println(sb);
    }

    static int findParent(int x){
        if(parent[x] == x){
            return x;
        }
        return parent[x] = findParent(parent[x]);
    }
    static long ncp(int k, int x){
        if(k<x) return 0;
        if(k==x) return 1;
        long ans = 1;
        for(int i = k; i>(k-x); i--){
            ans *= i;
            ans %= mod;
        }
        return ans;
    }

   

	static long pow(long x, int y, long mod){
		long ans = 1;
		while(y>0){
			if(y%2==0){
				x *= x;
				x %= mod;
				y/=2;
			}
			else{
				y-=1;
				ans *= x;
				ans %= mod;
			}
		}
		return ans;
	}
	static class Pair implements Comparable<Pair>{
		int x, y;
		Pair(int a, int b){
			x = a; y = b;
		}
        public int compareTo(Pair p){
            return -Integer.compare(this.y, p.y);
        }
	}
	public static int[] radixSort(int[] f){ return radixSort(f, f.length); }
	public static int[] radixSort(int[] f, int n)
	{
		int[] to = new int[n];
		{
			int[] b = new int[65537];
			for(int i = 0;i < n;i++)b[1+(f[i]&0xffff)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < n;i++)to[b[f[i]&0xffff]++] = f[i];
			int[] d = f; f = to;to = d;
		}
		{
			int[] b = new int[65537];
			for(int i = 0;i < n;i++)b[1+(f[i]>>>16)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];
			int[] d = f; f = to;to = d;
		}
		return f;
	}

}