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;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
  return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " +
         to_string(get<2>(t)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
  return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " +
         to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}
template <typename A>
string to_string(vector<A> v) {
  bool first = true;
  string result = "[";
  for (A i : v) {
    if (!first) result += ", ";
    first = false;
    result += to_string(i);
  }
  return result + "]";
}
template <typename A>
string to_string(A x[], long long n) {
  string result = "{";
  for (long long i = (0); i < (n); ++i) {
    if (i != 0) result += ", ";
    result += to_string(x[i]);
  }
  return result + "}";
}
string bin_string(long long x) {
  const long long d = 64;
  string result(d, ' ');
  for (long long i = (d - 1); i < (-1); ++i)
    result[d - 1 - i] = '0' + ((x & 1LL << i) != 0);
  return result;
}
vector<long long> getZ(string s) {
  long long n = s.size();
  vector<long long> z(n);
  long long x = 0, y = 0;
  for (long long i = (1); i < (n); ++i) {
    z[i] = max(0LL, min(z[i - x], y - i + 1));
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
      x = i;
      y = i + z[i];
      ++z[i];
    }
  }
  return z;
}
long long powa(long long base, long long exp) {
  if (exp <= 0) return 1;
  if (base <= 0) return 0;
  long long val = powa(base, exp >> 1);
  val = val * val % MOD;
  if (exp & 1) {
    val = val * base % MOD;
  }
  return val;
}
const long long BIGN = 300;
long long weight[BIGN];
long long n, k;
vector<long long> nodes[BIGN];
vector<long long> solve(long long cur, long long avoid) {
  vector<long long> res(k);
  vector<vector<long long>> prevs;
  for (long long neighbour : nodes[cur])
    if (neighbour != avoid) prevs.push_back(solve(neighbour, cur));
  for (long long d = (k - 1); d > (0); --d) {
    long long upp = prevs.size() <= 2 ? k - 1 : (k - 2) / 2 + 1;
    long long e = d - 1;
    while (true) {
      long long alt = max(d - 1, k - 2 - e);
      if (prevs.size() >= 3 && alt + alt + 2 < k) break;
      for (long long elev = (0); elev < (prevs.size()); ++elev) {
        long long ans = 0;
        for (long long neighbour = (0); neighbour < (prevs.size());
             ++neighbour) {
          long long oldans = ans;
          if (neighbour == elev)
            ans += prevs[neighbour][e];
          else
            ans += prevs[neighbour][alt];
        }
        res[d] = max(res[d], ans);
      }
      if (prevs.size() == 1 || alt == d - 1) break;
      ++e;
    }
    if (d != k - 1) res[d] = max(res[d], res[d + 1]);
  }
  long long ans = weight[cur];
  for (long long neighbour = (0); neighbour < (prevs.size()); ++neighbour)
    ans += prevs[neighbour][k - 1];
  res[0] = max(res[1], ans);
  return res;
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (long long i = (1); i < (n + 1); ++i) cin >> weight[i];
  for (long long i = (0); i < (n - 1); ++i) {
    long long a, b;
    cin >> a >> b;
    nodes[a].push_back(b);
    nodes[b].push_back(a);
  }
  ++k;
  vector<long long> res = solve(1, -1);
  cout << res[0];
}