func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long p = 1000000007;   int q[200005][3];   int n, cnt = 1;   vector<int> c[200005];   int v[200005];   int l[200005];   int r[200005];   int f[200005];   long long rev[200005];   void eec_solve(long long& a, const long long x, long long& b,                  const long long y) {     if (y == 0) {       a = 1;       b = 0;       return;     }     long long q = x / y, r = x % y, c = 0, d = 0;     eec_solve(c, y, d, r);     a = d;     b = c - a * q;   }   int solve_lr(int ind, int cur) {     l[ind] = cur;     int tmp = 1;     for (int i = 0; i < c[ind].size(); ++i) tmp += solve_lr(c[ind][i], cur + tmp);     r[ind] = cur + tmp - 1;     return tmp;   }   struct seg {     long long v, c;   };   seg segt[800005];   void init(int x, int ll, int rr) {     segt[x].v = 0;     segt[x].c = 1;     if (ll != rr) {       segt[x].v = 0;       segt[x].c = 1;       int k = (ll + rr) / 2;       init(x * 2, ll, k);       init(x * 2 + 1, k + 1, rr);     }   }   void insert(int ind, int v) {     int x = 1, ll = 1, rr = cnt, k;     long long cum = v;     while (ll != rr) {       k = (ll + rr) / 2;       if (ind <= k) {         x = x * 2;         rr = k;       } else {         x = x * 2 + 1;         ll = k + 1;       }     }     while (x > 0) {       segt[x].v = (segt[x].v + cum) % p;       cum = (cum * segt[x].c) % p;       x = x / 2;     }   }   void change(int x, int ll, int rr, int i, int j, int cc) {     if ((ll == i) && (rr == j)) {       segt[x].c = (((segt[x].c * rev[cc]) % p) * (cc + 1)) % p;       return;     }     int k = (ll + rr) / 2;     if (i <= k) change(x * 2, ll, k, i, min(k, j), cc);     if (j > k) change(x * 2 + 1, k + 1, rr, max(i, k + 1), j, cc);     segt[x].v =         (segt[x * 2].v * segt[x * 2].c + segt[x * 2 + 1].v * segt[x * 2 + 1].c) %         p;   }   long long sum(int x, int ll, int rr, int i, int j) {     if ((ll == i) && (rr == j)) return (segt[x].v * segt[x].c) % p;     int k = (ll + rr) / 2;     long long res = 0;     if (i <= k) res += sum(x * 2, ll, k, i, min(k, j));     if (j > k) res += sum(x * 2 + 1, k + 1, rr, max(i, k + 1), j);     return ((res % p) * segt[x].c) % p;   }   long long getC(int ind) {     long long res = 1;     int x = 1, ll = 1, rr = cnt, k;     while (ll != rr) {       res = (res * segt[x].c) % p;       k = (ll + rr) / 2;       if (ind <= k) {         x = x * 2;         rr = k;       } else {         x = x * 2 + 1;         ll = k + 1;       }     }     res = (res * segt[x].c) % p;     return res;   }   int main() {     cin >> v[1] >> n;     for (int i = 0; i < n; ++i) {       cin >> q[i][0] >> q[i][1];       if (q[i][0] == 1) {         cin >> q[i][2];         v[++cnt] = q[i][2];         c[q[i][1]].push_back(cnt);         f[cnt] = q[i][1];         q[i][2] = c[q[i][1]].size();       }     }     for (int i = 1; i <= cnt; ++i) {       eec_solve(rev[i], i, rev[i + 1], p);       rev[i] = ((rev[i] % p) + p) % p;     }     solve_lr(1, 1);     init(1, 1, cnt);     insert(1, v[1]);     int new_cnt = 1;     for (int i = 0; i < n; ++i)       if (q[i][0] == 1) {         ++new_cnt;         insert(l[new_cnt], v[new_cnt]);         change(1, 1, cnt, l[q[i][1]], r[q[i][1]], q[i][2]);       } else {         long long res = sum(1, 1, cnt, l[q[i][1]], r[q[i][1]]);         if (q[i][1] != 1) {           long long x = getC(l[f[q[i][1]]]);           long long ta, tb;           eec_solve(ta, x, tb, p);           ta = ((ta % p) + p) % p;           res = (res * ta) % p;         }         cout << res << endl;       }     return 0;   }   