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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static int n;
    static long [] dist , a , parent , pnt , res , e;
    static ArrayList<Integer> childs [] ;
    static ArrayList<Integer> dfs_tree;
    static void accDist (int node) {
        dist[node] += (parent[node] == - 1 ? 0 : dist[(int)parent[node]]);
        for (int child : childs[node])
            accDist(child);
    }

    static long distance (int from , int to) {
        return dist[from] - dist[to];
    }
    static int s [];
    static void dfs (int node ) {
        dfs_tree.add(node);
        int lo = 0 , hi = dfs_tree.size() - 1 , best = hi;
        for (int i = 0 ; i <= 23 ; ++ i) {
            int mid = lo + ((hi - lo) >> 1);
            if (distance(node , dfs_tree.get(mid)) <= a[node]) {
                best = mid;
                hi = Math.max(lo , mid - 1);
            }
            else
                lo = Math.min(hi , mid + 1);
        }

        if (node != 0 && node != dfs_tree.get(best))
        {
            s[(int)parent[node]] ++ ;
            e[dfs_tree.get(best)] ++ ;
        }
        for (int i = 0 ; i < childs[node].size() ; ++ i)
        {
            int child = childs[node].get(i);
            dfs(child);
        }
        dfs_tree.remove(dfs_tree.size() - 1);
    }

    static void fillRes (int node) {
        res[node] = s[node];
        for (int child : childs[node]) {
            fillRes(child);
            res[node] += res[child] - e[child];
        }
    }
    public static void main (String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        n = sc.nextInt() ;
        s = new int[n];
        e = new long[n];
        dist = new long[n];
        parent = new long[n];
        a = new long[n];
        pnt = new long[n];
        childs = new ArrayList[n];
        dfs_tree = new ArrayList<>();
        res = new long[n];
        for (int i = 0 ; i < n ; ++ i)
            childs[i] = new ArrayList<>();
        for (int i = 0 ; i < n ; ++ i)
            a[i] = sc.nextInt();
        parent[0] = - 1;

        for (int i = 1 ; i < n ; ++ i) {
            int p = sc.nextInt() - 1 , w = sc.nextInt();
            parent[i] = p;
            childs[p].add(i);
            dist[i] = w;
        }


        accDist (0);
        dfs(0);
        fillRes (0);
        for (int i = 0 ; i < n ; ++ i)
            if (i == 0)
                out.print(res[i]);
            else
                out.print(" " + res[i]);
        out.println();
        out.flush();
    }


























    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}