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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int d8x[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int d8y[] = {0, 1, 1, 1, 0, -1, -1, -1};
template <typename T>
inline T GCD(T a, T b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
template <typename T>
inline T EGCD(T a, T b, T &x, T &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  T x1, y1;
  T d = EGCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
template <typename T>
inline T LCM(T x, T y) {
  T tp = GCD(x, y);
  if ((x / tp) * 1. * y > 9e18) return 9e18;
  return (x / tp) * y;
}
template <typename T>
inline T BigMod(T A, T B) {
  T ret = 1;
  while (B) {
    if (B & 1) ret = (ret * A) % 1000000007;
    A = (A * A) % 1000000007;
    B = B >> 1;
  }
  return ret;
}
template <typename T>
inline T InvMod(T A, T M = 1000000007) {
  return BigMod(A, M - 2);
}
int n, k;
int dp[202][202];
int child[202], nxt[202], a[202];
vector<int> g[202];
void dfs(int u, int par) {
  int last;
  for (int v : g[u]) {
    if (v == par) continue;
    if (!child[u]) {
      child[u] = v;
      last = v;
    } else {
      nxt[last] = v;
      last = v;
    }
    dfs(v, u);
  }
}
int call(int u, int rem) {
  if (!u) return 0;
  if (dp[u][rem] != -1) return dp[u][rem];
  int res = 0;
  int tmp = 0;
  if (!rem) {
    tmp = a[u];
    tmp += call(child[u], k);
    if (nxt[u]) {
      tmp += call(nxt[u], k - 1);
    }
  }
  for (int i = max(rem - 1, 0); i <= k; i++) {
    int givenTochild = call(child[u], i);
    if (nxt[u]) {
      givenTochild += call(nxt[u], max(rem, k - i - 2));
    }
    res = max(res, givenTochild);
  }
  res = max(res, tmp);
  return dp[u][rem] = res;
}
int main(void) {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d", &n, &k);
  int i;
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (i = 1; i <= n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, -1);
  int ans = call(1, 0);
  printf("%d\n", ans);
  return 0;
}