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>
import java.io.*;

import java.util.*;
import java.lang.*;
import static java.lang.Math.*;

public class TaskC implements Runnable {
    InputReader c;
    PrintWriter w;
    /*Global Variables*/

    public void run() {
        c = new InputReader(System.in);
        w = new PrintWriter(System.out);
        HashMap<Integer,Integer> size = new HashMap<>();
        int n = c.nextInt(),m=c.nextInt();
        p3 edge[]  =new p3[n-1];
        for(int i=0;i<n-1;i++)
            edge[i] = new p3(c.nextInt()-1,c.nextInt()-1,c.nextInt());
        for(int i=0;i<n;i++) size.put(i,1);

        Arrays.sort(edge);
        DJSet dsu = new DJSet(n);
        pair queries[] = new pair[m];
        for(int i=0;i<m;i++)
            queries[i] = new pair(c.nextInt(),i);
        Arrays.sort(queries);
        int j=0;
        long res=0;
        long ans[] = new long[m];
        for(int i=0;i<m;i++){
            while (j<n-1 && edge[j].w<=queries[i].x){
                int xroot = dsu.root(edge[j].x), yroot = dsu.root(edge[j].y);
                dsu.union(edge[j].x,edge[j].y);
                int newroot = dsu.root(edge[j].x);
                if(size.get(xroot) != 1) res -= nc2(size.get(xroot));
                if(size.get(yroot) != 1) res -= nc2(size.get(yroot));
                if(newroot == xroot) {
                    size.put(xroot, size.get(xroot) + size.get(yroot));
                    size.remove(yroot);
                }else if(newroot == yroot){
                    size.put(yroot, size.get(xroot) + size.get(yroot));
                    size.remove(xroot);
                }else{
                    w.println("problem");
                    w.flush();
                }
                res += nc2(size.get(newroot));
                //w.println(newroot+" "+xroot+" "+yroot+" "+res+" "+size.get(newroot)); w.flush();
                j++;
            }
            //w.println(i+" "+res);
            //w.flush();
            ans[i] = res;
        }

        long seq[] = new long[m];
        for(int i=0;i<m;i++){
            seq[queries[i].y] = ans[i];
        }

        printArray(seq);


        w.close();
    }

    private long nc2(long n) {
        return (n*(n-1))/2;
    }

    public static class DJSet {
        public int[] upper;
        public DJSet(int n) {
            upper = new int[n];
            Arrays.fill(upper, -1);
        }

        public int root(int x) {
            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
        }

        public boolean equiv(int x, int y) {
            return root(x) == root(y);
        }

        public boolean union(int x, int y) {
            x = root(x);
            y = root(y);
            if (x != y) {
                if (upper[y] < upper[x]) {
                    int d = x;
                    x = y;
                    y = d;
                }
                upper[x] += upper[y];
                upper[y] = x;
            }
            return x == y;
        }
    }

    class p3 implements Comparable<p3>{
        int x, y, w;

        public p3(int x, int y, int w) {
            this.x = x;
            this.y = y;
            this.w = w;
        }

        @Override
        public int compareTo(p3 o) {
            return this.w - o.w;
        }
    }

/*Template Stuff*/
    ArrayList<Long> getDiv(long num){
        long square_root = (long) sqrt(num) + 1;
        ArrayList<Long>  l = new ArrayList<>();
        for (long i = 1; i < square_root; i++) {
            if (num % i == 0&&i*i!=num) {
                l.add(i);
                l.add(num / i);
            }
            if (num % i == 0&&i*i==num)
                l.add(i);
        }
        return l;
    }
    class pair implements Comparable<pair>{
        int x,y;

        @Override
        public String toString() {
            return "pair{" +
                    "x=" + x +
                    ", y=" + y +
                    '}';
        }

        pair(int x, int y){
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(pair o) {
            return this.x - o.x;
        }
    }
    public static void sortbyColumn(int arr[][], int col){
        Arrays.sort(arr, new Comparator<int[]>()
        {
            public int compare(int[] o1, int[] o2){
                return(Integer.valueOf(o1[col]).compareTo(o2[col]));
            }
        });
    }
    static long gcd(long a, long b){
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    public void printArray(int[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    public int[] scanArrayI(int n){
        int a[] = new int[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextInt();
        return a;
    }
    public long[] scanArrayL(int n){
        long a[] = new long[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextLong();
        return a;
    }
    public void printArray(long[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                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 {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        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 boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new TaskC(),"TaskC",1<<26).start();
    }
}