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.PrintWriter;
import java.util.Arrays;
import java.util.TreeMap;
import java.util.Map.Entry;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class GPathQueries {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int n = s.nextInt();
            int q = s.nextInt();
            GPathQueries.triplet[] arr = new GPathQueries.triplet[n - 1];
            for (int i = 0; i < n - 1; i++) {
                arr[i] = new GPathQueries.triplet(s.nextInt() - 1, s.nextInt() - 1, s.nextLong());
            }

            GPathQueries.UnionFindDisjointSet ufs = new GPathQueries.UnionFindDisjointSet(n);
            Arrays.sort(arr);
            TreeMap<Long, Long> solution = new TreeMap<>();

            long ans = 0;
            int i = 0;
            while (i < n - 1) {
                int j = i;
                while (j < n - 1 && arr[j].wt == arr[i].wt) {
                    int src = arr[j].src;
                    int dest = arr[j].dest;
                    long s1 = ufs.size[ufs.root(src)];
                    long s2 = ufs.size[ufs.root(dest)];
                    ufs.union(arr[j].src, arr[j].dest);
                    long a = (s1 * (s1 - 1)) / 2;
                    long b = (s2 * (s2 - 1)) / 2;
                    long c = ((s1 + s2) * (s1 + s2 - 1)) / 2;
                    ans = ans - a - b + c;
                    j++;
                }

                solution.put(arr[i].wt, ans);
                i = j;
            }


//        out.println(ans);
            while (q-- > 0) {
                long query = s.nextLong();
                if (solution.floorEntry(query) == null) {
                    out.println(0);
                } else {
                    out.println(solution.floorEntry(query).getValue());
                }

            }
        }

        private static class triplet implements Comparable<GPathQueries.triplet> {
            int src;
            int dest;
            long wt;

            public triplet(int src, int dest, long wt) {
                this.src = src;
                this.dest = dest;
                this.wt = wt;
            }

            public int compareTo(GPathQueries.triplet o) {
                return Long.compare(this.wt, o.wt);
            }

        }

        private static class UnionFindDisjointSet {
            int[] parent;
            int[] size;
            int n;
            int size1;

            public UnionFindDisjointSet(int n) {
                this.n = n;
                this.parent = new int[n];
                this.size = new int[n];
                for (int i = 0; i < n; i++) {
                    parent[i] = i;
                }

                for (int i = 0; i < n; i++) {
                    size[i] = 1;
                }

                this.size1 = n;
            }

            private int root(int b) {
                if (parent[b] != b) {
                    return parent[b] = root(parent[b]);
                }
                return b;
            }

            private void union(int a, int b) {
                int rootA = root(a);
                int rootB = root(b);
                if (rootA == rootB) {
                    return;
                }

                if (size[rootA] < size[rootB]) {
                    parent[rootA] = parent[rootB];
                    size[rootB] += size[rootA];
                    size[rootA] = size[rootB];
                } else {
                    parent[rootB] = parent[rootA];
                    size[rootA] += size[rootB];
                    size[rootB] = size[rootA];
                }
                size1--;
//            System.out.println(Arrays.toString(parent));
            }

        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

