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.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class TaskD {

    private static final boolean TEST_CASES = false;

    void solve(int testCaseNo, InputReader in, PrintWriter out) {
        final int n = in.nextInt();
        final int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = in.nextInt();
        }
        List<Pair>[] g = new List[n + 1];
        for (int i = 0; i <= n; i++) {
            g[i] = new ArrayList<>();
        }

        for (int i = 1; i < n; i++) {
            int p = in.nextInt();
            int w = in.nextInt();
            g[p].add(new Pair(i + 1, w));
            g[i + 1].add(new Pair(p, w));
        }

        final int[] vals = new int[n + 1];
        final int[] res = new int[n + 1];
        List<Pair> tsum = new ArrayList<>();
        dfs(1, 0, g, tsum, vals, 0, a, res);
        //compute(1, 0, g, vals, res);
        for (int i = 1; i <= n; i++) {
            if (i > 1) out.print(" ");
            out.print(res[i]);
        }
        out.println();

    }

    private void compute(int u, int p, List<Pair>[] g, int[] vals, int[] res) {
        int ans = 0;
        for (int i = 0; i < g[u].size(); i++) {
            int v = g[u].get(i).first;
            if (v == p) continue;
            compute(v, u, g, vals, res);
            ans += res[v] + vals[v];
        }
        res[u] = ans;
    }

    private void dfs(int u, int p, List<Pair>[] g, List<Pair> tsum, int[] vals, long cs, int[] a, int[] res) {
        tsum.add(new Pair(u, cs));
        int pos = find(tsum, cs - a[u]);
        vals[u] += 1;
        vals[pos] += -1;
        int ans = 0;
        for (int i = 0; i < g[u].size(); i++) {
            int v = g[u].get(i).first;
            long w = g[u].get(i).second;
            if (v == p) continue;
            dfs(v, u, g, tsum, vals, cs + w, a, res);
            ans += res[v] + vals[v];
        }
        tsum.remove(tsum.size() - 1);
        res[u] = ans;
    }

    private int find(List<Pair> tsum, long val) {
        if (tsum.get(0).second >= val) return tsum.get(0).first;
        int lo = 0, hi = tsum.size() - 1;
        while ((hi - lo) > 1) {
            int m = (lo + hi) / 2;
            if (val <= tsum.get(m).second)
                hi = m;
            else lo = m;
        }
        return tsum.get(hi).first;
    }

    static final class Pair {
        int first;
        long second;

        Pair(int first, long second) {
            this.first = first;
            this.second = second;
        }
    }


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

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

        /**
         * @return null if end of stream
         */
        public String readLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        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 long nextLong() {
            return Long.parseLong(next());
        }

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

    }

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

        int testCases = TEST_CASES ? in.nextInt() : 1;

        TaskD solver = new TaskD();
        for (int testCase = 0; testCase < testCases; testCase++) {
            solver.solve(testCase, in, out);
        }
        out.flush();
        out.close();
    }
}
