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 JAVA):

Solution:
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;

public class Solution {

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

		public InputReader(InputStream st) {
			this.stream = st;
		}

		public int read() {
			if (snumChars == -1) {
				throw new InputMismatchException();
			}
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				}
				catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}

	static int[] id;
	static int[] sizes;
	static long[] answers;
	static long ans;

	static int find(int v) {
		if (v == id[v]) {
			return v;
		}
		id[v] = find(id[v]);
		return id[v];
	}

	static long calc(long sz) {
		return sz * (sz - 1) / 2;
	}

	static void union(int u, int v) {
		u = find(u);
		v = find(v);

		if (u > v) {
			int temp = u;
			u = v;
			v = temp;
		}
		id[v] = u;

		ans -= calc(sizes[u]);
		ans -= calc(sizes[v]);
		ans += calc(sizes[u] + sizes[v]);
		sizes[u] += sizes[v];
	}

	static class Edge {
		int s;
		int t;
		int w;
	}

	static class Query {
		int q;
		int index;
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);

		int n = in.nextInt();
		int m = in.nextInt();

		id = new int[n];
		sizes = new int[n];
		for (int i = 0; i < n; ++i) {
			id[i] = i;
			sizes[i] = 1;
		}

		Edge[] edges = new Edge[n - 1];
		for (int i = 0; i < n - 1; ++i) {
			edges[i] = new Edge();
			edges[i].s = in.nextInt() - 1;
			edges[i].t = in.nextInt() - 1;
			edges[i].w = in.nextInt();
		}

		Query[] queries = new Query[m];
		for (int i = 0; i < m; ++i) {
			queries[i] = new Query();
			queries[i].q = in.nextInt();
			queries[i].index = i;
		}

		Arrays.sort(edges, Comparator.comparingInt(o -> o.w));
		Arrays.sort(queries, Comparator.comparingInt(o -> o.q));

		answers = new long[m];
		int idx = 0;
		for (int i = 0; i < m; ++i) {
			int q = queries[i].q;
			while (idx < n - 1 && edges[idx].w <= q ) {
				int s = edges[idx].s;
				int t = edges[idx].t;
				union(s, t);
				idx++;
			}
			answers[queries[i].index] = ans;
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < m; ++i) {
			sb.append(answers[i]);
			if (i < m - 1) {
				sb.append(" ");
			}
		}
		System.out.println(sb.toString());

	}

}