#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define long long long
void _read();

const int nax = 2e5+11;
int n;
vector<vector<pair<int,int>>> adj;
// vector<oset<pair<long,int>>> chi;
vector<int> a,ans;
vector<long> dp,vec;
int in = 0;
void dfs_1( int u = 1, int p = 1, int W = 0) {
      dp[u] = W;
      vec[u] = dp[u] - a[u];
      for( const auto &[v,w] : adj[u]) {
            if( v == p ) continue;
            dfs_1(v,u,w+W);
      }
}
oset<pair<long,int>> dfs( int u = 1, int p = 1) {
      oset<pair<long,int>> here;
      for( const auto &[v,w] : adj[u]) {
            if ( v == p ) continue;
            oset<pair<long,int>> chi = dfs(v,u);
            for( const pair<int,int> &pp : chi) {
                  here.insert(pp);
            }
      }
      ans[u] = here.order_of_key({dp[u],0});
      here.insert({vec[u],--in});
      return here;
}

int32_t main () { _read();

      cin >> n;
      a.resize(n+1);
      dp.resize(n+1);
      adj.resize(n+1);
      // chi.resize(n+1)
      vec.resize(n+1);
      ans.resize(n+1);
      for( int i = 1; i <= n; i++) {
            cin >> a[i];
      }
      for( int i = 2; i <= n; i++) {
            int p,w;
            cin >> p >> w;
            adj[i].emplace_back(p,w);
            adj[p].emplace_back(i,w);
      }
      dfs_1();
      dfs();
      for( int i = 1; i <= n; i++) {
            cout << ans[i] << ' ';
      }
      cout << '\n';
      return 0;
};

