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:

// Imports
import java.util.*;
import java.io.*;

public class G1213 {

    static int[] parent;
    static int[] size;
    static long res;
    
    public static int find(int a) {
        if(parent[a] != a) {
            parent[a] = find(parent[a]);
        }
        
        return parent[a];
    }
    
    public static void union(int a, int b) {
        int x = find(a);
        int y = find(b);
 
        if(x == y)
            return;
        
        if(size[x] < size[y]) {
            int temp = x;
            x = y;
            y = temp;
        }
        
        res -= size[x]*1L*(size[x] - 1)/2;
        res -= size[y]*1L*(size[y] - 1)/2;
        
        parent[y] = x;
        size[x] += size[y];
        
        res += size[x]*1L*(size[x] - 1)/2;
    }
    
    public static class Pair {
        public int first;
        public int second;
        public Pair(int f, int s) {
            first = f;
            second = s;
        }
        
        @Override
        public String toString() {
            return "{" + this.first + ", " + this.second + "}";
        }
    }
    
    /**
     * @param args the command line arguments
     * @throws IOException, FileNotFoundException 
     * @throws java.io.FileNotFoundException 
     */
    public static void main(String[] args) throws IOException, FileNotFoundException {
        
        // TODO UNCOMMENT WHEN ALGORITHM CORRECT
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        
        /* BufferedReader f = new BufferedReader(new StringReader("7 5\n" +
"1 2 1\n" +
"3 2 3\n" +
"2 4 1\n" +
"4 5 2\n" +
"5 7 4\n" +
"3 6 2\n" +
"5 2 3 4 1")); */
        
        res = 0;
        
        // TODO code application logic here
        StringTokenizer st = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        
        parent = new int[n];
        size = new int[n];
        long[] a = new long[k];
        
        TreeMap<Integer, List<Pair>> insert = new TreeMap<>();
        for(int i = 0; i < n - 1; i++) {
            StringTokenizer edge = new StringTokenizer(f.readLine());
            int start = Integer.parseInt(edge.nextToken()) - 1;
            int end = Integer.parseInt(edge.nextToken()) - 1;
            int weight = Integer.parseInt(edge.nextToken());
            
            if(insert.containsKey(weight)) {
                insert.get(weight).add(new Pair(start, end));
            }
            else {
                ArrayList<Pair> temp = new ArrayList<>();
                temp.add(new Pair(start, end));
                insert.put(weight, temp);
            }
        }
        
        for(int j = 0; j < n; j++) {
            parent[j] = j;
            size[j] = 1;
        }
        
        int[][] queries = new int[k][2];
        StringTokenizer q = new StringTokenizer(f.readLine());
        for(int i = 0; i < k; i++) {
            queries[i][0] = Integer.parseInt(q.nextToken());
            queries[i][1] = i;
        }
        
        
        Arrays.sort(queries, (int[] o1, int[] o2) -> {
            if(o1[0] > o2[0]) {
                return 1;
            }
            else if(o2[0] > o1[0]) {
                return -1;
            }
            else {
                return 0;
            }
        });
        
        int current = 0;
        for(int num : insert.keySet()) {
            while(num > queries[current][0]) {
                // run the query
                a[queries[current][1]] = res;
                current++;
                
                if(current == k) {
                    break;
                }
            }
            
            
            if(current == k) {
                break;
            }
            
            insert.get(num).forEach((i) -> {
                union(i.first, i.second);
            });
        }
        
        
        for(int i = current; i < k; i++) {
            a[queries[i][1]] = res;
        }
        
        // System.out.println(Arrays.deepToString(queries));
        StringBuilder ans = new StringBuilder();
        for(int i = 0; i < k; i++) {
            ans.append(a[i]);
            ans.append(" ");
        }
        System.out.println(ans.substring(0, ans.length() - 1));
        
    }

}