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>
from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
sys.setrecursionlimit(10000000)
if sys.version_info[0] < 3:
    from io import BytesIO as stream
else:
    from io import StringIO as stream
 
 
if sys.version_info[0] < 3:
    class dict(dict):
        """dict() -> new empty dictionary"""
        def items(self):
            """D.items() -> a set-like object providing a view on D's items"""
            return dict.iteritems(self)
 
        def keys(self):
            """D.keys() -> a set-like object providing a view on D's keys"""
            return dict.iterkeys(self)
 
        def values(self):
            """D.values() -> an object providing a view on D's values"""
            return dict.itervalues(self)
 
    input = raw_input
    range = xrange
 
    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip
 
 
def sync_with_stdio(sync=True):
    """Set whether the standard Python streams are allowed to buffer their I/O.
 
    Args:
        sync (bool, optional): The new synchronization setting.
 
    """
    global input, flush
 
    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')
 
        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

res=0
n,m=map(int,input().split())
dsu=[i for i in range(n)]
size=[1]*n
def find(x):
    global res
    while x!=dsu[x]:
        dsu[x]=dsu[dsu[x]]
        x=dsu[x]
    return x
def union(x,y):
    global res
    fx=find(x)
    fy=find(y)
    sfx=size[fx]
    sfy=size[fy]
    ts=sfx+sfy
    if fx==fy:
        return
    if sfx>sfy:
        res=res-(sfx*(sfx-1)//2)-(sfy*(sfy-1)//2)+(ts*(ts-1)//2)
        size[fx]+=size[fy]
        dsu[fy]=fx
        return
    else:
        res=res-(sfx*(sfx-1)//2)-(sfy*(sfy-1)//2)+(ts*(ts-1)//2)
        size[fy]+=size[fx]
        dsu[fx]=fy
        return

def main():
    edges=[]

    for i in range(n-1):
        a,b,c=map(int,input().split())
        edges.append([c,a-1,b-1])
    edges.sort()
    #dsu=[i for i in range(n)]
    #size=[1]*n
    q=[int(o) for o in input().split()]
    q1=[[q[i],i] for i in range(m)]
    q1=sorted(q1)
    j=0
    answer=[0]*m
    for i in range(m):
        while j<n-1 and edges[j][0]<=q1[i][0]:
            union(edges[j][1],edges[j][2])
            j+=1
        
        answer[q1[i][1]]=res
    print(*answer)

if __name__ == '__main__':
    sync_with_stdio(False)
    main()