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.*;
import java.math.BigInteger;
 public class Task{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
static int gcd(int a,int b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}

//sort map w.r.t value use-> TreeSet of array? write comparator which depends on all the entries of array otherwise weired behavior you can prove it.
//......................................@uthor_Alx..............................................
   static int[] parent;
   static int[] size;
   static void make_set(int a){
        parent[a]=a;
        size[a]=1;
   }
   static int find_set(int a){
        if(parent[a]==a) return a;
        return parent[a]=find_set(parent[a]);
   } 
   static void union(int a, int b){
        a=find_set(a);
        b=find_set(b);
        if(a==b) return ;
        if(size[b]>size[a]){
            a^=b;b^=a;a^=b;
        }
        size[a]+=size[b];
        parent[b]=a;
   }
   static int f(int[] a, int[] b){
        if(a[2]==b[2]) return b[1]-a[1];
        return a[2]-b[2];
   }
   static long g(int n){
        long kk= (long)n*(n-1);
        return kk/2;
   }
   public static void main(String[] args) throws  IOException{
                assign();
                int t=1;//int_v(read());//1;//,cn=1;
                while(t--!=0){
                    int[] z=int_arr();
                    int n=z[0],m=z[1];
                    int[][] a=new int[n-1+m][3];
                    for(int i=0;i<n-1;i++) a[i]=int_arr();
                    int[] q=int_arr();
                    for(int i=n-1;i<m+n-1;i++){
                        a[i][2]=q[i-n+1];
                        a[i][0]=i-n+1;
                    }
                    long[] res= new long[m];
                    Arrays.sort(a,(x,y)->f(x,y));
                    parent=new int[n+1];
                    size=new int[n+1];
                    long tmp=0;
                    for(int i=1;i<=n;i++) make_set(i);
                    for(int i=0;i<n-1+m;i++){
                        if(a[i][1]!=0){
                            int x=a[i][0],y=a[i][1],w=a[i][2];
                            x=find_set(x); y=find_set(y);
                            tmp+=(long)size[x]*size[y];
                            union(x,y);
                        }
                        else{
                            res[a[i][0]]=tmp;
                        }
                    }
                    for(long x:res) out.write(x+" ");
                }
                    out.flush();

    }
}
             