Problem: We have a magic tree: a rooted tree on n vertices. The vertices are numbered 1 through n. Vertex 1 is the root.

The magic tree gives us magic fruit. The fruit only grows in vertices of the tree other than the root. Each vertex contains at most one piece of fruit.

It is now day 0 and no fruit is ripe yet. Each fruit will only be ripe for a single day. For each fruit, we are given the vertex v_j where it grows, the day d_j on which it will be ripe, and the amount w_j of magic juice we can extract from it if we harvest it when it is ripe.

The fruits have to be harvested by cutting some branches of the tree. On each day, you may cut as many branches of the tree as you like. The parts of the tree you cut off will fall to the ground and you can collect all the ripe fruits they contain. All fruits that fall to the ground when they are not ripe are discarded and no magic juice is collected from them.

Formally, on each day, you may erase some edges of the tree. Whenever you do so, the tree will split into multiple connected components. You then erase all components that do not contain the root and you harvest all ripe fruits those components contained.

Given is a description of the tree together with the locations, ripening days and juiciness of all m fruits. Calculate the maximum total amount of magic juice we can harvest from the tree.

Input

The first line contains three space-separated integers n (2 ≤ n ≤ 100,000), m (1 ≤ m ≤ n-1) and k (1 ≤ k ≤ 100,000) – the number of vertices, the number of fruits, and the maximum day on which a fruit may become ripe.

The following n-1 lines contain the integers p_2, ..., p_n, one per line. For each i (from 2 to n, inclusive), vertex p_i (1 ≤ p_i ≤ i-1) is the parent of vertex i.

Each of the last m lines describes one fruit. The j-th of these lines has the form "v_j\ d_j\ w_j" (2 ≤ v_j ≤ n, 1 ≤ d_j ≤ k, 1 ≤ w_j ≤ 10^9).

It is guaranteed that no vertex contains more than one fruit (i.e., the values v_j are distinct).

Output

Output a single line with a single integer, the maximum amount of magic juice we can harvest from the tree.

Scoring

Subtask 1 (6 points): n, k ≤ 20, and w_j = 1 for all j

Subtask 2 (3 points): fruits only grow in the leaves of the tree

Subtask 3 (11 points): p_i = i-1 for each i, and w_j = 1 for all j

Subtask 4 (12 points): k ≤ 2

Subtask 5 (16 points): k ≤ 20, and w_j = 1 for all j

Subtask 6 (13 points): m ≤ 1,000

Subtask 7 (22 points): w_j = 1 for all j

Subtask 8 (17 points): no additional constraints

Example

Input


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


Output


9

Note

In the example input, one optimal solution looks as follows: 

  * On day 4, cut the edge between vertices 4 and 5 and harvest a ripe fruit with 1 unit of magic juice. On the same day, cut the edge between vertices 1 and 2 and harvest 5 units of magic juice from the ripe fruit in vertex 3. 
  * On day 7, do nothing. (We could harvest the fruit in vertex 4 that just became ripe, but doing so is not optimal.) 
  * On day 9, cut the edge between vertices 1 and 4. Discard the fruit in vertex 4 that is no longer ripe, and harvest 3 units of magic juice from the ripe fruit in vertex 6. (Alternately, we could achieve the same effect by cutting the edge between vertices 4 and 6.) 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
