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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author sarthakmanna
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        FastWriter out = new FastWriter(outputStream);
        GPathQueries solver = new GPathQueries();
        solver.solve(1, in, out);
        out.close();
    }

    static class GPathQueries {
        int N;
        int Q;
        int[][] edges;
        long[][] queries;
        long pairCount;
        int[] parent;
        int[] size;

        public void solve(int testNumber, FastReader in, FastWriter out) {
            int i, j, k;

            N = in.nextInt();
            Q = in.nextInt();
            edges = new int[N - 1][];
            for (i = 0; i < N - 1; ++i) {
                int a = in.nextInt() - 1, b = in.nextInt() - 1, w = in.nextInt();
                edges[i] = new int[]{a, b, w};
            }
            Arrays.sort(edges, (a, b) -> Integer.compare(a[2], b[2]));

            queries = new long[Q][];
            for (i = 0; i < Q; ++i) queries[i] = new long[]{i, in.nextInt(), -7};
            Arrays.sort(queries, (a, b) -> Long.compare(a[1], b[1]));

            parent = new int[N];
            Arrays.fill(parent, -7);
            size = new int[N];
            Arrays.fill(size, 1);

            int p = 0;
            for (long[] q : queries) {
                while (p < N - 1 && edges[p][2] <= q[1]) {
                    int a = edges[p][0], b = edges[p][1];
                    ++p;
                    join(a, b);
                }
                q[2] = pairCount;
            }

            Arrays.sort(queries, (a, b) -> Long.compare(a[0], b[0]));
            for (long[] q : queries) out.printsp(q[2]);
            out.println();

            out.flush();
        }

        void join(int a, int b) {
            a = findParent(a);
            b = findParent(b);
            if (size[a] < size[b]) {
                a ^= b;
                b ^= a;
                a ^= b;
            }

            pairCount -= calc(size[a]) + calc(size[b]);
            parent[b] = a;
            size[a] += size[b];
            pairCount += calc(size[a]);
        }

        int findParent(int node) {
            int par = node;
            while (parent[par] >= 0) par = parent[par];
            while (parent[node] >= 0) {
                int temp = parent[node];
                parent[node] = par;
                node = temp;
            }
            return par;
        }

        long calc(long v) {
            return v * (v - 1) >> 1;
        }

    }

    static class FastReader {
        static private byte[] buf = new byte[2048];
        static private int index;
        static private int total;
        static private InputStream in;

        public FastReader(InputStream is) {
            try {
                in = is;
            } catch (Exception e) {
            }
        }

        private int scan() {
            try {
                if (index >= total) {
                    index = 0;
                    total = in.read(buf);
                    if (total <= 0)
                        return -1;
                }
                return buf[index++];
            } catch (Exception e) {
                return 7 / 0;
            }
        }

        public int nextInt() {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+')
                c = scan();
            for (; c >= '0' && c <= '9'; c = scan())
                val = (val << 3) + (val << 1) + (c & 15);
            return neg ? -val : val;
        }

    }

    static class FastWriter {
        static private BufferedWriter bw;

        public FastWriter(OutputStream os) {
            bw = new BufferedWriter(new OutputStreamWriter(os));
        }

        public FastWriter(Writer w) {
            bw = new BufferedWriter(w);
        }

        public void print(Object a) {
            try {
                bw.write(a.toString());
            } catch (Exception e) {
            }
        }

        public void println() {
            print("\n");
        }

        public void printsp(Object a) {
            print(a);
            print(" ");
        }

        public void flush() {
            try {
                bw.flush();
            } catch (Exception e) {
            }
        }

        public void close() {
            try {
                bw.close();
            } catch (Exception e) {
            }
        }

    }
}

