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>
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
from bisect import bisect_left as bsl
n,m=map(int,input().split())
graph=[set([]) for s in range(n)]
weight=[]
for s in range(n-1):
    a,b,w=map(int,input().split())
    a-=1;b-=1
    weight.append((w,(min(a,b),max(a,b))))
    graph[a].add(b);graph[b].add(a)
weight.sort(key=lambda x: x[0])
group=list(range(n));count={}
def find(node):
    comp=[]
    while group[node]!=node:
        comp.append(node)
        node=group[node]
    for i in comp:
        group[i]=node
    return group[node]
ans=[];cumans=0
for s in range(n-1):
    w=weight[s][0];edge=weight[s][1]
    group1=find(edge[0]);group2=find(edge[1])
    if not(group1 in count):
        count[group1]=1
    if not(group2 in count):
        count[group2]=1
    cumans-=(count[group1]*(count[group1]-1))//2
    cumans-=(count[group2]*(count[group2]-1))//2
    if count[group1]<=count[group2]:
        count[group2]+=count[group1];count.pop(group1)
        cumans+=(count[group2]*(count[group2]-1))//2
        group[group1]=group2
    else:
        count[group1]+=count[group2];count.pop(group2)
        cumans+=(count[group1]*(count[group1]-1))//2
        group[group2]=group1
    if s>0 and weight[s-1][0]==weight[s][0]:
        ans[-1]=cumans
    else:
        ans.append(cumans)
queries=list(map(int,input().split()))
weights=list(set([x[0] for x in weight]));weights.sort()
if len(weights)==0:
    print(*[0 for s in range(m)])
else:
    out=[]
    for s in range(m):
        w=queries[s]
        ind=min(bsl(weights,w),len(weights)-1)
        if weights[ind]>w:
            ind-=1
        if ind==-1:
            out.append(0)
        else:
            out.append(ans[ind])
    print(*out)