Problem: 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>

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            Edge[] edges = new Edge[n - 1];
            for (int i = 0; i < n - 1; i++) {
                edges[i] = new Edge();
                edges[i].u = in.nextInt();
                edges[i].v = in.nextInt();
                edges[i].w = in.nextInt();
            }
            Query[] queries = new Query[m];
            for (int i = 0; i < m; i++) {
                queries[i] = new Query();
                queries[i].ind = i;
                queries[i].w = in.nextInt();
            }
            Arrays.sort(edges, Comparator.comparingInt((Edge f) -> f.w));
            Arrays.sort(queries, Comparator.comparingInt((Query f) -> f.w));
            long wQty = 0;
            DSU s = new DSU(n + 1);
            for (int i = 0, edgeInd = 0; i < m; i++) {
                while (edgeInd < edges.length && edges[edgeInd].w <= queries[i].w) {
                    wQty += s.getSize(edges[edgeInd].v) * s.getSize(edges[edgeInd].u);
                    s.union(edges[edgeInd].v, edges[edgeInd].u);
                    edgeInd++;
                }
                queries[i].ans = wQty;
            }
            Arrays.sort(queries, Comparator.comparingInt((Query f) -> f.ind));
            for (Query cur : queries) {
                out.print(cur.ans);
                out.print(' ');
            }
        }

    }

    static class DSU {
        private int[] parent;
        private int[] size;

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

        int find(int n) {
            if (parent[n] == n) return n;
            return parent[n] = find(parent[n]);
        }

        void union(int a, int b) {
            a = find(a);
            b = find(b);
            if (a != b) {
                parent[a] = b;
                size[b] += size[a];
            }
        }

        long getSize(int a) {
            return size[find(a)];
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class Edge {
        int u;
        int v;
        int w;

    }

    static class Query {
        int ind;
        int w;
        long ans;

    }
}