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 double eps = 1e-7;
const long long int maxn = 2e5 + 6;
long long int pr[maxn];
long long int n, m;
long long int sum = 0;
vector<pair<long long int, long long int> > adj[maxn];
set<long long int> weight;
class dsuClass {
 public:
  long long int n;
  vector<long long int> parent;
  vector<long long int> size;
  long long int sccCount;
  void init(long long int n) {
    this->n = n;
    parent.resize(n);
    size.resize(n);
    reset();
  }
  void reset() {
    sccCount = n;
    for (long long int i = 0; i < n; i++) parent[i] = i;
    for (long long int i = 0; i < n; i++) size[i] = 1;
  }
  long long int update(long long int a) {
    if (parent[a] == a) return a;
    return parent[a] = update(parent[a]);
  }
  void join(long long int a, long long int b) {
    a = update(a);
    b = update(b);
    if (size[b] > size[a]) swap(a, b);
    if (a == b) return;
    size[a] += size[b];
    parent[b] = a;
    sccCount--;
  }
  long long int _size(long long int a) {
    a = update(a);
    return size[a];
  }
  bool isMaster(long long int v) { return parent[v] == v; }
  void updateAll() {
    for (long long int i = 0; i < n; i++) update(i);
  }
};
long long int val[maxn];
long long int cnt(long long int num) { return ((num - 1) * num) / 2; }
int main() {
  cin >> n >> m;
  for (long long int i = 0; i < n - 1; i++) {
    long long int a, b, c;
    cin >> a >> b >> c;
    adj[c].push_back({a, b});
    weight.insert(c);
  }
  dsuClass dsu;
  dsu.init(n + 9);
  for (long long int eg : weight) {
    for (pair<long long int, long long int> p : adj[eg]) {
      long long int a, b;
      a = p.first, b = p.second;
      long long int s1 = dsu._size(a);
      long long int s2 = dsu._size(b);
      dsu.join(a, b);
      sum -= cnt(s1) + cnt(s2);
      long long int s3 = dsu._size(a);
      sum += cnt(s3);
    }
    val[eg] = sum;
  }
  for (long long int i = 1; i < maxn; i++) {
    val[i] = max(val[i - 1], val[i]);
  }
  while (m--) {
    long long int k;
    cin >> k;
    cout << val[k] << ' ';
  }
  cout << "\n";
}