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.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
public class realfast implements Runnable {
    private static final int INF = (int) 1e9;
    
    public  void solve() throws IOException 
    {
       
     int n = readInt();
     int m = readInt();
     Edge edge[]= new Edge[n-1];
     for(int i=0;i<n-1;i++)
     {
        int u = readInt();
        int v = readInt();
        int w = readInt();
        edge[i]= new Edge(u,v,w);
     }
     Arrays.sort(edge);
     query q[]= new query[m];
     for(int i =0;i<m;i++)
     {
        int a= readInt();
        q[i]= new query(a,i);
     }
      Arrays.sort(q);
      
           
      long fina[]= new long [m];
      int parent[]= new int [n+1];
      int size[]= new int [n+1];
      for(int i=1;i<=n;i++){
        parent[i]=i;
        size[i]=1;
      }
      int i =0;
      long change =0;
      for(int j=0;j<m;j++)
      {
        int val = q[j].m;
        int index= q[j].index;
        
        while(i<n-1&&edge[i].val<=val)
        {
              int u = edge[i].u;
              int v = edge[i].v;
              change = change+union(parent,size,u,v);
              
              i++;
        }
        fina[index]=change;
      }
      
      for(int j=0;j<m;j++)
        out.print(fina[j]+" ");

      

    }
    public static int find(int parent[], int i)
    {
        if(parent[i]==i)
            return i;
        parent[i]= find(parent,parent[i]);
       return parent[i];
    }
    public static long union(int parent[], int size[], int u, int v)
    {
         int par1 = find(parent,u);
         int par2 = find(parent,v);
         if(par1==par2)
         return 0;
         int size1= size[par1];
         int size2 = size[par2];
         long change = ncr(size1+size2)-ncr(size1)-ncr(size2);
         parent[par1]=par2;
         size[par2]=size[par1]+size[par2];
        return change;
    }

    public static long ncr(long n)
    {

        if(n<2)
            return 0;
        return (n*(n-1))/2;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static void main(String[] args) {
        new Thread(null, new realfast(), "", 128 * (1L << 20)).start();
    }
 
    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    private PrintWriter out;
 
    @Override
    public void run() {
        try {
            if (ONLINE_JUDGE || !new File("input.txt").exists()) {
                reader = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                reader = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            }
            solve();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                // nothing
            }
            out.close();
        }
    }
 
    private String readString() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
 
    @SuppressWarnings("unused")
    private int readInt() throws IOException {
        return Integer.parseInt(readString());
    }
 
    @SuppressWarnings("unused")
    private long readLong() throws IOException {
        return Long.parseLong(readString());
    }
 
    @SuppressWarnings("unused")
    private double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
}
class Edge implements Comparable<Edge>{
    int u ;
    int v ;
    int val;
    Edge(int u1, int v1 , int val1)
    {
       this.u=u1;
       this.v=v1;
       this.val=val1;
    }
    public int compareTo(Edge e)
    {
        return this.val-e.val;
    }
}
class query implements Comparable<query>
{
    int m;
    int index;
    query(int m ,int index)
    {
        this.m=m;
        this.index=index;

    }
    public int compareTo(query yo)
    {
         return this.m-yo.m;
    }
}