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;
using ll = long long;
using ii = pair<int, int>;
using iii = array<int, 3>;
using vi = vector<int>;
template <typename InputIterator,
          typename T = typename iterator_traits<InputIterator>::value_type>
void read_n(InputIterator it, int n) {
  copy_n(istream_iterator<T>(cin), n, it);
}
template <typename InputIterator,
          typename T = typename iterator_traits<InputIterator>::value_type>
void write(InputIterator first, InputIterator last, const char *delim = "\n") {
  copy(first, last, ostream_iterator<T>(cout, delim));
}
struct DisjointSetUnion {
  using vi = vector<int>;
  using ll = long long;
  int n;
  ll ans = 0;
  vi parent, ssize;
  DisjointSetUnion(int n) : n(n) {
    parent.resize(n);
    ssize.resize(n, 1);
    for (int u = 0; u < n; ++u) parent[u] = u;
  }
  int find_set(int u) {
    if (u == parent[u]) return u;
    return (parent[u] = find_set(parent[u]));
  }
  inline ll contribution(ll m) { return (m * (m - 1)) / 2; }
  void union_sets(int u, int v) {
    u = find_set(u);
    v = find_set(v);
    if (u != v) {
      if (ssize[u] < ssize[v]) swap(u, v);
      ans -= contribution(ssize[v]);
      ans -= contribution(ssize[u]);
      ans += contribution(ssize[u] + ssize[v]);
      parent[v] = u;
      ssize[u] += ssize[v];
    }
  }
};
ll const INF = 1e16;
int main(void) {
  ios::sync_with_stdio(false), cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<iii> edges(n - 1);
  for (auto &[w, u, v] : edges) cin >> u >> v >> w, u--, v--;
  DisjointSetUnion dsu(n);
  vector<pair<int, ll>> ans = {{0, 0}};
  sort(begin(edges), end(edges));
  auto it = edges.begin();
  while (it != end(edges)) {
    auto it_temp = it;
    while (it_temp != end(edges) and it_temp->at(0) == it->at(0)) {
      dsu.union_sets(it_temp->at(1), it_temp->at(2));
      it_temp++;
    }
    ans.emplace_back(it->at(0), dsu.ans);
    it = it_temp;
  }
  while (m--) {
    int qi;
    cin >> qi;
    auto it = prev(upper_bound(begin(ans), end(ans), make_pair(qi, INF)));
    cout << it->second << " ";
  }
  cout << endl;
  return 0;
}