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 final class alonya_tree_2
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long[] a,pre;
	static ArrayList<Node>[] al;
	static int[] parent,level,log,res;
	static int[][] st;
	static int maxn=(int)2e5+5;
	
	static void dfs(int u,int p,int curr,long tot)
	{
		level[u]=curr;pre[u]=tot;
		for(Node x:al[u])
		{
			if(x.idx!=p)
			{
				dfs(x.idx,u,curr+1,tot+x.val);
			}
		}
	}
	
	static void dfs2(int u,int p)
	{
		for(Node x:al[u])
		{
			if(x.idx!=p)
			{
				dfs2(x.idx,u);res[u]+=res[x.idx];
			}
		}
	}
	
	static boolean check(int mid,int idx)
	{
		int anc=idx;
		for(int i=25;i>=0;i--)
		{
			int curr=1<<i;
			if(curr<=mid)
			{
				anc=st[i][anc];mid-=curr;
			}
		}
		return (pre[idx]-pre[anc]<=a[idx]);
	}
	
	static int get(int now,int idx)
	{
		int anc=idx;
		for(int i=25;i>=0;i--)
		{
			int curr=1<<i;
			if(curr<=now)
			{
				anc=st[i][anc];now-=curr;
			}
		}
		return anc;
	}
	
	@SuppressWarnings("unchecked")
    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();a=new long[n+1];al=new ArrayList[n+1];
		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextInt();al[i]=new ArrayList<Node>();
		}
		parent=new int[n+1];level=new int[n+1];
		for(int i=2;i<=n;i++)
		{
			int u=i,v=sc.nextInt(),cost=sc.nextInt();parent[u]=v;al[u].add(new Node(v,cost));al[v].add(new Node(u,cost));
		}
		pre=new long[n+1];dfs(1,-1,1,0);log=new int[maxn];
		for(int i=2;i<=n;i++)
		{
			log[i]=log[i>>1]+1;
		}
		st=new int[log[n]+2][n+1];
		for(int i=1;i<=n;i++)
		{
			st[0][i]=parent[i];
		}
		for(int i=1;(1<<i)<=n+1;i++)
		{
			for(int j=1;j<=n;j++)
			{
				st[i][j]=st[i-1][st[i-1][j]];
			}
		}
		res=new int[n+1];//out.println(Arrays.toString(pre));
		for(int i=2;i<=n;i++)
		{
			int low=1,high=level[i]-1;
			while(low<high)
			{
				int mid=(low+high+1)>>1;
				if(check(mid,i))
				{
					low=mid;
				}
				else
				{
					high=mid-1;
				}
			}
		//	out.println(i+" "+low);
			if(check(low,i))
			{
				int anc=get(low,i);res[parent[i]]++;
				if(anc!=0)
				{
					res[parent[anc]]--;
				}
			}
		}
		dfs2(1,-1);
		for(int i=1;i<=n;i++)
		{
			out.print(res[i]+" ");
		}
		out.println("");out.close();
    }
}
class Node
{
	int idx,val;
	public Node(int idx,int val)
	{
		this.idx=idx;this.val=val;
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}