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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.TreeMap;
import java.io.IOException;
import java.util.Comparator;
import java.io.InputStream;
import java.util.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Indrajit Sinha
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		GPathQueries solver = new GPathQueries();
		solver.solve(1, in, out);
		out.close();
	}

	static class GPathQueries {
		int n;
		PrintWriter out;
		InputReader in;
		final Comparator<Entity> com = new Comparator<Entity>() {
			public int compare(Entity x, Entity y) {
				int xx = Integer.compare(x.c, y.c);
				return xx;
			}
		};

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int t, i, j, tt, k;
			this.out = out;
			this.in = in;
			n = in.nextInt();
			int m = in.nextInt();
			TreeMap<Integer, Long> tm = new TreeMap<>();
			DisjointUnionSets dsu = new DisjointUnionSets(n);
			Entity en[] = new Entity[n - 1];
			for (i = 0; i < n - 1; i++) {
				en[i] = new Entity(in.nextInt() - 1, in.nextInt() - 1, in.nextInt());
			}
			Arrays.sort(en, com);
			int cc = 0;
			int a[] = new int[m];
			int b[] = new int[m];
			PriorityQueue<Integer> pq = new PriorityQueue<>();
			for (i = 0; i < m; i++) {
				a[i] = in.nextInt();
				pq.add(a[i]);
			}
			for (i = 0; i < m; i++) {
				b[i] = pq.poll();
			}
			long ans = 0;
			for (i = 0; i < m; i++) {
				if (tm.containsKey(b[i]))
					continue;
				while (cc < n - 1 && en[cc].c <= b[i]) {
					ans = dsu.union(en[cc].a, en[cc].b, ans);
					cc++;
				}
				tm.put(b[i], ans);
			}
			for (i = 0; i < m; i++) {
				p(tm.get(a[i]));
			}
			pn("");
		}

		void pn(String zx) {
			out.println(zx);
		}

		void p(long zx) {
			out.print(zx + " ");
		}

		class DisjointUnionSets {
			long[] size;
			int[] parent;
			int n;

			public DisjointUnionSets(int n) {
				size = new long[n];
				parent = new int[n];
				this.n = n;
				makeSet();
			}

			void makeSet() {
				for (int i = 0; i < n; i++) {
					parent[i] = i;
					size[i] = 1;
				}
			}

			int find(int x) {
				if (parent[x] != x) {
					parent[x] = find(parent[x]);
				}
				return parent[x];
			}

			long union(int x, int y, long ans) {
				int xRoot = find(x), yRoot = find(y);
				if (xRoot == yRoot) {
					return ans;
				}
				long hp = ans;
				ans -= size[xRoot] * (size[xRoot] - 1) / 2;
				ans -= size[yRoot] * (size[yRoot] - 1) / 2;
				if (size[xRoot] < size[yRoot]) {
					parent[xRoot] = yRoot;
					size[yRoot] += size[xRoot];
					ans += size[yRoot] * (size[yRoot] - 1) / 2;
				} else if (size[yRoot] < size[xRoot]) {
					parent[yRoot] = xRoot;
					size[xRoot] += size[yRoot];
					ans += size[xRoot] * (size[xRoot] - 1) / 2;
				} else {
					parent[yRoot] = xRoot;
					size[xRoot] += size[yRoot];
					ans += size[xRoot] * (size[xRoot] - 1) / 2;
				}
				return ans;
			}

		}

		class Entity {
			int a;
			int b;
			int c;

			Entity(int p, int q, int r) {
				a = p;
				b = q;
				c = r;
			}

		}

	}

	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

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

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

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public String next() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));

			return res.toString();
		}

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

	}
}