void _read() {
      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define long long long
void _read();

const int nax = 2e5+11;
int n;
vector<vector<pair<int,int>>> adj;
// vector<oset<pair<long,int>>> chi;
vector<int> a,ans;
vector<long> dp,vec;
int in = 0;
void dfs_1( int u = 1, int p = 1, int W = 0) {
      dp[u] = W;
      vec[u] = dp[u] - a[u];
      for( const auto &[v,w] : adj[u]) {
            if( v == p ) continue;
            dfs_1(v,u,w+W);
      }
}
oset<pair<long,int>> dfs( int u = 1, int p = 1) {
      oset<pair<long,int>> here;
      for( const auto &[v,w] : adj[u]) {
            if ( v == p ) continue;
            dfs(v,u);
            oset<pair<long,int>> chi = dfs(v,u);
            for( const pair<int,int> &pp : chi) {
                  here.insert(pp);
            }
      }
      ans[u] = here.order_of_key({dp[u],0});
      here.insert({vec[u],--in});
      return here;
}

int32_t main () { _read();

      cin >> n;
      a.resize(n+1);
      dp.resize(n+1);
      adj.resize(n+1);
      // chi.resize(n+1)
      vec.resize(n+1);
      ans.resize(n+1);
      for( int i = 1; i <= n; i++) {
            cin >> a[i];
      }
      for( int i = 2; i <= n; i++) {
            int p,w;
            cin >> p >> w;
            adj[i].emplace_back(p,w);
            adj[p].emplace_back(i,w);
      }
      dfs_1();
      dfs();
      for( int i = 1; i <= n; i++) {
            cout << ans[i] << ' ';
      }
      cout << '\n';
      return 0;
};

void _read() {
      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define int long long
void _read();

const int nax = 2e5+11;
int n;
vector<vector<pair<int,int>>> adj;
vector<oset<pair<int,int>>> chi;
vector<int> a,vec,dp,ans;
int in = 0;
void dfs_1( int u = 1, int p = 1, int W = 0) {
      dp[u] = W;
      vec[u] = dp[u] - a[u];
      for( const auto &[v,w] : adj[u]) {
            if( v == p ) continue;
            dfs_1(v,u,w+W);
      }
}
void dfs( int u = 1, int p = 1) {
      oset<pair<int,int>> here;
      for( const auto &[v,w] : adj[u]) {
            if ( v == p ) continue;
            dfs(v,u);
            for( const pair<int,int> &pp : chi[v]) {
                  here.insert(pp);
            }
      }
      ans[u] = here.order_of_key({dp[u],0});
      // db(u,here,ans[u],dp[u],vec[u],a[u]);
      here.insert({vec[u],--in});
      chi[u] = here;
}

int32_t main () { _read();

      cin >> n;
      a.resize(n+1);
      dp.resize(n+1);
      adj.resize(n+1);
      chi.resize(n+1);
      vec.resize(n+1);
      ans.resize(n+1);
      for( int i = 1; i <= n; i++) {
            cin >> a[i];
      }
      for( int i = 2; i <= n; i++) {
            int p,w;
            cin >> p >> w;
            adj[i].emplace_back(p,w);
            adj[p].emplace_back(i,w);
      }
      dfs_1();
      dfs();
      for( int i = 1; i <= n; i++) {
            cout << ans[i] << ' ';
      }
      cout << '\n';
      return 0;
};

void _read() {
      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define int long long
void _read();

const int nax = 2e5+11;
int n;
vector<vector<pair<int,int>>> adj;
oset<pair<int,int>> s;
vector<int> a,ans;
vector<int> dp,vec;
int in = 0;
void dfs_1( int u = 1, int p = 1, int W = 0) {
      dp[u] = W;
      vec[u] = dp[u] - a[u];
      for( const auto &[v,w] : adj[u]) {
            if( v == p ) continue;
            dfs_1(v,u,w+W);
      }
}
void dfs( int u = 1, int p = 1) {
      for( const auto &[v,w] : adj[u]) {
            if ( v == p ) continue;
            int bef = s.order_of_key({dp[v],0});
            dfs(v,u);
            int af = s.order_of_key({dp[v],0});
            ans[v] = af-bef;
            s.insert({vec[v],--in});
      }
}

int32_t main () { _read();

      cin >> n;
      a.resize(n+1);
      dp.resize(n+1);
      adj.resize(n+1);
      vec.resize(n+1);
      ans.resize(n+1);
      for( int i = 1; i <= n; i++) {
            cin >> a[i];
      }
      for( int i = 2; i <= n; i++) {
            int p,w;
            cin >> p >> w;
            adj[i].emplace_back(p,w);
            adj[p].emplace_back(i,w);
      }
      dfs_1();
      dfs();
      ans[1] = (int) s.order_of_key({dp[1],0});
      for( int i = 1; i <= n; i++) {
            cout << ans[i] << ' ';
      }
      cout << '\n';
      return 0;
};

void _read() {
      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef pair<int,int> PII;
typedef long long int ll;
typedef pair< ll,ll> PLL;

PLL operator+(PLL a,PLL b){ return {a.first + b.first, a.second + b.second}; }
PLL operator-(PLL a,PLL b){ return {a.first - b.first, a.second - b.second}; }
PLL operator*(PLL a,PLL b){ return {a.first * b.first, a.second * b.second}; }
PLL operator/(PLL a,PLL b){ return {a.first / b.first, a.second / b.second}; }
PLL operator%(PLL a,PLL b){ return {( b.first + a.first) % b.first, (b.second + a.second) % b.second}; }
PLL operator%(PLL a,ll b){ return {a.first % b, a.second % b} ;}
PLL operator+(PLL a,ll b){ return {a.first + b, a.second + b} ;}
PLL operator-(PLL a,ll b){ return {a.first - b, a.second - b} ;}
PLL operator*(PLL a,ll b){ return {a.first * b, a.second * b} ;}

ostream& operator<<(ostream &out,PLL a)
{
    out << "( " << a.first << ", " << a.second << " )" ;
    return out;
}

/*
	Order Statistics Tree ( OST )

	find_by_order()
		takes an integer k and returns an iterator to the k'th largest element counting from zero
	order_of_key()
		takes an element, here an integer and returns the number of elements strictly smaller than input
*/

typedef tree<
PII,
null_type,
less<PLL>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int const N = 2e5 + 100;
vector < pair<int,int> > g[N];
int sub[N] ;
int ans[N] ;
ll lvl[N] ;
int a[N] ;
//ll cost[]
ordered_set* ost[N] ;

void dfs(int u,ll l)
{
    int big = -1, mx = -1;
    sub[u] = 1, lvl[u] = l;
    for(auto v : g[u]){
        dfs(v.first,l+v.second);
        sub[u] += sub[v.first] ;
        if(sub[v.first] > mx) mx = sub[v.first] , big = v.first;
    }
    if(big != -1){
        ost[u] = ost[big] ;
    }
    else
        ost[u] = new ordered_set;

    ans[u] = (*ost[u]).order_of_key({lvl[u],(ll)1e9});

    for(auto ed: g[u]){
        int v = ed.first;
        if(v != big){
            for(auto x : *ost[v]){
                if(x.first <= lvl[u]) ans[u]++;
                (*ost[u]).insert(x);
            }
        }
    }

    (*ost[u]).insert({lvl[u]-a[u],u});
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;

    for(int i = 1; i <= n;i++) cin >> a[i] ;

    for(int i = 1;i < n; i++){
        int a,b;
        cin >> a >> b;
        g[a].push_back({i+1, b});
    }

    dfs(1,0);

    for(int i = 1; i <= n;i++)
        cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef pair<int,int> PII;
typedef long long int ll;
typedef pair< ll,ll> PLL;

PLL operator+(PLL a,PLL b){ return {a.first + b.first, a.second + b.second}; }
PLL operator-(PLL a,PLL b){ return {a.first - b.first, a.second - b.second}; }
PLL operator*(PLL a,PLL b){ return {a.first * b.first, a.second * b.second}; }
PLL operator/(PLL a,PLL b){ return {a.first / b.first, a.second / b.second}; }
PLL operator%(PLL a,PLL b){ return {( b.first + a.first) % b.first, (b.second + a.second) % b.second}; }
PLL operator%(PLL a,ll b){ return {a.first % b, a.second % b} ;}
PLL operator+(PLL a,ll b){ return {a.first + b, a.second + b} ;}
PLL operator-(PLL a,ll b){ return {a.first - b, a.second - b} ;}
PLL operator*(PLL a,ll b){ return {a.first * b, a.second * b} ;}

ostream& operator<<(ostream &out,PLL a)
{
    out << "( " << a.first << ", " << a.second << " )" ;
    return out;
}

/*
	Order Statistics Tree ( OST )

	find_by_order()
		takes an integer k and returns an iterator to the k'th largest element counting from zero
	order_of_key()
		takes an element, here an integer and returns the number of elements strictly smaller than input
*/

typedef tree<
PII,
null_type,
less<PLL>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int const N = 2e5 + 100;
vector < pair<int,int> > g[N];
int sub[N] ;
int ans[N] ;
ll lvl[N] ;
int a[N] ;
//ll cost[]
ordered_set* ost[N] ;

void dfs(int u,int l)
{
    int big = -1, mx = -1;
    sub[u] = 1, lvl[u] = l;
    for(auto v : g[u]){
        dfs(v.first,l+v.second);
        sub[u] += sub[v.first] ;
        if(sub[v.first] > mx) mx = sub[v.first] , big = v.first;
    }
    if(big != -1){
        ost[u] = ost[big] ;
    }
    else
        ost[u] = new ordered_set;

    ans[u] = (*ost[u]).order_of_key({lvl[u],(ll)1e9});

    for(auto ed: g[u]){
        int v = ed.first;
        if(v != big){
            for(auto x : *ost[v]){
                if(x.first <= lvl[u]) ans[u]++;
                (*ost[u]).insert(x);
            }
        }
    }

    (*ost[u]).insert({lvl[u]-a[u],u});
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;

    for(int i = 1; i <= n;i++) cin >> a[i] ;

    for(int i = 1;i < n; i++){
        int a,b;
        cin >> a >> b;
        g[a].push_back({i+1, b});
    }

    dfs(1,0);

    for(int i = 1; i <= n;i++)
        cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef pair<int,int> PII;
typedef long long int ll;
typedef pair< ll,ll> PLL;

PLL operator+(PLL a,PLL b){ return {a.first + b.first, a.second + b.second}; }
PLL operator-(PLL a,PLL b){ return {a.first - b.first, a.second - b.second}; }
PLL operator*(PLL a,PLL b){ return {a.first * b.first, a.second * b.second}; }
PLL operator/(PLL a,PLL b){ return {a.first / b.first, a.second / b.second}; }
PLL operator%(PLL a,PLL b){ return {( b.first + a.first) % b.first, (b.second + a.second) % b.second}; }
PLL operator%(PLL a,ll b){ return {a.first % b, a.second % b} ;}
PLL operator+(PLL a,ll b){ return {a.first + b, a.second + b} ;}
PLL operator-(PLL a,ll b){ return {a.first - b, a.second - b} ;}
PLL operator*(PLL a,ll b){ return {a.first * b, a.second * b} ;}

ostream& operator<<(ostream &out,PLL a)
{
    out << "( " << a.first << ", " << a.second << " )" ;
    return out;
}

/*
	Order Statistics Tree ( OST )

	find_by_order()
		takes an integer k and returns an iterator to the k'th largest element counting from zero
	order_of_key()
		takes an element, here an integer and returns the number of elements strictly smaller than input
*/

typedef tree<
PLL,
null_type,
less<PLL>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int const N = 2e5 + 100;
vector < PLL > g[N];
ll sub[N] ;
ll ans[N] ;
ll lvl[N] ;
ll a[N] ;
//ll cost[]
ordered_set* ost[N] ;

void dfs(int u,ll l)
{
    int big = -1, mx = -1;
    sub[u] = 1, lvl[u] = l;
    for(auto v : g[u]){
        dfs(v.first,l+v.second);
        sub[u] += sub[v.first] ;
        if(sub[v.first] > mx) mx = sub[v.first] , big = v.first;
    }
    if(big != -1){
        ost[u] = ost[big] ;
    }
    else
        ost[u] = new ordered_set;

    ans[u] = (*ost[u]).order_of_key({lvl[u],(ll)1e9});

    for(auto ed: g[u]){
        int v = ed.first;
        if(v != big){
            for(auto x : *ost[v]){
                if(x.first <= lvl[u]) ans[u]++;
                (*ost[u]).insert(x);
            }
        }
    }

    (*ost[u]).insert({lvl[u]-a[u],u});
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;

    for(int i = 1; i <= n;i++) cin >> a[i] ;

    for(int i = 1;i < n; i++){
        int a,b;
        cin >> a >> b;
        g[a].push_back({i+1, b});
    }

    dfs(1,0);

    for(int i = 1; i <= n;i++)
        cout << ans[i] << " ";
    return 0;
}


///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef int ll;
const ll MXN = 2e5 + 10;
ll n;
ll A[MXN], Val[MXN], ex[MXN];
vector<ll> Jads, Diss;
vector<pair<ll, ll>> adj[MXN];
void dfs(ll u, ll par, ll d = 0){
    Jads.push_back(u), Diss.push_back(d);
    ll ind = lower_bound(Diss.begin(), Diss.end(), d - A[u]) - Diss.begin();
    if(Jads[ind] != u) Val[Jads[ind]] ++, Val[par] --, ex[par] ++;
    for(auto Pr : adj[u]){
        ll v = Pr.first, w = Pr.second;
        if(v != par) dfs(v, u, d + w);
    }
    Jads.pop_back(), Diss.pop_back();
}
void DFS(ll u, ll par){
    Val[u] += Val[par];
    for(auto Pr : adj[u]){
        ll v = Pr.first;
        if(v != par) DFS(v, u);
    }
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> A[i];
    for(int i = 2; i <= n; i ++){
        ll p, x; cin >> p >> x;
        adj[i].emplace_back(p, x), adj[p].emplace_back(i, x);
    }
    dfs(1, 0);
    DFS(1, 0);
    for(int i = 1; i <= n; i ++) cout << Val[i] + ex[i] << ' '; cout << '\n';
    return 0;
}
/*!
    HE'S AN INSTIGATOR,
    ENEMY ELIMINATOR,
    AND WHEN HE KNOCKS YOU BETTER
    YOU BETTER LET HIM IN.
*/
//! N.N


///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 2e5 + 10;
ll n;
ll A[MXN], Val[MXN], ex[MXN];
vector<ll> Jads, Diss;
vector<pair<ll, ll>> adj[MXN];
void dfs(ll u, ll par, ll d = 0){
    Jads.push_back(u), Diss.push_back(d);
    ll ind = lower_bound(Diss.begin(), Diss.end(), d - A[u]) - Diss.begin();
    Val[par] ++;
    if(ind) Val[Jads[ind - 1]] --;
    for(auto Pr : adj[u]){
        ll v = Pr.first, w = Pr.second;
        if(v != par) dfs(v, u, d + w);
    }
    Jads.pop_back(), Diss.pop_back();
}
void DFS(ll u, ll par){
    for(auto Pr : adj[u]){
        ll v = Pr.first;
        if(v != par) DFS(v, u), Val[u] += Val[v];
    }
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> A[i];
    for(int i = 2; i <= n; i ++){
        ll p, x; cin >> p >> x;
        adj[i].emplace_back(p, x), adj[p].emplace_back(i, x);
    }
    dfs(1, 0);
    DFS(1, 0);
    for(int i = 1; i <= n; i ++) cout << Val[i] + ex[i] << ' '; cout << '\n';
    return 0;
}
/*!
    HE'S AN INSTIGATOR,
    ENEMY ELIMINATOR,
    AND WHEN HE KNOCKS YOU BETTER
    YOU BETTER LET HIM IN.
*/
//! N.N


///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef int ll;
const ll MXN = 2e5 + 10;
ll n;
ll A[MXN], Val[MXN], ex[MXN];
vector<ll> Jads, Diss;
vector<pair<ll, ll>> adj[MXN];
void dfs(ll u, ll par, ll d = 0){
    Jads.push_back(u), Diss.push_back(d);
    ll ind = lower_bound(Diss.begin(), Diss.end(), d - A[u]) - Diss.begin();
    Val[par] ++;
    if(ind) Val[Jads[ind - 1]] --;
    for(auto Pr : adj[u]){
        ll v = Pr.first, w = Pr.second;
        if(v != par) dfs(v, u, d + w);
    }
    Jads.pop_back(), Diss.pop_back();
}
void DFS(ll u, ll par){
    for(auto Pr : adj[u]){
        ll v = Pr.first;
        if(v != par) DFS(v, u), Val[u] += Val[v];
    }
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> A[i];
    for(int i = 2; i <= n; i ++){
        ll p, x; cin >> p >> x;
        adj[i].emplace_back(p, x), adj[p].emplace_back(i, x);
    }
    dfs(1, 0);
    DFS(1, 0);
    for(int i = 1; i <= n; i ++) cout << Val[i] + ex[i] << ' '; cout << '\n';
    return 0;
}
/*!
    HE'S AN INSTIGATOR,
    ENEMY ELIMINATOR,
    AND WHEN HE KNOCKS YOU BETTER
    YOU BETTER LET HIM IN.
*/
//! N.N


#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using graph = vector<vi>;
using sparse = vector<vll>;

const ll inf = (1ll << 40);

int dfs(graph& G, vi& minus,  vi& ans, vi& subSize, int v) {

	int accumulated = minus[v];
	for (int u : G[v]) {
		accumulated += dfs(G, minus, ans, subSize, u);
		subSize[v] += subSize[u] + 1;
	}

	ans[v] = subSize[v] + accumulated;

	return accumulated;
}

void go() {
	int V; cin >> V;
	int dep = 25;

	sparse parent(dep, vll(V + 1, -1));
	sparse cost(dep, vll(V + 1, 0));

	parent[0][1] = 0;
	cost[0][1] = inf;

	vll a(V + 1, 0);
	vi minus(V + 1, 0);

	graph G(V + 1);

	for (int v = 1; v <= V; v++)
		cin >> a[v];

	for (int v = 2; v <= V; v++) {
		cin >> parent[0][v] >> cost[0][v];
		G[parent[0][v]].push_back(v);
	}

	for (int j = 0; j < dep - 1; j++)
	for (int v = 1; v <= V; v++) {
		int p = parent[j][v];
		if ( p != -1 ) {
			cost[j + 1][v] = cost[j][v] + cost[j][p];
			parent[j + 1][v] = parent[j][p];
		}
	}

	for (int v = 1; v <= V; v++) {
		int x = v;
		ll distSum = 0;
		for (int j = dep - 1; j >= 0; j--) {
			int p = parent[j][x];

			if (p != -1 && distSum + cost[j][x] <= a[v]) {
				distSum += cost[j][x];
				x = p;
			}
		}

		int p = parent[0][x];
		minus[p]--;
	}

	vi ans(V + 1, 0);
	vi subSize(V + 1, 0);
	dfs(G, minus, ans, subSize, 1);

	for (int v = 1; v <= V; v++) {
		cout << ans[v] << " ";
	}
	cout << "\n";
}

int main() {
	ios::sync_with_stdio(0);
	go();
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second
#define int ll

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=200005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
vector<int> e[MAXN];
int dep[MAXN],Log[MAXN],fa[MAXN][20],s[MAXN][20],a[MAXN],ans[MAXN],Ans[MAXN];
void dfs(int x)
{
	dep[x]=dep[fa[x][0]]+1;
	for (int i=1;i<=Log[dep[x]];i++) fa[x][i]=fa[fa[x][i-1]][i-1],s[x][i]=s[fa[x][i-1]][i-1]+s[x][i-1];
	for (auto v:e[x]) if (v!=fa[x][0]) dfs(v);
}
void query(int x)
{
	int nw=x;
	for (int i=Log[dep[x]];i>=0;i--)
		if (fa[nw][i]&&s[nw][i]<=a[x]) a[x]-=s[nw][i],nw=fa[nw][i];
	ans[fa[nw][0]]--,ans[fa[x][0]]++;
}
void solve(int x)
{
	for (auto v:e[x]) solve(v),ans[x]+=ans[v];
}
signed main()
{
	int n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=2,c;i<=n;i++) fa[i][0]=read(),s[i][0]=read(),e[fa[i][0]].PB(i);
	dep[0]=-1,Log[1]=0;
	for (int i=2;i<=n;i++) Log[i]=Log[i>>1]+1;
	dfs(1);
	for (int i=1;i<=n;i++) query(i);
	solve(1);
	for (int i=1;i<=n;i++) printf("ll%d ",ans[i]);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second
#define int ll

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=1000005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
vector<int> e[MAXN];
int dep[MAXN],Log[MAXN],fa[MAXN][20],s[MAXN][20],a[MAXN],ans[MAXN],Ans[MAXN];
void dfs(int x)
{
	dep[x]=dep[fa[x][0]]+1;
	for (int i=1;i<=Log[dep[x]];i++) fa[x][i]=fa[fa[x][i-1]][i-1],s[x][i]=s[fa[x][i-1]][i-1]+s[x][i-1];
	for (auto v:e[x]) if (v!=fa[x][0]) dfs(v);
}
void query(int x)
{
	int nw=x;
	for (int i=Log[dep[x]];i>=0;i--)
		if (fa[nw][i]&&s[nw][i]<=a[x]) a[x]-=s[nw][i],nw=fa[nw][i];
	ans[fa[nw][0]]--,ans[fa[x][0]]++;
}
void solve(int x)
{
	for (auto v:e[x]) solve(v),ans[x]+=ans[v];
}
signed main()
{
	int n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=2,c;i<=n;i++) fa[i][0]=read(),s[i][0]=read(),e[fa[i][0]].PB(i);
	dep[0]=-1,Log[1]=0;
	for (int i=2;i<=n;i++) Log[i]=Log[i>>1]+1;
	dfs(1);
	for (int i=1;i<=n;i++) query(i);
	solve(1);
	for (int i=1;i<=n;i++) printf("ll%d ",ans[i]);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=1000005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
vector<int> e[MAXN];
int dep[MAXN],Log[MAXN],fa[MAXN][20],s[MAXN][20],a[MAXN],ans[MAXN],Ans[MAXN];
void dfs(int x)
{
	dep[x]=dep[fa[x][0]]+1;
	for (int i=1;i<=Log[dep[x]];i++) fa[x][i]=fa[fa[x][i-1]][i-1],s[x][i]=s[fa[x][i-1]][i-1]+s[x][i-1];
	for (auto v:e[x]) if (v!=fa[x][0]) dfs(v);
}
void query(int x)
{
	int nw=x;
	for (int i=Log[dep[x]];i>=0;i--)
		if (fa[nw][i]&&s[nw][i]<=a[x]) a[x]-=s[nw][i],nw=fa[nw][i];
	ans[fa[nw][0]]--,ans[fa[x][0]]++;
}
void solve(int x)
{
	for (auto v:e[x]) solve(v),ans[x]+=ans[v];
}
signed main()
{
	int n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=2,c;i<=n;i++) fa[i][0]=read(),s[i][0]=read(),e[fa[i][0]].PB(i);
	dep[0]=-1,Log[1]=0;
	for (int i=2;i<=n;i++) Log[i]=Log[i>>1]+1;
	dfs(1);
	for (int i=1;i<=n;i++) query(i);
	solve(1);
	for (int i=1;i<=n;i++) printf("%d ",ans[i]);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second
#define int ll

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=1000005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
vector<int> e[MAXN];
int dep[MAXN],Log[MAXN],fa[MAXN][20],s[MAXN][20],a[MAXN],ans[MAXN],Ans[MAXN];
void dfs(int x)
{
	dep[x]=dep[fa[x][0]]+1;
	for (int i=1;i<=Log[dep[x]];i++) fa[x][i]=fa[fa[x][i-1]][i-1],s[x][i]=s[fa[x][i-1]][i-1]+s[x][i-1];
	for (auto v:e[x]) if (v!=fa[x][0]) dfs(v);
}
void query(int x)
{
	int nw=x;
	for (int i=Log[dep[x]];i>=0;i--)
		if (fa[nw][i]&&s[nw][i]<=a[x]) a[x]-=s[nw][i],nw=fa[nw][i];
	ans[fa[nw][0]]--,ans[fa[x][0]]++;
}
void solve(int x)
{
	for (auto v:e[x]) solve(v),ans[x]+=ans[v];
}
signed main()
{
	int n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=2,c;i<=n;i++) fa[i][0]=read(),s[i][0]=read(),e[fa[i][0]].PB(i);
	dep[0]=-1,Log[1]=0;
	for (int i=2;i<=n;i++) Log[i]=Log[i>>1]+1;
	dfs(1);
	for (int i=1;i<=n;i++) query(i);
	solve(1);
	for (int i=1;i<=n;i++) printf("%lld ",ans[i]);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second
#define int ll

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=200005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
vector<int> e[MAXN];
int dep[MAXN],Log[MAXN],fa[MAXN][20],s[MAXN][20],a[MAXN],ans[MAXN],Ans[MAXN];
void dfs(int x)
{
	dep[x]=dep[fa[x][0]]+1;
	for (int i=1;i<=Log[dep[x]];i++) fa[x][i]=fa[fa[x][i-1]][i-1],s[x][i]=s[fa[x][i-1]][i-1]+s[x][i-1];
	for (auto v:e[x]) if (v!=fa[x][0]) dfs(v);
}
void query(int x)
{
	int nw=x;
	for (int i=Log[dep[x]];i>=0;i--)
		if (fa[nw][i]&&s[nw][i]<=a[x]) a[x]-=s[nw][i],nw=fa[nw][i];
	ans[fa[nw][0]]--,ans[fa[x][0]]++;
}
void solve(int x)
{
	for (auto v:e[x]) solve(v),ans[x]+=ans[v];
}
signed main()
{
	int n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=2,c;i<=n;i++) fa[i][0]=read(),s[i][0]=read(),e[fa[i][0]].PB(i);
	dep[0]=-1,Log[1]=0;
	for (int i=2;i<=n;i++) Log[i]=Log[i>>1]+1;
	dfs(1);
	for (int i=1;i<=n;i++) query(i);
	solve(1);
	for (int i=1;i<=n;i++) printf("%lld ",ans[i]);
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define ll          long long
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD         1000000007
#define hell        1000000007
#define N           4000
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define ll          long long
#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)

#define track(x)                cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl

#define ed(i)       i.end()
#define mem(a)      memset(a, 0, sizeof(a))
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int &b) {a = max(a, b); }
void self_min(int &a, int &b) {a = min(a, b); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// const ll sizes  = 1e7+1;
// bool dp[sizes] ;
// std::vector<int> veca;

bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

const ll sizes  = 1e7+1;
int parent[sizes];
int value[sizes];
int answer[sizes];
int v[sizes];

int n, m , k , o , p;

void solve(){
    // std::vector<int> v;

    memset(answer , 0 , sizeof(answer));
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> v[i];
        // v.pb(o);
        /* code */
    }

    for (int i = 2; i <= n ; ++i)
    {
        cin >> parent[i] >> value[i];
        /* code */
    }

    for (int i = 2; i <= n; ++i)
    {
        int par = parent[i];
        int node = i;
        int count = 0;
        int sumval = value[i];
        if(sumval <= v[node])answer[par]++;
        int fixed  = v[node];
        while(par != 1){
            sumval += value[par];
            node = par;
            par = parent[node];
            if(sumval <= fixed){
                answer[par]++;
            }
            else break;
        }

    //     for (int i = 1; i <= n ; ++i)
    // {
    //     cout << answer[i] << " ";
    //     /* code */
    // }
    // cout << endl;
        /* code */
    }

    for (int i = 1; i <= n ; ++i)
    {
        cout << answer[i] << " ";
        /* code */
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    cin.tie(0);
    cout.tie(0);
    // sieve();
    // fun();
    int t = 1;
    // cin >> t;
    int p = t;
    while(t--){
        // cout << "Case #" << p - t << ": ";
        solve();
    }
}


    #include <bits/stdc++.h>
    using namespace std;

    #define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
    vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(move(x)); return v; }
    void err(vector<string>::iterator it) {}
    template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) { cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\n'; err(++it, args...); }

    typedef long long LL;
    #define MAXN 200013
    #define INF (1LL<<50);
    #define MAXLG 20
    int N;
    LL A[MAXN];
    int parent[MAXN];
    LL weight[MAXN];
    vector<int> ch[MAXN];
    int depth[MAXN];
    LL toroot[MAXN];
    int L[MAXN][MAXLG];
    int pref[MAXN];
    int ans[MAXN];

    void dfs(int n) {
    	if (n) {
    		depth[n] = depth[parent[n]] + 1;
    		toroot[n] = toroot[parent[n]] + weight[n];
    	}
    	for (int x : ch[n]) {
    		dfs(x);
    	}
    }

    void lcadp_init() {
    	for (int i = 0; i < N; i++) {
    		L[i][0] = parent[i];
    	}
    	for (int lg = 0; lg < MAXLG - 1; lg++) {
    		for (int i = 0; i < N; i++) {
    			L[i][lg+1] = L[L[i][lg]][lg];
    		}
    	}
    }

    int ancestor(int n, int k) {
    	// k-th ancestor of n
    	if (k >= depth[n]) {
    		return 0;
    	}
    	int ret = n;
    	for (int lg = MAXLG - 1; lg >= 0; lg--) {
    		if ((1<<lg) <= k) {
    			k -= (1<<lg);
    			ret = L[ret][lg];
    		}
    	}
    	return ret;
    }

    int where(int n) {
    	// remember: weight[n] >= toroot[n] - toroot[v];
    	int lo = 0;
    	int hi = depth[n];
    	while (lo != hi) {
    		int mid = (lo + hi + 1) / 2;
    		int x = ancestor(n, mid);
    		if (A[n] >= toroot[n] - toroot[x]) {
    			lo = mid;
    		}
    		else {
    			hi = mid - 1;
    		}
    	}
    	return ancestor(n, lo);
    }

    void dfs2(int n) {
    	ans[n] = pref[n];
    	for (int x : ch[n]) {
    		dfs2(x);
    		ans[n] += ans[x];
    	}
    }

    int main() {
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);

    	// freopen("input.txt", "r", stdin);

    	cin >> N;
    	for (int i = 0; i < N; i++) {
    		cin >> A[i];
    	}

    	parent[0] = 0;
    	weight[0] = INF;
    	for (int i = 1; i < N; i++) {
    		cin >> parent[i] >> weight[i];
    		parent[i]--;
    		ch[parent[i]].push_back(i);
    	}

    	dfs(0);
    	lcadp_init();

    	for (int u = 1; u < N; u++) {
    		int v = where(u);
    		// error(u, v);
    		pref[parent[u]] += 1;
    		if (v) {
    			pref[parent[v]] -= 1;
    		}
    	}

    	dfs2(0);

    	for (int i = 0; i < N; i++) {
    		cout << ans[i] << ' ';
    	}
    	cout << endl;
    	return 0;
    }


#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define ll          long long
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD         1000000007
#define hell        1000000007
#define N           4000
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define ll          long long
#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)

#define track(x)                cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl

#define ed(i)       i.end()
#define mem(a)      memset(a, 0, sizeof(a))
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int &b) {a = max(a, b); }
void self_min(int &a, int &b) {a = min(a, b); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// const ll sizes  = 1e7+1;
// bool dp[sizes] ;
// std::vector<int> veca;

bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

const ll sizes  = 1e7+1;
int parent[sizes];
int value[sizes];
int answer[sizes];
int v[sizes];

int n, m , k , o , p;

void solve(){
    // std::vector<int> v;

    memset(answer , 0 , sizeof(answer));
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> v[i];
        // v.pb(o);
        /* code */
    }

    for (int i = 2; i <= n ; ++i)
    {
        cin >> parent[i] >> value[i];
        /* code */
    }

    for (int i = 2; i <= n; ++i)
    {
        int par = parent[i];
        int node = i;
        int count = 0;
        int sumval = value[i];
        if(sumval <= v[node])answer[par]++;
        int fixed  = v[node];
        while(par != 1){
            sumval += value[par];
            node = par;
            par = parent[node];
            if(sumval <= fixed)answer[par]++;
        }

    //     for (int i = 1; i <= n ; ++i)
    // {
    //     cout << answer[i] << " ";
    //     /* code */
    // }
    // cout << endl;
        /* code */
    }

    for (int i = 1; i <= n ; ++i)
    {
        cout << answer[i] << " ";
        /* code */
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    cin.tie(0);
    cout.tie(0);
    // sieve();
    // fun();
    int t = 1;
    // cin >> t;
    int p = t;
    while(t--){
        // cout << "Case #" << p - t << ": ";
        solve();
    }
}


#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define ll          long long
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD         1000000007
#define hell        1000000007
#define N           4000
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define ll          long long
#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)

#define track(x)                cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl

#define ed(i)       i.end()
#define mem(a)      memset(a, 0, sizeof(a))
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int &b) {a = max(a, b); }
void self_min(int &a, int &b) {a = min(a, b); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// const ll sizes  = 1e7+1;
// bool dp[sizes] ;
// std::vector<int> veca;

bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

const ll sizes  = 1e7+1;
int parent[sizes];
int value[sizes];
int answer[sizes];
int v[sizes];

int n, m , k , o , p;

void solve(){
    // std::vector<int> v;

    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> v[i];
        // v.pb(o);
        /* code */
    }

    for (int i = 2; i <= n ; ++i)
    {
        cin >> parent[i] >> value[i];
        /* code */
    }

    for (int i = 2; i <= n; ++i)
    {
        int par = parent[i];
        int node = i;
        int count = 0;
        int sumval = value[i];
        if(sumval <= v[node])answer[par]++;
        while(par != 1){
            sumval += value[i];
            node = par;
            par = parent[node];
            if(sumval <= v[node])answer[par]++;
        }
        /* code */
    }

    for (int i = 1; i <= n ; ++i)
    {
        cout << answer[i] << " ";
        /* code */
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    cin.tie(0);
    cout.tie(0);
    // sieve();
    // fun();
    int t = 1;
    // cin >> t;
    int p = t;
    while(t--){
        // cout << "Case #" << p - t << ": ";
        solve();
    }
}


#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef long ll;
using namespace std;
const int M=1e9+7;
const int N=2e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
ll n;
ll a[N];
vector<pair<ll,ll>> g[N];
ll ans[N];
void dfs(ll ch,vector<pair<ll,ll>> q)
{
    ll d=0;
    //stack<pair<ll,ll>> q1=q;
    /*while(!q1.empty())
    {
        d+=q1.top().se;
        if(a[ch]>=d)
        ++ans[q1.top().fi];
        q1.pop();
    }*/
    for(ll i=q.size()-1;i>=0;--i)
    {

        d+=q[i].se;
        if(a[ch]>=d)
        ++ans[q[i].fi];
    }
    for(auto f: g[ch])
    {
        q.pb({ch,f.se});
        dfs(f.fi,q);
        q.pop_back();
    }
}
int main()
{
   cin>>n;
   for(ll i=1;i<=n;++i)
   cin>>a[i];
   for(ll i=2;i<=n;++i)
   {
       ll p,w;cin>>p>>w;
       g[p].pb({i,w});
   }
   vector<pair<ll,ll>> v;
   dfs(1,v);
   for(ll i=1;i<=n;++i)
   cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef long long int ll;
using namespace std;
const int M=1e9+7;
const int N=2e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
ll n;
ll a[N];
vector<pair<ll,ll>> g[N];
ll ans[N];
void dfs(ll ch,stack<pair<ll,ll>> q)
{
    ll d=0;
    stack<pair<ll,ll>> q1=q;
    while(!q1.empty())
    {
        d+=q1.top().se;
        if(a[ch]>=d)
        ++ans[q1.top().fi];
        q1.pop();
    }
    for(auto f: g[ch])
    {
        q.push({ch,f.se});
        dfs(f.fi,q);
        q.pop();
    }
}
int main()
{
    ios;
   cin>>n;
   for(ll i=1;i<=n;++i)
   cin>>a[i];
   for(ll i=2;i<=n;++i)
   {
       ll p,w;cin>>p>>w;
       g[p].pb({i,w});
   }
   stack<pair<ll,ll>> v;
   dfs(1,v);
   for(ll i=1;i<=n;++i)
   cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef long ll;
using namespace std;
const int M=1e9+7;
const int N=2e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
ll n;
ll a[N];
vector<pair<ll,ll>> g[N];
ll ans[N];
void dfs(ll ch,stack<pair<ll,ll>> q)
{
    ll d=0;
    stack<pair<ll,ll>> q1=q;
    while(!q1.empty())
    {
        d+=q1.top().se;
        if(a[ch]>=d)
        ++ans[q1.top().fi];
        q1.pop();
    }
    for(auto f: g[ch])
    {
        q.push({ch,f.se});
        dfs(f.fi,q);
        q.pop();
    }
}
int main()
{
   cin>>n;
   for(ll i=1;i<=n;++i)
   cin>>a[i];
   for(ll i=2;i<=n;++i)
   {
       ll p,w;cin>>p>>w;
       g[p].pb({i,w});
   }
   stack<pair<ll,ll>> v;
   dfs(1,v);
   for(ll i=1;i<=n;++i)
   cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef long long int ll;
using namespace std;
const int M=1e9+7;
const int N=2e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
ll n;
ll a[N],parent[N];
vector<pair<ll,ll>> g[N];
ll ans[N];
void dfs(ll ch)
{
    ll d=0;
    //stack<pair<ll,ll>> q1=q;
    /*while(!q1.empty())
    {
        d+=q1.top().se;
        if(a[ch]>=d)
        ++ans[q1.top().fi];
        q1.pop();
    }*/
    ll h=ch;
    while(parent[h]!=-1)
    {
        ll pa=parent[h];
        for(auto f: g[pa])
        {
            if(f.fi==h)
            {
                d+=f.se;
                break;
            }
        }
        if(a[ch]>=d)
        ++ans[pa];
        h=pa;
    }
    for(auto f: g[ch])
    {
        dfs(f.fi);
    }
}
int main()
{
   cin>>n;
   for(ll i=1;i<=n;++i)
   cin>>a[i];
   for(ll i=2;i<=n;++i)
   {
       ll pi,w;cin>>pi>>w;
       g[pi].pb({i,w});
       parent[i]=pi;
   }
   parent[1]=-1;
   dfs(1);
   for(ll i=1;i<=n;++i)
   cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef long long int ll;
using namespace std;
const int M=1e9+7;
const int N=2e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
ll n;
ll a[N],parent[N];
vector<pair<ll,ll>> g[N];
ll ans[N];
void dfs(ll ch)
{
    ll d=0;
    //stack<pair<ll,ll>> q1=q;
    /*while(!q1.empty())
    {
        d+=q1.top().se;
        if(a[ch]>=d)
        ++ans[q1.top().fi];
        q1.pop();
    }*/
    ll h=ch;
    while(parent[h]!=-1)
    {
        ll pa=parent[h];
        for(auto f: g[pa])
        {
            if(f.fi==h)
            {
                d+=f.se;
                break;
            }
        }
        if(a[ch]>=d)
        ++ans[pa];
        else
        break;
        h=pa;
    }
    for(auto f: g[ch])
    {
        dfs(f.fi);
    }
}
int main()
{
   cin>>n;
   for(ll i=1;i<=n;++i)
   cin>>a[i];
   for(ll i=2;i<=n;++i)
   {
       ll pi,w;cin>>pi>>w;
       g[pi].pb({i,w});
       parent[i]=pi;
   }
   parent[1]=-1;
   dfs(1);
   for(ll i=1;i<=n;++i)
   cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef long long int ll;
using namespace std;
const int M=1e9+7;
const int N=2e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
ll n;
ll st[N],en[N],ans[N];
ll a[N],dist[N];
vector<pair<ll,ll>> adj[N];
void dfs(ll cur,ll pos,ll d)
{
    dist[pos]=d;
    ll i=lower_bound(dist,dist+pos,dist[pos]-a[cur])-dist;
    if(i!=pos)
    {
        ++st[i];
        ++en[pos-1];
    }
    for(auto f: adj[cur])
    {
        dfs(f.fi,pos+1,f.se+d);
    }
    ans[cur]=en[pos];
    en[pos-1]+=en[pos]-st[pos];
    st[pos]=0;
    en[pos]=0;
}
int main()
{
    cin>>n;
    for(ll i=1;i<=n;++i)
    cin>>a[i];
    for(ll i=2;i<=n;++i)
    {
        ll p,w;cin>>p>>w;
        adj[p].pb({i,w});
    }
    dfs(1,0,0);
    for(ll i=1;i<=n;++i)
    cout<<ans[i]<<' ';
}


#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef long ll;
using namespace std;
const int M=1e9+7;
const int N=2e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
ll n;
ll a[N],parent[N];
vector<pair<ll,ll>> g[N];
ll ans[N];
void dfs(ll ch)
{
    ll d=0;
    //stack<pair<ll,ll>> q1=q;
    /*while(!q1.empty())
    {
        d+=q1.top().se;
        if(a[ch]>=d)
        ++ans[q1.top().fi];
        q1.pop();
    }*/
    ll h=ch;
    while(parent[h]!=-1)
    {
        ll pa=parent[h];
        for(auto f: g[pa])
        {
            if(f.fi==h)
            {
                d+=f.se;
            }
        }
        if(a[ch]>=d)
        ++ans[pa];
        h=pa;
    }
    for(auto f: g[ch])
    {
        dfs(f.fi);
    }
}
int main()
{
   cin>>n;
   for(ll i=1;i<=n;++i)
   cin>>a[i];
   for(ll i=2;i<=n;++i)
   {
       ll pi,w;cin>>pi>>w;
       g[pi].pb({i,w});
       parent[i]=pi;
   }
   parent[1]=-1;
   dfs(1);
   for(ll i=1;i<=n;++i)
   cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef long ll;
using namespace std;
const int M=1e9+7;
const int N=2e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
ll n;
ll a[N],parent[N];
vector<pair<ll,ll>> g[N];
ll ans[N];
void dfs(ll ch)
{
    ll d=0;
    //stack<pair<ll,ll>> q1=q;
    /*while(!q1.empty())
    {
        d+=q1.top().se;
        if(a[ch]>=d)
        ++ans[q1.top().fi];
        q1.pop();
    }*/
    ll h=ch;
    while(parent[h]!=-1)
    {
        ll pa=parent[h];
        for(auto f: g[pa])
        {
            if(f.fi==h)
            {
                d+=f.se;
                break;
            }
        }
        if(a[ch]>=d)
        ++ans[pa];
        h=pa;
    }
    for(auto f: g[ch])
    {
        dfs(f.fi);
    }
}
int main()
{
   cin>>n;
   for(ll i=1;i<=n;++i)
   cin>>a[i];
   for(ll i=2;i<=n;++i)
   {
       ll pi,w;cin>>pi>>w;
       g[pi].pb({i,w});
       parent[i]=pi;
   }
   parent[1]=-1;
   dfs(1);
   for(ll i=1;i<=n;++i)
   cout<<ans[i]<<" ";
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> ans(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<vector<pair<int, int>>> gr(n); // to, w
	for(int i = 1; i < n; i++) {
		int p, w;
		cin >> p >> w;
	 	p--;
	 	gr[p].push_back({i, w});
	}
	vector<int> path, pref(1, 0), dp(n);
	function<void(int, int)> dfs = [&](int v, int pr) {
		path.push_back(v);
		int lb = pref.back() - a[v];
		auto it = lower_bound(pref.begin(), pref.end(), lb);
		if(it != pref.end() && it != prev(pref.end())) {
			int pos = it - pref.begin();
			if(pos != 0) {
				dp[path[pos - 1]]--;
			}
			dp[path[path.size() - 2]]++;
		}
		for(auto it: gr[v]) {
			int to = it.first, w = it.second;
			if(to == pr) continue;
			pref.push_back(pref.back() + w);
			dfs(to, v);
			pref.pop_back();
		}
		path.pop_back();
	};
	dfs(0, 0);
	int cnt = 0;
	function<void(int, int)> calc = [&](int v, int pr) {
		for(auto it: gr[v]) {
			int to = it.first, w = it.second;
			if(to == pr) continue;
			calc(to, v);
			ans[v] += ans[to];
		}
		ans[v] += dp[v];
	};
	calc(0, 0);
	/*
		v controls u if, u != v and dist(v, u) <= a[u]
		0 1 2
		1 v1, v2, v3, vj ... vi
		a[vi]
		dist(vj, vi) <= a[vi]
		pref[i] - pref[j - 1] <= a[vi]
		pref[j - 1] >= pref[i] - a[vi]
		lower_bound(pref.begin(), pref.end(), pref[i] - a[vi]) - pref.begin()
	*/
	for(int i = 0; i < n; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> ans(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<vector<pair<int, int>>> gr(n); // to, w
	for(int i = 1; i < n; i++) {
		int p, w;
		cin >> p >> w;
	 	p--;
	 	gr[p].push_back({i, w});
	}
	vector<int> path, pref(1, 0);
	function<void(int, int)> dfs = [&](int v, int pr) {
		path.push_back(v);
		int lb = pref.back() - a[v];
		auto it = lower_bound(pref.begin(), pref.end(), lb);
		if(it != pref.end()) {
			int pos = it - pref.begin();
			ans[v] = pref.size() - pos - 1;
		}
		for(auto it: gr[v]) {
			int to = it.first, w = it.second;
			if(to == pr) continue;
			pref.push_back(pref.back() + w);
			dfs(to, v);
			pref.pop_back();
		}
		path.pop_back();
	};
	dfs(0, 0);
	/*
		v controls u if, u != v and dist(v, u) <= a[u]
		0 1 2
		1 v1, v2, v3, vj ... vi
		a[vi]
		dist(vj, vi) <= a[vi]
		pref[i] - pref[j - 1] <= a[vi]
		pref[j - 1] >= pref[i] - a[vi]
		lower_bound(pref.begin(), pref.end(), pref[i] - a[vi]) - pref.begin()
	*/
	for(int i = 0; i < n; i++) {
		cout << ans[n - i - 1] << " ";
	}
	cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,C[200005][22],A[200005],B[200005],D[200005],sum[200005];
vector <long long> v[200005];
void dfs(long long x,long long y,long long z) {
           C[x][0]=y;
           for(long long i=1;i<=20;i++)
           C[x][i]=C[C[x][i-1]][i-1];
           sum[x]=z;
           //cout<<x<<" "<<z<<endl;
           for(long long i=0;i<v[x].size();i++) {
                      if(v[x][i]==y) continue;
                      dfs(v[x][i],x,z+B[v[x][i]]);
           }
}
void dfs1(long long x,long long y) {
           for(long long i=0;i<v[x].size();i++) {
                      if(v[x][i]==y) continue;
                      dfs1(v[x][i],x);
                      D[x]+=D[v[x][i]]+1;
           }
}
int main(){
           cin>>n;
           for(long long i=1;i<=n;i++)
           cin>>A[i];
           for(long long i=2;i<=n;i++) {
                      cin>>a>>B[i];
                      v[a].push_back(i);
                      v[i].push_back(a);
           }
           dfs(1,0,0);
          // for(long long i=1;i<=n;i++)
           //cout<<sum[i]<<" ";
           //cout<<endl;
           for(long long i=2;i<=n;i++) {
                      if(sum[i]<=A[i]) continue;
                      a=i;
                      for(long long j=20;j>=0;j--) {
                                 if(sum[a]-sum[C[a][j]]<=A[i]) { a=C[a][j]; A[i]-=sum[a]-sum[C[a][j]]; }
                      }
                      D[C[a][0]]--;
           }
           dfs1(1,0);
           for(long long i=1;i<=n;i++)
           cout<<D[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,C[200005][22],A[200005],B[200005],D[200005],sum[200005];
vector <long long> v[200005];
void dfs(long long x,long long y,long long z) {
           C[x][0]=y;
           for(long long i=1;i<=20;i++)
           C[x][i]=C[C[x][i-1]][i-1];
           sum[x]=z;
           //cout<<x<<" "<<z<<endl;
           for(long long i=0;i<v[x].size();i++) {
                      if(v[x][i]==y) continue;
                      dfs(v[x][i],x,z+B[v[x][i]]);
           }
}
void dfs1(long long x,long long y) {
           for(long long i=0;i<v[x].size();i++) {
                      if(v[x][i]==y) continue;
                      dfs1(v[x][i],x);
                      D[x]+=D[v[x][i]]+1;
           }
}
int main(){
           cin>>n;
           for(long long i=1;i<=n;i++)
           cin>>A[i];
           for(long long i=2;i<=n;i++) {
                      cin>>a>>B[i];
                      v[a].push_back(i);
                      v[i].push_back(a);
           }
           dfs(1,0,0);
           /*for(long long i=1;i<=n;i++)
           cout<<sum[i]<<" ";
           cout<<endl;
           for(long long i=1;i<=n;i++) {
                      for(long long j=0;j<5;j++)
                      cout<<C[i][j]<<" ";
                      cout<<endl;
           }*/
           for(long long i=2;i<=n;i++) {
                      if(sum[i]<=A[i]) continue;
                      a=i;
                      for(long long j=20;j>=0;j--) {
                                 if(sum[a]-sum[C[a][j]]<=A[i]) { A[i]-=sum[a]-sum[C[a][j]]; a=C[a][j]; }
                      }
                      //cout<<a<<"-"<<i<<" ";
                      D[C[a][0]]--;
           }//cout<<endl;
           dfs1(1,0);
           for(long long i=1;i<=n;i++)
           cout<<D[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,C[200005][20],A[200005],B[200005],D[200005],sum[200005];
vector <long long> v[200005];
void dfs(long long x,long long y,long long z) {
           C[x][0]=y;
           for(long long i=1;i<=20;i++)
           C[x][i]=C[C[x][i-1]][i-1];
           sum[x]=z;
           //cout<<x<<" "<<z<<endl;
           for(long long i=0;i<v[x].size();i++) {
                      if(v[x][i]==y) continue;
                      dfs(v[x][i],x,z+B[v[x][i]]);
           }
}
void dfs1(long long x,long long y) {
           for(long long i=0;i<v[x].size();i++) {
                      if(v[x][i]==y) continue;
                      dfs1(v[x][i],x);
                      D[x]+=D[v[x][i]]+1;
           }
}
int main(){
           cin>>n;
           for(long long i=1;i<=n;i++)
           cin>>A[i];
           for(long long i=2;i<=n;i++) {
                      cin>>a>>B[i];
                      v[a].push_back(i);
                      v[i].push_back(a);
           }
           dfs(1,0,0);
          // for(long long i=1;i<=n;i++)
           //cout<<sum[i]<<" ";
           //cout<<endl;
           for(long long i=2;i<=n;i++) {
                      if(sum[i]<=A[i]) continue;
                      a=i;
                      for(long long j=20;j>=0;j--) {
                                 if(sum[a]-sum[C[a][j]]<=A[i]) { a=C[a][j]; A[i]-=sum[a]-sum[C[a][j]]; }
                      }
                      D[C[a][0]]--;
           }
           dfs1(1,0);
           for(long long i=1;i<=n;i++)
           cout<<D[i]<<" ";
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const int  N     =  3e5+5;
const int  mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const int  LEVEL =  log2(N)+1;

ll test = 1, n, a[N], ans[N];
vpll adj[N];
set <pll> path;

void dfs(int x, int p, ll d){
	path.insert({d, x});
	for(auto it : adj[x]){
		dfs(it.f, x, d+it.s);
	}
	path.erase({d, x});
	if(path.size() == 0) return;
	ans[p] += 1;
	auto ind = path.lower_bound({d-a[x], 0});
	if(ind != path.begin()) ind--;
	else return;
	ans[ind->s] -= 1;
}

void dfs1(int x){
	for(auto it : adj[x]){
		dfs1(it.f);
		ans[x] += ans[it.f];
	}
}

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int u = 2; u <= n; u++){
		ll v, w; cin >> v >> w;
		adj[v].pb({u,w});
	}
	dfs(1, 0, 0);
	dfs1(1);
	for(int i = 1; i <= n; i++) cout << ans[i] << " "; newl;
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const int  N     =  3e5+5;
const int  mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const int  LEVEL =  log2(N)+1;

ll test = 1, n, a[N], ans[N];
vpll adj[N];
set <pll> path;

void dfs(int x, int p, int d){
	path.insert({d, x});
	for(auto it : adj[x]){
		dfs(it.f, x, d+it.s);
	}
	path.erase({d, x});
	if(path.size() == 0) return;
	ans[p] += 1;
	auto ind = path.lower_bound({d-a[x], 0});
	if(ind != path.begin()) ind--;
	else return;
	ans[ind->s] -= 1;
}

void dfs1(int x){
	for(auto it : adj[x]){
		dfs1(it.f);
		ans[x] += ans[it.f];
	}
}

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int u = 2; u <= n; u++){
		int v, w; cin >> v >> w;
		adj[v].pb({u,w});
	}
	dfs(1, 0, 0);
	dfs1(1);
	for(int i = 1; i <= n; i++) cout << ans[i] << " "; newl;
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const int  N     =  3e5+5;
const int  mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const int  LEVEL =  log2(N)+1;

ll test = 1, n, a[N], ans[N];
vpll adj[N];
set <pll> path;

void dfs(int x, int p, ll d){
	path.insert({d, x});
	for(auto it : adj[x]){
		dfs(it.f, x, d+it.s);
		ans[x] += ans[it.f];
	}
	path.erase({d, x});
	if(path.size() == 0) return;
	ans[p] += 1;
	auto ind = path.lower_bound({d-a[x], 0});
	if(ind != path.begin()) ind--;
	else return;
	ans[ind->s] -= 1;
}

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int u = 2; u <= n; u++){
		ll v, w; cin >> v >> w;
		adj[v].pb({u,w});
	}
	dfs(1, 0, 0);
	for(int i = 1; i <= n; i++) cout << ans[i] << " "; newl;
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
const int L = 20;
int n;
long long a[N], d[N];
vector<pair<int, long long>> g[N];
int up[N][L];
int dp[N];

void dfs(int u, int p) {
  up[u][0] = p;
  for (int i = 1; i < L; i++) {
    up[u][i] = up[up[u][i - 1]][i - 1];
  }
  for (auto e : g[u]) {
    int v = e.first;
    long long w = e.second;
    d[v] = d[u] + w;
    dfs(v, u);
  }
}

int go(int u, long long val) {
  int v = u;
  for (int i = L - 1; i >= 0; i--) {
    if (d[u] - d[up[v][i]] <= val) v = up[v][i];
  }
  return up[v][0];
}

void upd(int u) {
  int v = go(u, a[u]);
  dp[v]--;
  dp[u]++;
}

void calc(int u) {
  for (auto e : g[u]) {
    int v = e.first;
    calc(v);
    dp[u] += dp[v];
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 2; i <= n; i++) {
    int u;
    long long w;
    cin >> u >> w;
    g[u].push_back({i, w});
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) upd(i);
  calc(1);
  for (int i = 1; i <= n; i++) {
    cout << dp[i] - 1 << (i == n ? '\n' : ' ');
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
const int L = log2(N);
int n;
long long a[N], d[N];
vector<pair<int, long long>> g[N];
int up[N][L];
int dp[N];

void dfs(int u, int p) {
  up[u][0] = p;
  for (int i = 1; i < L; i++) {
    up[u][i] = up[up[u][i - 1]][i - 1];
  }
  for (auto e : g[u]) {
    int v = e.first;
    long long w = e.second;
    d[v] = d[u] + w;
    dfs(v, u);
  }
}

int go(int u, long long val) {
  int v = u;
  for (int i = L - 1; i >= 0; i--) {
    if (d[u] - d[up[v][i]] <= val) v = up[v][i];
  }
  return up[v][0];
}

void upd(int u) {
  int v = go(u, a[u]);
  dp[v]--;
  dp[u]++;
}

void calc(int u) {
  for (auto e : g[u]) {
    int v = e.first;
    calc(v);
    dp[u] += dp[v];
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 2; i <= n; i++) {
    int u;
    long long w;
    cin >> u >> w;
    g[u].push_back({i, w});
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) upd(i);
  calc(1);
  for (int i = 1; i <= n; i++) {
    cout << dp[i] - 1 << (i == n ? '\n' : ' ');
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
const int L = log2(N);
int n;
long long a[N], d[N];
vector<pair<int, long long>> g[N];
int up[N][L];
int dp[N];

void dfs(int u, int p) {
  up[u][0] = p;
  for (int i = 1; i < L; i++) {
    up[u][i] = up[up[u][i - 1]][i - 1];
  }
  for (auto e : g[u]) {
    int v = e.first;
    long long w = e.second;
    if (p == v) continue;
    d[v] += d[u] + w;
    dfs(v, u);
  }
}

int go(int u, long long val) {
  int v = u;
  for (int i = L - 1; i >= 0; i--) {
    if (d[u] - d[up[v][i]] <= val) v = up[v][i];
  }
  return up[v][0];
}

void upd(int u) {
  int v = go(u, a[u]);
  dp[v]--;
  dp[u]++;
}

void calc(int u, int p) {
  for (auto e : g[u]) {
    int v = e.first;
    if (v == p) continue;
    calc(v, u);
    dp[u] += dp[v];
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 2; i <= n; i++) {
    int u;
    long long w;
    cin >> u >> w;
    g[u].push_back({i, w});
    g[i].push_back({u, w});
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) upd(i);
  calc(1, 0);
  for (int i = 1; i <= n; i++) {
    cout << dp[i] - 1 << (i == n ? '\n' : ' ');
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
const int L = log2(N);
int n;
long long a[N], d[N];
vector<pair<int, long long>> g[N];
int up[N][L];
int dp[N];

void dfs(int u, int p) {
  up[u][0] = p;
  for (int i = 1; i < L; i++) {
    up[u][i] = up[up[u][i - 1]][i - 1];
  }
  for (auto e : g[u]) {
    int v = e.first;
    long long w = e.second;
    d[v] = d[u] + w;
    dfs(v);
  }
}

int go(int u, long long val) {
  int v = u;
  for (int i = L - 1; i >= 0; i--) {
    if (d[u] - d[up[v][i]] <= val) v = up[v][i];
  }
  return up[v][0];
}

void upd(int u) {
  int v = go(u, a[u]);
  dp[v]--;
  dp[u]++;
}

void calc(int u) {
  for (auto e : g[u]) {
    int v = e.first;
    calc(v);
    dp[u] += dp[v];
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 2; i <= n; i++) {
    int u;
    long long w;
    cin >> u >> w;
    g[u].push_back({i, w});
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) upd(i);
  calc(1, 0);
  for (int i = 1; i <= n; i++) {
    cout << dp[i] - 1 << (i == n ? '\n' : ' ');
  }

  return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#define ll          long long int
#define db          double
#define pf          printf
#define sf          scanf
#define ff          first
#define ss          second
#define clr         clear()
#define sz          size()
#define pb          push_back
#define mk          make_pair
#define pi          acos(-1)
#define inf         1000000000000000005
#define mod          998244353

#define q(n)        q.push(n)
#define ull         unsigned long long int
#define f(i,k,n)    for(ll i=k;i<n;i++)
#define fr(i,n,k)   for(ll i=n;i>=k;i--)
#define ent(a)      scanf("%lld",&a)
#define ent2(a,b)   scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a)      memset(a,0,sizeof(a))
#define mem1(a)     memset(a,-1,sizeof(a))
#define vec(v,s)    vector<ll>v[s]
#define arr(a,s)    ll a[s]
//#define check(n,pos) (n&(1<<pos))
//#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 200003

ll dis[ma],c[ma],sub[ma],ans[ma],n,a[ma];
ll mp[ma];
vector<pair<ll,ll> >adj[ma];

void dfs(ll u)
{
 sub[u]=1;
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  dis[p]=dis[u]+adj[u][i].ss;
  dfs(p);
  sub[u]+=sub[p];
 }
}

ll tree[ma];

void update(ll x,ll val)
{
 while(x<=n)
 {
  tree[x]+=val;
  x+=x&(-x);
 }
}

ll query(ll x)
{
 ll s=0;
 while(x>0)
 {
  s+=tree[x];
  x-=x&(-x);
 }
 return s;
}

void add(ll u,ll par)
{
 ll i,k=0;
 ll r=max(k,dis[u]-a[u]);
 //cout<<r<<endl;
 update(r+1,1);
// cout<<r+1<<endl;
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par||mp[p]==1)continue;
  add(p,u);
 }
}

void rem(ll u,ll par)
{
 ll i,k=0;
 ll r=max(k,dis[u]-a[u]);
 update(r+1,-1);
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par||mp[p]==1)continue;
  rem(p,u);
 }
}

void dsu(ll u,ll par,ll f)
{
 ll mx=-1,big=-1;
 ll i;
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par)continue;
  if(sub[p]>mx)
  {
   mx=sub[p],big=p;
  }
 }
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par||p==big)continue;
  dsu(p,u,0);
 }

 if(big!=-1)
 {
  dsu(big,u,1);
  mp[big]=1;
 }
 add(u,par);
 ll pq=query(dis[u]+1);
 if(pq>0)pq--;
 ans[u]=pq;
 if(big!=-1)mp[big]=0;
 if(f==0)
 {
  rem(u,par);
 }

}

int main()
{
 ll i,x;
 while(cin>>n)
 {

  f(i,1,n+1)ent(a[i]);
  f(i,2,n+1)
  {
   ent2(x,c[i]);
   if(i>1)adj[x].pb(mk(i,c[i]));
  }
  f(i,0,ma)
  {
   tree[i]=0;
   mp[i]=0;
  }
  dis[1]=0;
  dfs(1);
  dsu(1,-1,0);

  f(i,1,n+1)
  {
   cout<<ans[i]<<" ";
  }
  cout<<endl;

 }

 return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#define ll          long long int
#define db          double
#define pf          printf
#define sf          scanf
#define ff          first
#define ss          second
#define clr         clear()
#define sz          size()
#define pb          push_back
#define mk          make_pair
#define pi          acos(-1)
#define inf         1000000000000000005
#define mod          998244353

#define q(n)        q.push(n)
#define ull         unsigned long long int
#define f(i,k,n)    for(ll i=k;i<n;i++)
#define fr(i,n,k)   for(ll i=n;i>=k;i--)
#define ent(a)      scanf("%lld",&a)
#define ent2(a,b)   scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a)      memset(a,0,sizeof(a))
#define mem1(a)     memset(a,-1,sizeof(a))
#define vec(v,s)    vector<ll>v[s]
#define arr(a,s)    ll a[s]
//#define check(n,pos) (n&(1<<pos))
//#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 500003

ll dis[ma],c[ma],sub[ma],ans[ma],n,a[ma];
ll mp[ma],cn=0;
vector<pair<ll,ll> >adj[ma];
map<ll,ll>mp1;

void dfs(ll u)
{
 sub[u]=1;
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  dis[p]=dis[u]+adj[u][i].ss;
  dfs(p);
  sub[u]+=sub[p];
 }
}

ll tree[ma];

void update(ll x,ll val)
{
 while(x<=cn)
 {
  tree[x]+=val;
  x+=x&(-x);
 }
}

ll query(ll x)
{
 ll s=0;
 while(x>0)
 {
  s+=tree[x];
  x-=x&(-x);
 }
 return s;
}

void add(ll u,ll par)
{
 ll i,k=0;
 ll r=mp1[dis[u]-a[u]];

 update(r,1);
// cout<<r+1<<endl;
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par||mp[p]==1)continue;
  add(p,u);
 }
}

void rem(ll u,ll par)
{
 ll i,k=0;
 ll r=mp1[dis[u]-a[u]];
 update(r,-1);
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par||mp[p]==1)continue;
  rem(p,u);
 }
}

void dsu(ll u,ll par,ll f)
{
 ll mx=-1,big=-1;
 ll i;
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par)continue;
  if(sub[p]>mx)
  {
   mx=sub[p],big=p;
  }
 }
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par||p==big)continue;
  dsu(p,u,0);
 }

 if(big!=-1)
 {
  dsu(big,u,1);
  mp[big]=1;
 }
 add(u,par);
 ll pq=query(mp1[dis[u]]);
 ans[u]=pq-1;
 if(big!=-1)mp[big]=0;
 if(f==0)
 {
  rem(u,par);
 }

}

int main()
{
 ll i,x;
 while(cin>>n)
 {

  f(i,1,n+1)ent(a[i]);
  f(i,2,n+1)
  {
   ent2(x,c[i]);
   if(i>1)adj[x].pb(mk(i,c[i]));
  }
  f(i,0,ma)
  {
   tree[i]=0;
   mp[i]=0;
  }
  dis[1]=0;
  dfs(1);

  vector<ll>v;
  f(i,1,n+1)
  {
   v.pb(dis[i]);
   v.pb(dis[i]-a[i]);
  }

  sort(v.begin(),v.end());
   cn=0;

  f(i,0,v.sz)
  {
   if(mp1[v[i]]==0)mp1[v[i]]=++cn;
  }

  dsu(1,-1,0);

  f(i,1,n+1)
  {
   cout<<ans[i]<<" ";
  }
  cout<<endl;

 }

 return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#define ll          long long int
#define db          double
#define pf          printf
#define sf          scanf
#define ff          first
#define ss          second
#define clr         clear()
#define sz          size()
#define pb          push_back
#define mk          make_pair
#define pi          acos(-1)
#define inf         1000000000000000005
#define mod          998244353

#define q(n)        q.push(n)
#define ull         unsigned long long int
#define f(i,k,n)    for(ll i=k;i<n;i++)
#define fr(i,n,k)   for(ll i=n;i>=k;i--)
#define ent(a)      scanf("%lld",&a)
#define ent2(a,b)   scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a)      memset(a,0,sizeof(a))
#define mem1(a)     memset(a,-1,sizeof(a))
#define vec(v,s)    vector<ll>v[s]
#define arr(a,s)    ll a[s]
//#define check(n,pos) (n&(1<<pos))
//#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 400005

ll dis[ma],c[ma],sub[ma],ans[ma],n,a[ma];
ll mp[ma],cn=0;
vector<pair<ll,ll> >adj[ma];
map<ll,ll>mp1;

void dfs(ll u)
{
 sub[u]=1;
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  dis[p]=dis[u]+adj[u][i].ss;
  dfs(p);
  sub[u]+=sub[p];
 }
}

ll tree[ma];

void update(ll x,ll val)
{
 while(x<=cn)
 {
  tree[x]+=val;
  x+=x&(-x);
 }
}

ll query(ll x)
{
 ll s=0;
 while(x>0)
 {
  s+=tree[x];
  x-=x&(-x);
 }
 return s;
}

void add(ll u,ll par)
{
 ll i,k=0;
 ll r=mp1[dis[u]-a[u]];

 update(r,1);
// cout<<r+1<<endl;
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par||mp[p]==1)continue;
  add(p,u);
 }
}

void rem(ll u,ll par)
{
 ll i,k=0;
 ll r=mp1[dis[u]-a[u]];
 update(r,-1);
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par||mp[p]==1)continue;
  rem(p,u);
 }
}

void dsu(ll u,ll par,ll f)
{
 ll mx=-1,big=-1;
 ll i;
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par)continue;
  if(sub[p]>mx)
  {
   mx=sub[p],big=p;
  }
 }
 f(i,0,adj[u].sz)
 {
  ll p=adj[u][i].ff;
  if(p==par||p==big)continue;
  dsu(p,u,0);
 }

 if(big!=-1)
 {
  dsu(big,u,1);
  mp[big]=1;
 }
 add(u,par);
 ll pq=query(mp1[dis[u]]);
 ans[u]=pq-1;
 if(big!=-1)mp[big]=0;
 if(f==0)
 {
  rem(u,par);
 }

}

int main()
{
 ll i,x;
 ent(n);

  f(i,1,n+1)ent(a[i]);
  f(i,2,n+1)
  {
   ent2(x,c[i]);
   if(i>1)adj[x].pb(mk(i,c[i]));
  }
  f(i,0,ma)
  {
   tree[i]=0;
   mp[i]=0;
  }
  dis[1]=0;
  dfs(1);

  vector<ll>v;
  f(i,1,n+1)
  {
   v.pb(dis[i]);
   v.pb(dis[i]-a[i]);
  }

  sort(v.begin(),v.end());
   cn=0;

  f(i,0,v.sz)
  {
   if(mp1[v[i]]==0)mp1[v[i]]=++cn;
  }

  dsu(1,-1,0);

  f(i,1,n+1)
  {
   pf("%lld ",ans[i]);
  }
  pf("\n");

 return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
using namespace std;
using namespace std::chrono;

const int mxn = 2e5+10;
vector<pair<int,int>>g[mxn];
int val[mxn];
int ans[mxn];
int st[mxn];
int dist[mxn];
int en[mxn];
void dfs(int node,int d,int m,int par){
    dist[m] = d;
    int i = lower_bound(dist,dist+m,dist[m]-val[node]) - dist;
    if(i!=m){
    	  st[i]++;
        en[m-1]++;
    }
    for(auto x:g[node]){
    	if(x.first!=par){
    		dfs(x.first,dist[m] + x.second,m+1,node);
    	}
    }
    ans[node]+= en[m];
    en[m-1]+=  (en[m] - st[m]);
    en[m]=0;
    st[m]=0;
}
void snow(){

   int n;
   cin>>n;
   for(int i=0;i<n;i++){
   	cin>>val[i];
   }
   for(int i=0;i<mxn;i++){
   	ans[i]=0;
   	dist[i]=0;
   	st[i]=0;
   	en[0];
   }
   for(int i=1;i<n;i++){
   	int a,w;
   	cin>>a>>w;
   	a--;
   	g[a].pb(mp(i,w));
    g[i].pb(mp(a,w));
   }
   dfs(0,0,0,0);
   for(int i=0;i<n;i++){
   	 cout<<ans[i]<<" ";
   }
   cout<<endl;
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
	  freopen("input.txt","r",stdin);
	  freopen("output.txt","w",stdout);
    #endif
    fastio;
    int t;t=1;
    while(t--)
    snow();
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
using namespace std;
using namespace std::chrono;

const int mxn = 2e5+10;
vector<pair<int,int>>g[mxn];
int val[mxn];
int ans[mxn];
int st[mxn];
int dist[mxn];
int en[mxn];
void dfs(int node,int d,int m,int par){
    dist[m] = d;
    int i = lower_bound(dist,dist+m,dist[m]-val[node]) - dist;
    if(i!=m){
    	  st[i]++;
        en[m-1]++;
    }
    for(auto x:g[node]){
    	if(x.first!=par){
    		dfs(x.first,dist[m] + x.second,m+1,node);
    	}
    }
    ans[node]+= en[m];
    en[m-1]+=  (en[m] - st[m]);
    en[m]=0;
    st[m]=0;
}
void snow(){

   int n;
   cin>>n;
   for(int i=0;i<n;i++){
   	cin>>val[i];
   }
   for(int i=0;i<mxn;i++){
   	ans[i]=0;
   	dist[i]=0;
   	st[i]=0;
   	en[0];
   }
   for(int i=1;i<n;i++){
   	int a,w;
   	cin>>a>>w;
   	a--;
   	g[a].pb(mp(i,w));
    g[i].pb(mp(a,w));
   }
   dfs(0,0,0,0);
   for(int i=0;i<n;i++){
   	 cout<<ans[i]<<" ";
   }
   cout<<endl;
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
	  freopen("input.txt","r",stdin);
	  freopen("output.txt","w",stdout);
    #endif
    fastio;
    int t;t=1;
    while(t--)
    snow();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[200100],s[200100],dist[200100],ans[200100],sum[200100];
vector<pair<int,int>> x[200100];

void dfs(int curr , int depth){
    s[depth] = dist[curr];
    for(pair<int,int> i : x[curr]){
        dist[i.first] = i.second + dist[curr];
        dfs(i.first, depth + 1);
    }
    sum[depth-1] += 1;
    sum[lower_bound(s,s+depth,dist[curr]-a[curr]) - s - 1] -= 1;
    ans[curr] = sum[depth];
    sum[depth-1] += ans[curr];
    sum[depth] = 0;
}

int main()
{
    int n,b,c;
    cin >> n;
    for(int i = 1 ; i <= n ; i += 1){
        cin >> a[i];
    }
    for(int i = 2 ; i <= n ; i += 1){
        cin >> b >> c;
        x[b].push_back({i,c});
    }
    dfs(1,1);
    for(int i = 1 ; i <= n ; i += 1){
        cout << ans[i] << " ";
    }
}


#include <bits/stdc++.h>
using namespace std;
long long a[200100],s[200100],dist[200100],ans[200100],sum[200100];
vector<pair<long long,long long>> x[200100];

void dfs(long long curr , long long depth){
    s[depth] = dist[curr];
    for(pair<long long,long long> i : x[curr]){
        dist[i.first] = i.second + dist[curr];
        dfs(i.first, depth + 1);
    }
    sum[depth-1] += 1;
    sum[lower_bound(s,s+depth,dist[curr]-a[curr]) - s - 1] -= 1;
    ans[curr] = sum[depth];
    sum[depth-1] += ans[curr];
    sum[depth] = 0;
}

int main()
{
    long long n,b,c;
    cin >> n;
    for(long long i = 1 ; i <= n ; i += 1){
        cin >> a[i];
    }
    for(long long i = 2 ; i <= n ; i += 1){
        cin >> b >> c;
        x[b].push_back({i,c});
    }
    dfs(1,1);
    for(long long i = 1 ; i <= n ; i += 1){
        cout << ans[i] << " ";
    }
}


#include <bits/stdc++.h>
using namespace std;
int a[200100];
vector<vector<pair<int,int>>> x(200100);
vector<vector<pair<int,int>>> y(200100);

void dfs(int curr , int par){
    for(pair<int,int> i : x[curr]){
        if(i.first != par){
            dfs(i.first,curr);
            for(pair<int,int> j : y[i.first]){
                if(j.first + i.second <= j.second){
                    y[curr].push_back({j.first+i.second,j.second});
                }
            }
            if(i.second <= a[i.first]){
                y[curr].push_back({i.second,a[i.first]});
            }
        }
    }
}

int main()
{
    int n,b,c;
    cin >> n;
    for(int i = 1 ; i <= n ; i += 1){
        cin >> a[i];
    }
    for(int i = 2 ; i <= n ; i += 1){
        cin >> b >> c;
        x[b].push_back({i,c});
        x[i].push_back({b,c});
    }
    dfs(1,-1);
    for(int i = 1 ; i <= n ; i += 1){
        cout << y[i].size() << " ";
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define sf scanf
#define pf printf
#define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
using namespace std;
#define ll long long
const int N=3e5+99;
vector<pair<ll,ll> >adj[N];
ll n,a[N],ans[N];
priority_queue<ll>pq[N];
void dfs(ll s,ll d)
{
    //cout<<"s "<<s<<endl;
    for(auto it : adj[s]) {
        ll v=it.first,w=it.second;
        dfs(v,d+w);
        while(!pq[v].empty() && pq[v].top()>d) pq[v].pop();
        ans[s] += pq[v].size();
        while(!pq[v].empty()) {
            pq[s].push(pq[v].top());
            pq[v].pop();
        }
    }
    pq[s].push(d-a[s]);
}
void slv()
{
    cin >> n;
    for(ll i=1;i<=n;i++) cin >> a[i];
    for(ll i=2;i<=n;i++) {
        ll v,w;
        cin >> v >> w;
        adj[v].push_back({i,w});
    }
    dfs(1,0);
    for(ll i=1;i<=n;i++) cout<<ans[i]<<" ";
}
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    int cs=1;
    while (t--)
    {
        //cout<<"case : "<<cs++<<endl;
        slv();
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define sf scanf
#define pf printf
#define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
using namespace std;
#define ll long long
const int N=2e5+9;
vector<pair<ll,ll> >adj[N];
ll n,a[N],ans[N];
priority_queue<ll>pq[N];
void dfs(ll s,ll d)
{
    //cout<<"s "<<s<<endl;
    for(auto it : adj[s]) {
        ll v=it.first,w=it.second;
        dfs(v,d+w);
        while(!pq[v].empty() && pq[v].top()>d) pq[v].pop();
        ans[s] += pq[v].size();
        while(!pq[v].empty()) {
            pq[s].push(pq[v].top());
            pq[v].pop();
        }
    }
    pq[s].push(d-a[s]);
}
void slv()
{
    cin >> n;
    for(ll i=1;i<=n;i++) cin >> a[i];
    for(ll i=2;i<=n;i++) {
        ll v,w;
        cin >> v >> w;
        adj[v].push_back({i,w});
    }
    dfs(1,0);
    for(ll i=1;i<=n;i++) cout<<ans[i]<<" ";
}
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    int cs=1;
    while (t--)
    {
        //cout<<"case : "<<cs++<<endl;
        slv();
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define sf scanf
#define pf printf
#define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
using namespace std;
#define ll long long
const int N=2e5+9;
vector<pair<ll,ll> >adj[N];
ll n,a[N],ans[N];
priority_queue<ll>pq[N];
void dfs(ll s,ll d)
{
    //cout<<"s "<<s<<endl;
    for(auto it : adj[s]) {
        ll v=it.first,w=it.second;
        dfs(v,d+w);
        while(!pq[v].empty() && pq[v].top()>d) pq[v].pop();
        ans[s] += pq[v].size();
        if(pq[v].size() > pq[s].size()) swap(pq[v],pq[s]);
        while(!pq[v].empty()) {
            pq[s].push(pq[v].top());
            pq[v].pop();
        }
    }
    pq[s].push(d-a[s]);
}
void slv()
{
    cin >> n;
    for(ll i=1;i<=n;i++) cin >> a[i];
    for(ll i=2;i<=n;i++) {
        ll v,w;
        cin >> v >> w;
        adj[v].push_back({i,w});
    }
    dfs(1,0);
    for(ll i=1;i<=n;i++) cout<<ans[i]<<" ";
}
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    int cs=1;
    while (t--)
    {
        //cout<<"case : "<<cs++<<endl;
        slv();
    }
    return 0;
}


#include"bits/stdc++.h"
#define int long long
#define float double
#define double long double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

using namespace std;

const int N = 2e5+5, M=25;
int n;
int val[N], dp[N][M], ans[N], dist[N];
vector<pair<int,int>> edg[N];
void dfs(int node){
	ans[node] = 1;
	for(auto i:edg[node]){
		dist[i.first] += dist[node] + i.second;
		dp[i.first][0] = node;
		dfs(i.first);
	}
}
void find_lowest(int node,int val){
	int cur = node;
	for(int i=M-1;i>=0;i--){
		if(dist[dp[cur][i]]>=val)
			cur = dp[cur][i];
	}
	if(cur==1) return;
	ans[dp[cur][0]]--;
}
void dfs2(int node){
	find_lowest(node,dist[node]-val[node]);
	for(auto i:edg[node]){
		dfs2(i.first);
		ans[node] += ans[i.first];
	}
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(int i=1;i<=n;i++) cin>>val[i];
	int par,wgt;
	for(int i=2;i<=n;i++){
		cin>>par>>wgt;
		edg[par].push_back({i,wgt});
	}
	dist[1] = 0;
	dfs(1);
	for(int i=1;i<M;i++){
		for(int j=1;j<n;j++){
			if(dp[j][i-1]==-1) continue;
			dp[j][i] = dp[dp[j][i-1]][i-1];
		}
	}
	dfs2(1);
	for(int i=1;i<=n;i++) cout<<ans[i]-1<<" ";
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e2+10;
const ll p=1e9+7;
ll a[1000010],b[N],c[N],d[N];
int m;
class Matrix {
public:
     long long a[N][N];
//��ά�����ž���
    Matrix(){}
    //������ĳ�ʼ��
    void init(long long  num[N]){
        for(int i = 0 ; i < m ; i++){
            for(int j = 0 ; j < m ; j++){
                a[i][j] = num[(i-j+m)%m];
           }
       }
    }
    //���ؾ���ĳ˷�����

    friend Matrix operator*(Matrix &m1 ,Matrix &m2) {
        int i, j, k;
        Matrix temp;
        for (i = 0; i < m; i++) {
            for (j = 0; j < m; j++) {
                temp.a[i][j] = 0;
                for(k = 0 ; k < m ; k++)
                   temp.a[i][j] += (m1.a[i][k] * m2.a[k][j])%p;
                temp.a[i][j] %= p;
//ע��ÿһ��������ȡģ
           }
        }
        return temp;
    }
    //����Ŀ�����

    friend Matrix quickpow(Matrix &M , long long n){
        Matrix tempans;
//��ʼ��Ϊ��λ����
        //��ʼ��
        for(int i = 0 ; i < m ; i++){
            for(int j = 0 ; j < m ; j++){
                if(i == j)
                    tempans.a[i][j] = 1;
                else
                    tempans.a[i][j] = 0;
            }
        }
        //�����ݣ�����������
        while(n){
            if(n & 1)
                tempans = tempans * M;
//�Ѿ�������*
            n = n >> 1;
            M = M * M;
        }
       return tempans;
    }
};
Matrix A;
int main()
{
    int n,l,i,j;
    cin>>n>>l>>m;
    for(i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x==m)x=0;
        c[x]++;
    }

    for(i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x==m)x=0;
        a[i]=x;
        b[x]++;
    }
    for(i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x==m)x=0;
        d[(x+a[i])%m]++;
    }
    A.init(b);
    A=quickpow(A,l-2);
    ll ans=0;
    for(i=0;i<m;i++)
        for(j=0;j<m;j++)
        {
            //if((c[i]*d[j]*A.a[(2*m-i-j)%m][0])%p!=0)cout<<i<<' '<<j<<' '<<(2*m-i-j)%m<<' '<<(c[i]*d[j]*A.a[(2*m-i-j)%m][0])%p<<endl;
            ans+=(c[i]*d[j]*A.a[(2*m-i-j)%m][0])%p;
        }
    ans%=p;
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define N 105
#define B 1000005
#define M 1000000007
using namespace std;
typedef long long ll;// fen kuai
struct mat{
    int n,m,a[N][N];
    mat operator*(const mat &ot)
    {
        mat ans;ans.n=n;ans.m=ot.m;memset(ans.a,0,sizeof(ans.a));
        for(int i=0;i<n;++i){
            for(int k=0;k<m;++k){
                for(int j=0;j<ot.m;++j){
                    ans.a[i][j]=(0LL+ans.a[i][j]+1LL*a[i][k]*ot.a[k][j]%M)%M;
                }
            }
        }return ans;
    }
}ans,mul;
mat qpow(mat a,int b)
{
    mat ans;ans.n=ans.m=a.n;memset(ans.a,0,sizeof(ans.a));
    for(int i=0;i<ans.n;++i)ans.a[i][i]=1;
    for(;b;b>>=1,a=a*a)if(b&1)ans=ans*a;return ans;
}
int n,L,m,to[B],sum,tot[N],a[B];
int main()
{
    scanf("%d%d%d",&n,&L,&m);ans.n=1;ans.m=mul.n=mul.m=m;
    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        ans.a[0][x%m]++;
    }
    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        tot[x%m]++;a[i]=x%m;
    }for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        to[i]=x%m;
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            mul.a[i][(i+j)%m]+=tot[j];
        }
    }

    mul=qpow(mul,L-2);ans=ans*mul;
    // for(int i=0;i<m;i++)cout<<ans.a[0][i]<<' ';
    for(int i=1;i<=n;i++){
        sum=sum+ans.a[0][((-a[i]-to[i])%m+m)%m];sum%=M;
    }cout<<sum;
    return 0;
}


#include<bits/stdc++.h>
#define N 105
#define B 1000005
#define M 1000000007
using namespace std;
typedef long long ll;// fen kuai
struct mat{
    int n,m,a[N][N]={0};
    mat operator*(const mat &ot)
    {
        mat ans;ans.n=n;ans.m=ot.m;
        for(int i=0;i<n;++i){
            for(int k=0;k<m;++k){
                for(int j=0;j<ot.m;++j){
                    ans.a[i][j]=(0LL+ans.a[i][j]+1LL*a[i][k]*ot.a[k][j]%M)%M;
                }
            }
        }return ans;
    }
}ans,mul;
mat qpow(mat a,int b)
{
    mat ans;ans.n=ans.m=a.n;
    for(int i=0;i<ans.n;++i)ans.a[i][i]=1;
    for(;b;b>>=1,a=a*a)if(b&1)ans=ans*a;return ans;
}
int n,L,m,to[B],sum,tot[N],a[B];
int main()
{
    scanf("%d%d%d",&n,&L,&m);ans.n=1;ans.m=mul.n=mul.m=m;
    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        ans.a[0][x%m]++;
    }
    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        tot[x%m]++;a[i]=x%m;
    }for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        to[i]=x%m;
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            mul.a[i][(i+j)%m]+=tot[j];
        }
    }

    mul=qpow(mul,L-2);ans=ans*mul;
    // for(int i=0;i<m;i++)cout<<ans.a[0][i]<<' ';
    for(int i=1;i<=n;i++){
        sum=sum+ans.a[0][((-a[i]-to[i])%m+m)%m];sum%=M;
    }cout<<sum;
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

