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

public class Main {
    public static class edge{
        int u;
        int v;
        long w;
        public edge(int u,int v,long w){
            this.u=u;
            this.v=v;
            this.w=w;
        }
    }

    public static class unionSet{
        int[] father;
        long[] rank;
        public unionSet(int n){
            father=new int[n];
            rank=new long[n];
            for (int i = 0; i < n; i++) {
                father[i]=i;
                rank[i]=1L;
            }
        }

        int find(int x){
            if(x == father[x]) {
                return x;
            }else{
                father[x] = find(father[x]);
                return father[x];
            }
        }

        void union(int x,int y){
            int fa_x=find(x);
            int fa_y=find(y);
            father[fa_x]=fa_y;
            rank[fa_y]=rank[fa_y]+rank[fa_x];
        }
    }

    private static long Combination(long n, long k) {
        long a=1,b=1;
        if(k>n/2) {
            k=n-k;
        }
        for(long i=1;i<=k;i++) {
            a*=(n+1-i);
            b*=i;
        }
        return a/b;
    }

    public static void main(String[] args) throws IOException {
        Reader in=new Reader();//"/Users/brooklyn/Downloads/lab10b_cases/case0.in");
        PrintWriter out=new PrintWriter(System.out);
        int n=in.nextInt();
        int m=in.nextInt();
        long max=0L;
        unionSet UnionSet=new unionSet(n);
        long[] result=new long[n+1];
        PriorityQueue<edge> heap=new PriorityQueue<>(new Comparator<edge>() {
            @Override
            public int compare(edge o1, edge o2) {
                if(o1.w>o2.w){
                    return 1;
                }else if(o1.w<o2.w){
                    return -1;
                }else{
                    return 0;
                }
            }
        });
        for (int i = 0; i < n-1; i++) {
            int u=in.nextInt();
            int v=in.nextInt();
            long w=in.nextLong();
            max=Math.max(max,w);
            edge Edge=new edge(u-1,v-1,w);
            heap.add(Edge);
        }
        for (int i = 0; i < n+1; i++) {
            result[i]=0L;
        }
        while(!heap.isEmpty()){
            edge Edge=heap.poll();
            int fa_u=UnionSet.find(Edge.u);
            int fa_v=UnionSet.find(Edge.v);
            if(fa_u!=fa_v){
                result[(int)Edge.w]+=UnionSet.rank[fa_u]*UnionSet.rank[fa_v];
                UnionSet.union(Edge.u,Edge.v);
            }
        }
        for (int i = 1; i < n+1; i++) {
            result[i]+=result[i-1];
        }
        if(n==1){
            for (int i = 0; i <m ; i++) {
                int query=in.nextInt();
                out.print(0+" ");
            }
        }else{
            long maxNumber=Combination(n,2);
            for (int i = 0; i < m; i++) {
                int query=in.nextInt();
                if(query>=max){
                    out.print(maxNumber+" ");
                }else{
                    out.print(result[query]+" ");
                }
            }
        }
        out.close();
    }

    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

}