template <typename T>
void ckmin(T& a, const T& b) {
  a = min(a, b);
}
template <typename T>
void ckmax(T& a, const T& b) {
  a = max(a, b);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace __input {
template <class T1, class T2>
void re(pair<T1, T2>& p);
template <class T>
void re(vector<T>& a);
template <class T, size_t SZ>
void re(array<T, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(double& x) {
  string t;
  re(t);
  x = stod(t);
}
template <class Arg, class... Args>
void re(Arg& first, Args&... rest) {
  re(first);
  re(rest...);
}
template <class T1, class T2>
void re(pair<T1, T2>& p) {
  re(p.first, p.second);
}
template <class T>
void re(vector<T>& a) {
  for (int i = 0; i < (int((a).size())); i++) re(a[i]);
}
template <class T, size_t SZ>
void re(array<T, SZ>& a) {
  for (int i = 0; i < (SZ); i++) re(a[i]);
}
}  // namespace __input
using namespace __input;
namespace __output {
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T, size_t SZ>
void pr(const array<T, SZ>& x);
template <class T>
void pr(const vector<T>& x);
template <class T>
void pr(const set<T>& x);
template <class T1, class T2>
void pr(const map<T1, T2>& x);
template <class T>
void pr(const T& x) {
  cout << x;
}
template <class Arg, class... Args>
void pr(const Arg& first, const Args&... rest) {
  pr(first);
  pr(rest...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
  pr("{", x.first, ", ", x.second, "}");
}
template <class T, bool pretty = true>
void prContain(const T& x) {
  if (pretty) pr("{");
  bool fst = 1;
  for (const auto& a : x) pr(!fst ? pretty ? ", " : " " : "", a), fst = 0;
  if (pretty) pr("}");
}
template <class T>
void pc(const T& x) {
  prContain<T, false>(x);
  pr("\n");
}
template <class T, size_t SZ>
void pr(const array<T, SZ>& x) {
  prContain(x);
}
template <class T>
void pr(const vector<T>& x) {
  prContain(x);
}
template <class T>
void pr(const set<T>& x) {
  prContain(x);
}
template <class T1, class T2>
void pr(const map<T1, T2>& x) {
  prContain(x);
}
void ps() { pr("\n"); }
template <class Arg>
void ps(const Arg& first) {
  pr(first);
  ps();
}
template <class Arg, class... Args>
void ps(const Arg& first, const Args&... rest) {
  pr(first, " ");
  ps(rest...);
}
}  // namespace __output
using namespace __output;
namespace __algorithm {
template <typename T>
void dedup(vector<T>& v) {
  sort((v).begin(), (v).end());
  v.erase(unique((v).begin(), (v).end()), v.end());
}
template <typename T>
typename vector<T>::iterator find(vector<T>& v, const T& x) {
  auto it = lower_bound((v).begin(), (v).end(), x);
  return it != v.end() && *it == x ? it : v.end();
}
template <typename T>
size_t index(vector<T>& v, const T& x) {
  auto it = find(v, x);
  assert(it != v.end() && *it == x);
  return it - v.begin();
}
}  // namespace __algorithm
using namespace __algorithm;
struct monostate {
  friend istream& operator>>(istream& is,
                             const __attribute__((unused)) monostate& ms) {
    return is;
  }
  friend ostream& operator<<(ostream& os,
                             const __attribute__((unused)) monostate& ms) {
    return os;
  }
} ms;
template <typename W = monostate>
struct wedge {
  int u, v, i;
  W w;
  wedge<W>(int _u = -1, int _v = -1, int _i = -1) : u(_u), v(_v), i(_i) {}
  int operator[](int loc) const { return u ^ v ^ loc; }
  friend void re(wedge& e) {
    re(e.u, e.v, e.w);
    --e.u, --e.v;
  }
  friend void pr(const wedge& e) { pr(e.u, "<-", e.w, "->", e.v); }
};
namespace __io {
void setIn(string second) { freopen(second.c_str(), "r", stdin); }
void setOut(string second) { freopen(second.c_str(), "w", stdout); }
void setIO(string second = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (int((second).size())) {
    setIn(second + ".in"), setOut(second + ".out");
  }
}
}  // namespace __io
using namespace __io;
template <typename E>
struct tree {
  int N;
  vvi adj;
  vector<E> edges;
  tree() {}
  tree(int _N) : N(_N) {
    adj.resize(N);
    edges.resize(N - 1);
  }
  tree(const vector<E>& __edges) : edges(__edges) {
    adj.resize(N = int((edges).size()) + 1);
    __init();
  }
  void __init() {
    for (int i = 0; i < (int((edges).size())); i++) {
      auto& e = edges[i];
      assert(0 <= e.u && e.u < N), adj[e.u].push_back(i);
      assert(0 <= e.v && e.v < N), adj[e.v].push_back(i);
      e.i = i;
    }
  }
  friend void re(tree& t) {
    re(t.edges);
    t.__init();
  }
  friend void pr(const tree& t) { pr("{N=", t.N, " ", t.edges, "}"); }
  template <typename T>
  void go(vector<T>& down, int loc, int ine) const {
    for (auto& ei : adj[loc])
      if (ei != ine) {
        int cloc = edges[ei][loc];
        down[loc].pre_process(down[cloc]);
        go(down, cloc, ei);
        down[loc].attach(down[cloc].extend());
      }
    down[loc].post_process();
  }
  template <typename T>
  vector<T> rooted(int root) const {
    vector<T> down(N);
    for (int i = 0; i < (N); i++) down[i] = T::leaf(i);
    go(down, root, -1);
    return down;
  }
  template <typename T>
  void again(vector<T>& down, vector<T>& up, vector<T>& entire, int loc,
             int ine) const {
    const int D = int((adj[loc]).size());
    vector<T> pref(D), suff(D);
    for (int i = 0; i < (D); i++) {
      const E& e = edges[adj[loc][i]];
      pref[i] = suff[i] = ((e.i != ine) ? down[e[loc]] : up[loc]).extend();
    }
    for (int i = 0; i < (D - 1); i++) pref[i + 1].accumulate(pref[i]);
    for (int i = (D - 1) - 1; i >= 0; i--) suff[i].accumulate(suff[i + 1]);
    for (int i = 0; i < (D); i++) {
      const E& e = edges[adj[loc][i]];
      if (e.i != ine) {
        int cloc = e[loc];
        T& cres = up[cloc] = T::leaf(loc);
        if (i) cres.attach(pref[i - 1]);
        if (i + 1 < D) cres.attach(suff[i + 1]);
        cres.post_process();
        again(down, up, entire, e[loc], e.i);
      }
    }
    entire[loc] = T::leaf(loc);
    entire[loc].accumulate(pref.back());
    entire[loc].post_process();
  }
  template <typename T>
  array<vector<T>, 3> unrooted() const {
    vector<T> down, up(N), entire(N);
    down = rooted<T>(0);
    again(down, up, entire, 0, -1);
    return {down, up, entire};
  }
};
enum { DOWN, UP, ENTIRE };
using edge = wedge<>;
vi ripen, value;
struct treedp {
  int id, size, depth;
  map<int, ll> dp;
  static treedp leaf(int id) { return {id, 1, 0, {}}; }
  void pre_process(treedp& child) { child.depth = depth + 1; }
  treedp& extend() { return *this; }
  void attach(treedp& o) {
    size += o.size;
    if (int((o.dp).size()) > int((dp).size())) swap(dp, o.dp);
    for (auto& p : o.dp) dp[p.first] += p.second;
  }
  void post_process() {
    dp[ripen[id]] += value[id];
    for (auto it = dp.upper_bound(ripen[id]);
         it != dp.end() && value[id] > 0;) {
      int reduce = min(ll(value[id]), it->second);
      value[id] -= reduce;
      if (reduce == it->second) {
        dp.erase(it++);
      } else {
        it->second -= reduce;
        it++;
      }
    }
  }
  void accumulate(const treedp& o) { size += o.size; }
  friend void pr(const treedp& second) {
    pr("{id=", second.id, " sz=", second.size, " depth=", second.depth, "}");
  }
};
int main() {
  setIO();
  int N, M, K;
  re(N, M, K);
  vector<edge> edges;
  for (int i = (1); i < (N); i++) {
    int p;
    re(p);
    edges.push_back({p - 1, i});
  }
  tree<edge> tr(edges);
  ripen.resize(N), value.resize(N);
  for (int i = 0; i < (M); i++) {
    int v, d, w;
    re(v, d, w);
    --v;
    ripen[v] = d;
    value[v] = w;
  }
  vector<treedp> ss = tr.rooted<treedp>(0);
  ll ans = 0;
  for (auto& p : ss[0].dp) ans += p.second;
  ps(ans);
  return 0;
}