Problem: 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>

Solution (in JAVA):

Solution:
//package code;
import java.io.*;
import java.util.*;

public class c 
{
    public static int t, n ,m, a[], b[], parent[] , size[];
    static long ans=0;
    public static Edge[] edge;
    public static pair[] p;
    public static PrintWriter pw;
    public  static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    public static int max1=2000005;
    public static void main(String[]sd)throws IOException
    {
        Scanner sc = new Scanner(System.in);
		pw = new PrintWriter(System.out);
        n=sc.nextInt();
        m=sc.nextInt();
        p=new pair[m];
        edge=new Edge[n-1];
        parent=new int[n];
        size=new int[n];
        for(int i=0;i<n;i++)
        {
        	size[i]=1;
        	parent[i]=i;
        }
        for(int i=0;i<n-1;i++)
        {
        	int u=sc.nextInt()-1;
        	int v=sc.nextInt()-1;
        	int w=sc.nextInt();
        	edge[i]=new Edge(u,v,w);
        }

        Arrays.sort(edge , (e1,e2)->e1.weight-e2.weight);

        for(int i=0;i<m;i++)
        {
        	p[i]=new pair(sc.nextInt() , i);
        }
        Arrays.sort(p,(p1,p2)->p1.val-p2.val);
        //pw.println(p[0].val + " "+ p[0].indx);
        long[] an=new long[m];
        int pos=0;
        for(int i=0;i<m;i++)
        {
        	while(pos<n-1&&edge[pos].weight<=p[i].val)
        	{
        		merge(edge[pos].x, edge[pos].y);
        		pos++;
        	}
        	an[p[i].indx]=ans;
        }
        for(int i=0;i<m;i++)pw.print(an[i]+" ");
      pw.close();
    }
    static int root(int x)
    {
    	if(x==parent[x])return x;
    	else return parent[x]=root(parent[x]);
    }
    static void merge(int x1, int y1)
    {
    	int x=root(x1);
    	int y=root(y1);
    	if(size[x]<size[y])
    	{
    		int temp=x;
    		x=y;
    		y=temp;
    	}
    	ans-=countPair(size[x]);
    	ans-=countPair(size[y]);
    	size[x]+=size[y];
    	ans+=countPair(size[x]);
    	parent[y]=x;

    }
    public static class pair{
    	int val , indx;
      public  pair(int val, int indx)
        {
        	this.val=val;
        	this.indx=indx;
        }
    }
    public static class Edge{
    	int x , y, weight;
    	Edge(int x,int y, int weight)
    	{
    		this.x=x;
    		this.y=y;
    		this.weight=weight;
    	}
    }
    static long countPair(int size)
    {
    	return size*1l*(size-1)/2;
    }
   

}