func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000001;   const long long LINF = 1000000000000000001LL;   struct ITree {     vector<vector<long long>> T;     int p = 1;     int par(int x) { return (x - 1) / 2; }     ITree(vector<long long> &E) {       int n = (int)(E).size();       while (p < n) p *= 2;       T.resize(2 * p - 1);       for (int i = (0); i <= (n - 1); ++i) {         int v = i + p - 1;         T[v].push_back(E[i]);         while (v) {           v = par(v);           T[v].push_back(E[i]);         }       }       for (int i = (0); i <= ((int)(T).size() - 1); ++i)         sort(T[i].begin(), T[i].end());     }     int Count(int v, long long valL, long long valR) {       return upper_bound(T[v].begin(), T[v].end(), valR) -              lower_bound(T[v].begin(), T[v].end(), valL);     }     int Query(int l, int r, long long valL, long long valR) {       if (l > r) return 0;       l += p - 1;       r += p - 1;       int ans = Count(l, valL, valR);       if (l < r) ans += Count(r, valL, valR);       while (par(l) != par(r)) {         if (l % 2 == 1) ans += Count(l + 1, valL, valR);         if (r % 2 == 0) ans += Count(r - 1, valL, valR);         l = par(l);         r = par(r);       }       return ans;     }   };   void dfs(int v, vector<vector<pair<int, int>>> &g, vector<long long> &depth,            vector<int> &in, vector<int> &out, int &t) {     in[v] = ++t;     for (auto &e : g[v]) {       int u = e.first, len = e.second;       depth[u] = depth[v] + len;       dfs(u, g, depth, in, out, t);     }     out[v] = t;   }   vector<int> solve(int n, vector<int> &a, vector<vector<pair<int, int>>> &g) {     vector<long long> depth(n, 0);     vector<int> in(n), out(n);     int t = -1;     dfs(0, g, depth, in, out, t);     vector<long long> value(n);     for (int i = (0); i <= (n - 1); ++i) {       value[in[i]] = depth[i] - a[i];     }     ITree tree(value);     vector<int> ans(n);     for (int i = (0); i <= (n - 1); ++i) {       ans[i] = tree.Query(in[i] + 1, out[i], -LINF, depth[i]);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = (0); i <= (n - 1); ++i) {       cin >> a[i];     }     vector<vector<pair<int, int>>> g(n);     for (int i = (1); i <= (n - 1); ++i) {       int p, len;       cin >> p >> len;       p--;       g[p].push_back({i, len});     }     vector<int> ans = solve(n, a, g);     for (int i = (0); i <= (n - 1); ++i) {       cout << ans[i] <<    ;     }     return 0;   }   