typedef vector<Vll> Matrix;
Matrix operator *(const Matrix& A, const Matrix& B)
{
	int n = A.size(), m = A[0].size();
	int N = B.size(), M = B[0].size();
	Matrix C= Matrix(n, Vll(M));
	if (m != N)return C;
	fup(i, 0, n - 1, 1)
	{
		fup(j, 0, M - 1, 1)
		{
			fup(k, 0, m - 1, 1)
			{
				C[i][j] += A[i][k] * B[k][j];
				C[i][j]%=MOD;
			}
		}
	}
	return C;
}
int a[101],b[101],c[101],aa[1000000],bb[1000000],cc[1000000];
Matrix mul(Matrix &A,int l)
{
	if(l==1)return A;
	if(l&1)
	{
		return mul(A,l-1)*A;
	}
	else
	{
		Matrix t=mul(A,l/2);
		return t*t;
	}
}
int main() {
	int n,l,m;
	scanf("%d%d%d",&n,&l,&m);
	fup(i,0,n-1,1)
	{
		scanf("%d",aa+i);
		a[aa[i]%m]++;
	}
	fup(i,0,n-1,1)
	{
		scanf("%d",bb+i);
		b[bb[i]%m]++;
	}
	fup(i,0,n-1,1)
	{
		int x;
		scanf("%d",&x);
		cc[i]=x+bb[i];
		c[cc[i]%m]++;
	}
	if(l==2)
	{
		int ans=0;
		fup(i,0,n-1,1)if((aa[i]+cc[i])%m==0)ans++;
		return !printf("%d",ans);
	}
	Matrix B(m,Vll(m));
	fup(i,0,m-1,1)
		fup(j,0,m-1,1)
	{
		B[i][(i+j)%m]=b[j];
	}
	B=mul(B,l-2);
	ll ans=0;
	fup(i,0,m-1,1)
		fup(j,0,m-1,1)
	{
		ll t=(a[i]*B[i][j==0?0:m-j])%MOD;
		t=(t*c[j])%MOD;
		ans=(ans+t)%MOD;
	}
	printf("%lld",ans);
}