#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
const long double PI = acos((long double)(-1));
using namespace std;
struct LCA {
  static const int BITLEN_MAX = 20;
  vector<int> parent[BITLEN_MAX];
  vector<long long> len[BITLEN_MAX];
  vector<int> depth;
  int bitlen;
  LCA() {}
  LCA(int N, vector<vector<pair<int, long long>>> edges, int root) {
    initialize(N, edges, root);
  }
  void initialize(int N, vector<vector<pair<int, long long>>>& edges,
                  int root) {
    bitlen = 1;
    while ((1 << bitlen) < N) bitlen += 1;
    for (int i = 0; i < bitlen; i++) parent[i].resize(N), len[i].resize(N);
    depth.resize(N, -1);
    dfs(root, -1, 0, 0, edges);
    for (int k = 0; k < bitlen - 1; k++) {
      for (int v = 0; v < N; v++) {
        if (depth[v] == -1) continue;
        if (parent[k][v] < 0) {
          parent[k + 1][v] = -1;
          len[k + 1][v] = 0;
        } else {
          parent[k + 1][v] = parent[k][parent[k][v]];
          len[k + 1][v] = len[k][v] + len[k][parent[k][v]];
        }
      }
    }
  }
  void dfs(int v, int p, int d, int plen,
           vector<vector<pair<int, long long>>>& edges) {
    parent[0][v] = p;
    len[0][v] = plen;
    depth[v] = d;
    for (auto u : edges[v]) {
      if (u.first != p) dfs(u.first, v, d + 1, u.second, edges);
    }
  }
  int calc_lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < bitlen; k++) {
      if (((depth[v] - depth[u]) >> k) & 1) v = parent[k][v];
    }
    if (u == v) return u;
    for (int k = bitlen - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
  int calc_dist(int u, int v) {
    int l = calc_lca(u, v);
    return depth[u] + depth[v] - depth[l] * 2;
  }
};
void dfs(int cur, int pre, vector<int>& res,
         vector<vector<pair<int, long long>>>& g) {
  for (auto nxt : g[cur]) {
    if (nxt.first == pre) continue;
    dfs(nxt.first, cur, res, g);
    res[cur] += res[nxt.first];
  }
}
int main() {
  int n;
  scanf("%d", &n);
  vector<long long> a(n);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  vector<vector<pair<int, long long>>> g(n);
  for (int i = 1; i < n; i++) {
    long long p, w;
    scanf("%lld %lld", &p, &w);
    p--;
    g[i].emplace_back(p, w);
    g[p].emplace_back(i, w);
  }
  LCA lca(n, g, 0);
  vector<int> res(n);
  for (int i = 0; i < n; i++) {
    int lf = 0;
    int rg = lca.depth[i] + 1;
    while (rg - lf > 1) {
      int mid = (lf + rg) >> 1;
      int cur = i;
      long long t = 0;
      for (int bit = lca.bitlen - 1; bit >= 0; bit--) {
        if (mid >> bit & 1) {
          t += lca.len[bit][cur];
          cur = lca.parent[bit][cur];
        }
      }
      if (t <= a[i])
        lf = mid;
      else
        rg = mid;
    }
    int cur = i;
    for (int bit = lca.bitlen - 1; bit >= 0; bit--) {
      if (lf >> bit & 1) {
        cur = lca.parent[bit][cur];
      }
    }
    if (lca.parent[0][cur] != -1) res[lca.parent[0][cur]]--;
    if (lca.parent[0][i] != -1) res[lca.parent[0][i]]++;
  }
  dfs(0, -1, res, g);
  for (int i = 0; i < n; i++) printf("%d%c", res[i], " \n"[i + 1 == n]);
  return 0;
}

### Prompt

In cpp, your task is to solve the following problem:

Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges).

Let's define dist(v, u) as the sum of the integers written on the edges of the simple path from v to u.

The vertex v controls the vertex u (v ≠ u) if and only if u is in the subtree of v and dist(v, u) ≤ au.

Alyona wants to settle in some vertex. In order to do this, she wants to know for each vertex v what is the number of vertices u such that v controls u.

Input

The first line contains single integer n (1 ≤ n ≤ 2·105).

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the integers written in the vertices.

The next (n - 1) lines contain two integers each. The i-th of these lines contains integers pi and wi (1 ≤ pi ≤ n, 1 ≤ wi ≤ 109) — the parent of the (i + 1)-th vertex in the tree and the number written on the edge between pi and (i + 1).

