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 javafx.util.Pair;

import java.io.*;
import java.util.*;

/**
 * Created by chao on 16/11/13.
 */
public class A {

    private static long[] delta;
    private static long[] deltaP;
    private static long[] b;
    private static long[] a;
    private static int n;
    private static long[] res;
    private static List<Pair<Integer, Long>>[] tree;


    public static void main(String[] args) throws IOException {
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        n = Integer.parseInt(br.readLine());
        delta = new long[n+1];
        deltaP = new long[n+1];
        a = new long[n+1];
        b = new long[n+1];

        String[] nums = br.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            a[i+1] = Long.parseLong(nums[i]);
        }
        tree = new List[n+1];
        for (int i = 0; i <= n; i++) {
            tree[i] = new ArrayList<>();
        }
        for (int i = 2; i <= n; i++) {
            nums = br.readLine().split(" ");
            int parent = Integer.parseInt(nums[0]);
            long val = Long.parseLong(nums[1]);
            tree[parent].add(new Pair<>(i, val));
        }

        res = new long[n+1];
        gao(1, 0, 1);

        for (int i = 1; i <= n; i++) {
            if (i != 1) pw.print(' ');
            pw.print(res[i]);
        }
        pw.println();




        pw.flush();
        pw.close();
        br.close();

    }

    private static void gao(int p, long dis, int m) {
        // reset delta[p] deltaP[p] to 0
        b[m] = dis + b[m-1];
        // binary search to find first ancestor of which (b[m]-b[node]<= a[p])
        int pA = 1;
        int st = 1, ed = m;
        if (b[m] - b[1] <= a[p]) {
            pA = 1;
        } else {
            while (st + 1 < ed) {
                int md = (st+ed)/2;
                if (b[m] - b[md] <= a[p]) ed = md;
                else st = md;
            }
            pA = ed;
        }
        update(pA, m, 1);


        for (Pair<Integer, Long> pair : tree[p]) {
            gao(pair.getKey(), pair.getValue(), m+1);
        }
        res[p] = getAns(m);
        update(m, m+1, -res[p]);

    }

    private static int lowbit(int x) {
        return x&(-x);
    }

    //[p1, p2)
    private static void update(int p1, int p2, long val) {
        if (p1 < p2) {
            add(delta, p1, val);
            add(delta, p2, -val);
            add(deltaP, p1, val * p1);
            add(deltaP, p2, -val * p2);
        }
    }

    private static void add(long[] a, int p, long val) {
        while (p <= n) {
            a[p] += val;
            p += lowbit(p);
        }
    }

    private static long getSum(long[] a, int p) {
        long s = 0;
        while (p > 0) {
            s += a[p];
            p -= lowbit(p);
        }
        return s;
    }

    private static long getAns(int p) {
        return getNewSum(p) - getNewSum(p-1);
    }


    // sum[p] = (p+1)*Sigma(delta[p])-Sigma(delta[p]*p)
    private static long getNewSum(int p) {
        return (p+1)*getSum(delta, p) - getSum(deltaP, p);
    }



}

