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 int MAXN = 2e5 + 5;
long long int par[MAXN];
long long int rnk[MAXN];
long long int total[MAXN];
long long int getPar(long long int x) {
  if (x == par[x]) return x;
  par[x] = getPar(par[x]);
  return par[x];
}
void unite(long long int x, long long int y) {
  long long int x1 = getPar(x);
  long long int x2 = getPar(y);
  if (rnk[x1] > rnk[x2]) {
    par[x2] = x1;
    total[x1] += total[x2];
  } else if (rnk[x1] < rnk[x2]) {
    par[x1] = x2;
    total[x2] += total[x1];
  } else {
    rnk[x1]++;
    par[x2] = x1;
    total[x1] += total[x2];
  }
}
bool check(int x, int y) { return getPar(x) == getPar(y); }
void initialize(long long int n) {
  for (long long int i = 0; i < n + 1; i++) {
    par[i] = i;
    rnk[i] = 0;
    total[i] = 1;
  }
}
vector<pair<long long int, long long int> > graph[MAXN];
pair<long long int, pair<long long int, long long int> > edges[MAXN];
bool compare(pair<long long int, pair<long long int, long long int> > p1,
             pair<long long int, pair<long long int, long long int> > p2) {
  return p1.second.second < p2.second.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  initialize(n);
  long long int queries;
  cin >> queries;
  if (n == 1) {
    while (queries--) {
      long long int qii;
      cin >> qii;
      cout << 0 << " ";
    }
    return 0;
  }
  for (long long int i = 0; i < n - 1; i++) {
    long long int u, v, w;
    cin >> u >> v >> w;
    edges[i].first = u;
    edges[i].second = {v, w};
  }
  sort(edges, edges + n - 1, compare);
  vector<long long int> weights;
  for (long long int i = 0; i < n - 1; i++) {
    weights.push_back(edges[i].second.second);
  }
  long long int arr[n - 1];
  for (long long int i = 0; i < n - 1; i++) arr[i] = 0;
  for (long long int i = 0; i < n - 1; i++) {
    if (i == 0) {
      arr[i] = 1;
      unite(edges[i].first, edges[i].second.first);
    } else {
      arr[i] += arr[i - 1];
      long long int u = edges[i].first;
      long long int v = edges[i].second.first;
      arr[i] += (total[getPar(u)] * total[getPar(v)]);
      unite(u, v);
    }
  }
  while (queries--) {
    long long int qi;
    cin >> qi;
    auto it = upper_bound(weights.begin(), weights.end(), qi);
    if (it == weights.end()) {
      cout << arr[n - 2] << " ";
    } else {
      long long int ind = it - weights.begin();
      if (weights[ind] != qi) {
        ind--;
      }
      if (ind < 0) {
        cout << 0 << " ";
      } else
        cout << arr[ind] << " ";
    }
  }
  return 0;
}