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.util.*;
import java.io.*;
public class Alyonaandatree
{


	/************************ SOLUTION STARTS HERE ***********************/

	static class FenwickTree {  // In this variant of BIT each query is **NOT** a cumulative sum , it is the actual freq
		int tree[];
		int len;
		FenwickTree(int len) {
			this.len = len;
			tree = new int[len + 10];
		}
		void update(int idx , int val) {
			for(;idx <= len;idx += (idx & -idx))
				tree[idx] += val;
		}
		int query(int idx) {
			int sum = 0;
			for(;idx > 0;idx -= (idx & -idx))
				sum += tree[idx];

			return sum;
		}
		void update(int L , int R , int val) {
			if(L <= R && L > 0) {
				update(L, val);
				update(R + 1, -val);
			}
		}
	}

	static class Edge {
		int v;
		long cost;
		Edge(int vv , long ww) {
			v = vv;
			cost = ww;
		}
	}

	static ArrayList<Edge>[] adj;
	static long prefixSum[];
	static long A[];
	static int cnt[];
	static FenwickTree fenwickTree;
	
	static int ceil(int lo , int hi , long key) {
		int ceil = (int)1e6; // infinity
		while(lo <= hi) {
			int mid = (lo + hi) / 2;
			if(key <= prefixSum[mid]) {
				ceil = mid;
				hi = mid - 1;
			}
			else
				lo = mid + 1;
		}
		return ceil;
	}

	static void dfs(int u , int level , long currSum) {
		prefixSum[level] = currSum;
		fenwickTree.update(ceil(1, level - 1, currSum - A[u]), level - 1, 1);

		for(Edge e : adj[u])
			dfs(e.v, level + 1, currSum + e.cost);
		
		// cnt[u] = fenwickTree.query(level);
		cnt[u - 1] = fenwickTree.query(level);
		fenwickTree.update(level, level, -cnt[u - 1]);
	}

	@SuppressWarnings("unchecked")
	private static void solve(FastScanner s1, PrintWriter out){

		int N = s1.nextInt();
		A = s1.nextLongArrayOneBased(N);
		adj = new ArrayList[N + 1];
		for(int i=1;i<=N;i++)
			adj[i] = new ArrayList<>();

		for(int i=2;i<=N;i++) 
			adj[s1.nextInt()].add(new Edge(i, s1.nextLong()));

		prefixSum = new long[N + 1];
		//cnt = new int[N + 1];
		cnt = new int[N];
		fenwickTree = new FenwickTree(N);
		dfs(1, 1, 0);
		
/*		for(int i=1;i<=N;i++)
			out.print(cnt[i] + " ");*/
		Arrays.stream(cnt).forEach(a -> out.print(a + " "));
	}



	/************************ SOLUTION ENDS HERE ************************/





	/************************ TEMPLATE STARTS HERE *********************/

	public static void main(String []args) throws IOException {
		FastScanner in  = new FastScanner(System.in);
		PrintWriter out = 
				new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); 
		solve(in, out);
		in.close();
		out.close();
	}    

	static class FastScanner{
		BufferedReader reader;
		StringTokenizer st;
		FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}	
		String next()
		{while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}		    
		st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
		String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}	    	  	
		int    nextInt()   {return Integer.parseInt(next());}
		long   nextLong()  {return Long.parseLong(next());}		
		double nextDouble(){return Double.parseDouble(next());}
		char   nextChar()  {return next().charAt(0);}
		int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
		long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}	
		int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}	    	
		long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}	    	
		void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}				
	}

	/************************ TEMPLATE ENDS HERE ************************/
}