It is guaranteed that the given graph is a tree.

Output

Print n integers — the i-th of these numbers should be equal to the number of vertices that the i-th vertex controls.

Examples

Input

5
2 5 1 4 6
1 7
1 1
3 5
3 6


Output

1 0 1 0 0


Input

5
9 7 8 6 5
1 1
2 1
3 1
4 1


Output

4 3 2 1 0

Note

In the example test case the vertex 1 controls the vertex 3, the vertex 3 controls the vertex 5 (note that is doesn't mean the vertex 1 controls the vertex 5).

### Response

```cpp
#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
const long double PI = acos((long double)(-1));
using namespace std;
struct LCA {
  static const int BITLEN_MAX = 20;
  vector<int> parent[BITLEN_MAX];
  vector<long long> len[BITLEN_MAX];
  vector<int> depth;
  int bitlen;
  LCA() {}
  LCA(int N, vector<vector<pair<int, long long>>> edges, int root) {
    initialize(N, edges, root);
  }
  void initialize(int N, vector<vector<pair<int, long long>>>& edges,
                  int root) {
    bitlen = 1;
    while ((1 << bitlen) < N) bitlen += 1;
    for (int i = 0; i < bitlen; i++) parent[i].resize(N), len[i].resize(N);
    depth.resize(N, -1);
    dfs(root, -1, 0, 0, edges);
    for (int k = 0; k < bitlen - 1; k++) {
      for (int v = 0; v < N; v++) {
        if (depth[v] == -1) continue;
        if (parent[k][v] < 0) {
          parent[k + 1][v] = -1;
          len[k + 1][v] = 0;
        } else {
          parent[k + 1][v] = parent[k][parent[k][v]];
          len[k + 1][v] = len[k][v] + len[k][parent[k][v]];
        }
      }
    }
  }
  void dfs(int v, int p, int d, int plen,
           vector<vector<pair<int, long long>>>& edges) {
    parent[0][v] = p;
    len[0][v] = plen;
    depth[v] = d;
    for (auto u : edges[v]) {
      if (u.first != p) dfs(u.first, v, d + 1, u.second, edges);
    }
  }
  int calc_lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < bitlen; k++) {
      if (((depth[v] - depth[u]) >> k) & 1) v = parent[k][v];
    }
    if (u == v) return u;
    for (int k = bitlen - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
  int calc_dist(int u, int v) {
    int l = calc_lca(u, v);
    return depth[u] + depth[v] - depth[l] * 2;
  }
};
void dfs(int cur, int pre, vector<int>& res,
         vector<vector<pair<int, long long>>>& g) {
  for (auto nxt : g[cur]) {
    if (nxt.first == pre) continue;
    dfs(nxt.first, cur, res, g);
    res[cur] += res[nxt.first];
  }
}
int main() {
  int n;
  scanf("%d", &n);
  vector<long long> a(n);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  vector<vector<pair<int, long long>>> g(n);
  for (int i = 1; i < n; i++) {
    long long p, w;
    scanf("%lld %lld", &p, &w);
    p--;
    g[i].emplace_back(p, w);
    g[p].emplace_back(i, w);
  }
  LCA lca(n, g, 0);
  vector<int> res(n);
  for (int i = 0; i < n; i++) {
    int lf = 0;
    int rg = lca.depth[i] + 1;
    while (rg - lf > 1) {
      int mid = (lf + rg) >> 1;
      int cur = i;
      long long t = 0;
      for (int bit = lca.bitlen - 1; bit >= 0; bit--) {
        if (mid >> bit & 1) {
          t += lca.len[bit][cur];
          cur = lca.parent[bit][cur];
        }
      }
      if (t <= a[i])
        lf = mid;
      else
        rg = mid;
    }
    int cur = i;
    for (int bit = lca.bitlen - 1; bit >= 0; bit--) {
      if (lf >> bit & 1) {
        cur = lca.parent[bit][cur];
      }
    }
    if (lca.parent[0][cur] != -1) res[lca.parent[0][cur]]--;
    if (lca.parent[0][i] != -1) res[lca.parent[0][i]]++;
  }
  dfs(0, -1, res, g);
  for (int i = 0; i < n; i++) printf("%d%c", res[i], " \n"[i + 1 == n]);
  return 0;
}

```