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 int mod = 1e9 + 7;
template <class T, class U>
inline void add_self(T &a, U b) {
  a += b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
}
template <class T, class U>
inline void min_self(T &x, U y) {
  if (y < x) x = y;
}
template <class T, class U>
inline void max_self(T &x, U y) {
  if (y > x) x = y;
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  cout << t;
  ;
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
template <class T, class U>
void print_m(const map<T, U> &m, int w = 3) {
  if (m.empty()) {
    cout << "Empty" << endl;
    return;
  }
  for (auto x : m) cout << "(" << x.first << ": " << x.second << ")," << endl;
  cout << endl;
}
template <class T, class U>
void debp(const pair<T, U> &pr, bool end_line = 1) {
  cout << "{" << pr.first << " " << pr.second << "}";
  cout << (end_line ? "\n" : ", ");
}
template <class T>
void print_vp(const T &vp, int sep_line = 0) {
  if (vp.empty()) {
    cout << "Empty" << endl;
    return;
  }
  if (!sep_line) cout << "{ ";
  for (auto x : vp) debp(x, sep_line);
  if (!sep_line) cout << "}\n";
  cout << endl;
}
template <typename T>
void print(const T &v, bool show_index = false) {
  int w = 2;
  if (show_index) {
    for (int i = 0; i < int((v).size()); i++) cout << setw(w) << i << " ";
    cout << endl;
  }
  for (auto &el : v) cout << setw(w) << el << " ";
  cout << endl;
}
template <typename T>
void print_vv(const T &vv) {
  if (int((vv).size()) == 0) {
    cout << "Empty" << endl;
    return;
  }
  int w = 3;
  cout << setw(w) << " ";
  for (int j = 0; j < int((*vv.begin()).size()); j++)
    cout << setw(w) << j << " ";
  cout << endl;
  int i = 0;
  for (auto &v : vv) {
    cout << i++ << " {";
    for (auto &el : v) cout << setw(w) << el << " ";
    cout << "},\n";
  }
  cout << endl;
}
class DisjointSet {
 public:
  vector<int> par, ranks;
  void make_sets(int n) {
    par.clear();
    par.resize(n);
    ranks.clear();
    ranks.resize(n, 1);
    iota(par.begin(), par.end(), 0);
  }
  bool union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a == b) return false;
    if (ranks[a] < ranks[b]) swap(a, b);
    par[b] = a;
    ranks[a] += ranks[b];
    return true;
  };
  int find_set(int a) {
    if (a == par[a]) return a;
    return par[a] = find_set(par[a]);
  }
};
const int nax = 2e5 + 10;
int n, m, u, v, w, q;
vector<pair<int, pair<int, int>>> edges;
vector<long long> ans(nax);
long long nc2(long long s) {
  if (s < 2) return 0;
  return (s * (s - 1)) / 2;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < int(n - 1); i++) {
    cin >> u >> v >> w;
    edges.push_back({w, {u, v}});
  }
  DisjointSet ds;
  ds.make_sets(nax);
  long long tot = 0;
  sort(edges.begin(), edges.end());
  int i = 0;
  for (; i < n - 1; ++i) {
    int j = i;
    while (j < n - 1 && edges[i].first == edges[j].first) {
      int a = edges[j].second.first;
      int b = edges[j].second.second;
      a = ds.find_set(a), b = ds.find_set(b);
      long long old_a_sz = nc2(ds.ranks[a]);
      long long old_b_sz = nc2(ds.ranks[b]);
      ds.union_sets(a, b);
      int par = ds.find_set(a);
      long long new_sz_combined = nc2(ds.ranks[par]);
      tot += new_sz_combined - old_a_sz - old_b_sz;
      ++j;
    }
    i = j - 1;
    ans[edges[i].first] = tot;
  }
  for (int i = int(1); i < int(n + 1); i++) {
    if (!ans[i]) ans[i] = ans[i - 1];
  }
  for (int i = 0; i < int(m); i++) {
    cin >> q;
    cout << ans[q] << " ";
  }
  cout << endl;
  return 0;
}