Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges).

Let's define dist(v, u) as the sum of the integers written on the edges of the simple path from v to u.

The vertex v controls the vertex u (v ≠ u) if and only if u is in the subtree of v and dist(v, u) ≤ au.

Alyona wants to settle in some vertex. In order to do this, she wants to know for each vertex v what is the number of vertices u such that v controls u.

Input

The first line contains single integer n (1 ≤ n ≤ 2·105).

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the integers written in the vertices.

The next (n - 1) lines contain two integers each. The i-th of these lines contains integers pi and wi (1 ≤ pi ≤ n, 1 ≤ wi ≤ 109) — the parent of the (i + 1)-th vertex in the tree and the number written on the edge between pi and (i + 1).

It is guaranteed that the given graph is a tree.

Output

Print n integers — the i-th of these numbers should be equal to the number of vertices that the i-th vertex controls.

Examples

Input

5
2 5 1 4 6
1 7
1 1
3 5
3 6


Output

1 0 1 0 0


Input

5
9 7 8 6 5
1 1
2 1
3 1
4 1


Output

4 3 2 1 0

Note

In the example test case the vertex 1 controls the vertex 3, the vertex 3 controls the vertex 5 (note that is doesn't mean the vertex 1 controls the vertex 5).
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        InputStream inputStream = System.in;
//        InputStream inputStream = new FileInputStream("dijkstra.in");
        OutputStream outputStream = System.out;
//        OutputStream outputStream = new FileOutputStream("dijkstra.out");
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Answer solver = new Answer();
        solver.solve(1, in, out);
        out.close();
    }

    static class Answer {
        private List<Integer>[] G;
        private List<Integer>[] W;

        private void add(int u, int v, int w) {
            if (G[u] == null) {
                G[u] = new ArrayList<>();
                W[u] = new ArrayList<>();
            }
            G[u].add(v);
            W[u].add(w);
        }

        private int bin(List<Integer> t, int l, int r, long[] d, long dv, long av) {
            if (l > r) {
                return -1;
            }

            int m = (l + r) >> 1;
            if (d[t.get(m)] < dv - av) {
                return bin(t, m + 1, r, d, dv, av);
            } else if (d[t.get(m)] > dv - av) {
                int x = bin(t, l, m - 1, d, dv, av);
                if (x == -1) {
                    return m;
                }
                return x;
            }
            return m;
        }

        private List<Integer> t = new ArrayList<>();
        private long[] d;
        private int[] ans;

        private void dfs(int v, int p, long[] a) {
            if (G[v] == null) {
                return;
            }
            for (int i = 0; i < G[v].size(); i++) {
                int u = G[v].get(i);
                if (u != p) {
                    if (p == -1) {
                        d[u] = W[v].get(i);
                    } else {
                        d[u] = d[v] + W[v].get(i);
                    }

//                    for (Integer x : t) {
//                        System.out.print(x + " ");
//                    }
//                    System.out.println();

                    int pp = bin(t, 0, t.size() - 1, d, d[u], a[u]);
                    if (pp != -1) {
//                        System.out.println("TUTA");
                        if (pp != 0) {
                            int par_par = t.get(pp - 1);
                            ans[par_par]--;
                        }
                        ans[v]++;
                    }

                    t.add(u);
                    dfs(u, v, a);
                    t.remove(t.size() - 1);
                }
            }
        }

        private void dfs1(int v, int p) {
            if (G[v] == null) {
                return;
            }
            for (Integer u : G[v]) {
                if (u != p) {
                    dfs1(u, v);
                    ans[v] += ans[u];
                }
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            long[] a = new long[n + 1];
            for (int i = 1; i <= n; i++) {
                a[i] = in.nextInt();
            }

            G = new List[n + 1];
            W = new List[n + 1];
            d = new long[n + 1];
            ans = new int[n + 1];

            for (int i = 2; i <= n; i++) {
                int p = in.nextInt();
                int w = in.nextInt();
                add(p, i, w);
                add(i, p, w);
            }

            t.add(1);
            dfs(1, -1, a);
            dfs1(1, -1);

            for (int i = 1; i <= n; i++) {
                out.print(ans[i] + " ");
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public List<Integer> nextIntArrayList(int n) {
            List<Integer> a = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int x = nextInt();
                a.add(x);
            }
            return a;
        }

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

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }
    }
}