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.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.Random;
import java.util.Comparator;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        GPathQueries solver = new GPathQueries();
        solver.solve(1, in, out);
        out.close();
    }

    static class GPathQueries {
        long ans = 0;
        int n;
        int[] disjointArray;
        int[] size;

        private void inititalise() {
            disjointArray = new int[n + 1];
            size = new int[n + 1];
            Arrays.fill(size, 1);
            for (int i = 0; i <= n; i++) disjointArray[i] = i;
        }

        private int findRoot(int node) {
            while (disjointArray[node] != node) {
                disjointArray[node] = disjointArray[disjointArray[node]];
                node = disjointArray[node];
            }
            return node;
        }

        private void union(int a, int b) {
            int a_root = findRoot(a);
            int b_root = findRoot(b);
            if (a_root != b_root) {
                ans += (((long) size[a_root]) * size[b_root]);
                if (size[a_root] < size[b_root]) {
                    disjointArray[a_root] = disjointArray[b_root];
                    size[b_root] += size[a_root];
                } else {
                    disjointArray[b_root] = disjointArray[a_root];
                    size[a_root] += size[b_root];
                }
            }
        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            n = in.scanInt();
            int m = in.scanInt();
            inititalise();
            int[][] edges = new int[n - 1][3];
            for (int i = 0; i < n - 1; i++) {
                edges[i][0] = in.scanInt();
                edges[i][1] = in.scanInt();
                edges[i][2] = in.scanInt();
            }
            CodeHash.shuffle(edges);
            Arrays.sort(edges, new Comparator<int[]>() {

                public int compare(int[] o1, int[] o2) {
                    return o1[2] - o2[2];
                }
            });
            int[][] q = new int[m][2];
            for (int i = 0; i < m; i++) {
                q[i][0] = in.scanInt();
                q[i][1] = i;
            }
            CodeHash.shuffle(q);
            Arrays.sort(q, new Comparator<int[]>() {

                public int compare(int[] o1, int[] o2) {
                    if (o1[0] == o2[0]) return o1[1] - o2[1];
                    return o1[0] - o2[0];
                }
            });
            long[] anss = new long[m];
            int ptr = 0;
            for (int i = 0; i < m; i++) {
                while (ptr < n - 1 && edges[ptr][2] <= q[i][0]) {
                    union(edges[ptr][0], edges[ptr][1]);
                    ptr++;
                }
                anss[q[i][1]] = ans;
            }
            for (long i : anss) out.print(i + " ");


        }

    }

    static class CodeHash {
        public static void shuffle(int[][] ar) {
            Random rd = new Random(new Random().nextInt());
            for (int i = 0; i < ar.length; i++) {
                int index = rd.nextInt(ar.length);
                int[] temp = ar[i];
                ar[i] = ar[index];
                ar[index] = temp;
            }
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

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

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}

