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.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class G {

    static long compute(int groupSize) {
        return ((long) groupSize * (groupSize - 1)) / 2;
    }


    static class UnionFind {
        int[] p, rank, setSize;
        int numSets;

        public UnionFind(int N)
        {
            p = new int[numSets = N];
            rank = new int[N];
            setSize = new int[N];
            for (int i = 0; i < N; i++) {  p[i] = i; setSize[i] = 1; }
        }

        public int findSet(int i) { return p[i] == i ? i : (p[i] = findSet(p[i])); }

        public boolean isSameSet(int i, int j) { return findSet(i) == findSet(j); }

        public void unionSet(int i, int j)
        {
            if (isSameSet(i, j))
                return;
            numSets--;
            int x = findSet(i), y = findSet(j);
            if(rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
            else
            {	p[x] = y; setSize[y] += setSize[x];
                if(rank[x] == rank[y]) rank[y]++;
            }
        }

        public int numDisjointSets() { return numSets; }

        public int sizeOfSet(int i) { return setSize[findSet(i)]; }
    }

    static class Edge implements Comparable<Edge> {

        int from, to, weight;
        public Edge(int f, int t, int w) {
            from = f;
            to = t;
            weight = w;
        }

        @Override
        public int compareTo(Edge o) {
            return weight - o.weight;
        }
    }

    static class Query implements Comparable<Query> {
        int index, weight;
        Query(int i, int w) {
            index = i;
            weight = w;
        }

        @Override
        public int compareTo(Query o) {
            if (weight == o.weight)
                return index - o.index;
            return weight - o.weight;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt(), Q = sc.nextInt();
        Edge [] edges = new Edge[N - 1];
        Query[] queries = new Query[Q];
        UnionFind unionFind = new UnionFind(N);

        for (int i = 0; i < N - 1; ++i)
            edges[i] = new Edge(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt());

        for (int i = 0; i < Q; ++i)
            queries[i] = new Query(i, sc.nextInt());

        Arrays.sort(edges);
        Arrays.sort(queries);

        long [] answer = new long[Q];

        int pos = 0;
        long result = 0;

        for (int i = 0; i < Q; ++i) {
            int curW = queries[i].weight;

            while(pos < N - 1 && edges[pos].weight <= curW) {
                result += updateRes(edges[pos], unionFind);
                unionFind.unionSet(edges[pos].from, edges[pos].to);
                ++pos;
            }

            answer[queries[i].index] = result;
        }

        for (int i = 0; i < Q; ++i) {
            out.print(answer[i]);
            if (i != Q - 1) out.print(" ");
        }
        out.flush();
        out.close();
    }

    private static long updateRes(Edge edge, UnionFind uf) {
        int g1 = uf.sizeOfSet(edge.from), g2 = uf.sizeOfSet(edge.to);
        long result = compute(g1 + g2) - compute(g1) - compute(g2);
        return result;
    }
}
