func_code_string: #include <bits/stdc++.h>   using namespace std;   inline int read() {     int first = 0, f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar()) {       if (ch ==  - ) f = -1;     }     for (; isdigit(ch); ch = getchar()) {       first = first * 10 + ch - 48;     }     return first * f;   }   const int mxN = 1.5e5;   const int S = 26;   int n, en, q, mxd, tot;   int fa[mxN + 3];   char c[mxN + 3];   int sonn[mxN + 3];   int dep[mxN + 3];   int tpv[mxN + 3], btv[mxN + 3], cnt[mxN + 3][S + 3], f[mxN + 3][S + 3],       g[mxN + 3];   vector<int> son[mxN + 3];   int main() {     n = read(), q = read();     for (int i = 2; i <= n; i++) {       scanf( %d%*c%c , &fa[i], &c[i]);       sonn[fa[i]]++;       c[i] = c[i] ==  ?  ? 27 : c[i] - 96;     }     for (int u = 2; u <= n; u++) {       dep[u] = dep[fa[u]] + 1;       mxd = max(mxd, dep[u]);     }     for (int u = 1; u <= n; u++)       if (sonn[u] == 0 && dep[u] < mxd) {         for (int i = 1; i <= q; i++) puts( Fou );         return 0;       }     tpv[1] = 1;     btv[1] = 1;     for (int u = 2; u <= n; u++) {       if (sonn[fa[u]] == 1) {         tpv[u] = tpv[fa[u]];       } else {         tpv[u] = fa[u];       }       if (sonn[u] != 1) {         int v = u;         while (v != tpv[u]) {           btv[v] = u;           cnt[u][c[v]]++;           v = fa[v];         }       }     }     for (int u = n; u >= 2; u--)       if (btv[u] == u) {         for (int i = 1; i <= S; i++) {           f[tpv[u]][i] = max(f[tpv[u]][i], f[u][i] + cnt[u][i]);         }         son[tpv[u]].push_back(u);       }     for (int u = 1; u <= n; u++)       if (btv[u] == u) {         for (int i = 1; i <= S; i++) g[u] += f[u][i];         if (g[u] > mxd - dep[u]) {           tot++;         }       }     while (q--) {       int u;       char ch, ch0;       scanf( %d%*c%c , &u, &ch);       ch = ch ==  ?  ? 27 : ch - 96;       ch0 = c[u];       int u0 = btv[u];       cnt[u0][ch0]--;       c[u] = ch;       cnt[u0][ch]++;       while (1) {         u0 = tpv[u0];         if (g[u0] > mxd - dep[u0]) {           tot--;         }         if (ch0 <= S) {           g[u0] -= f[u0][ch0];         }         if (ch <= S) {           g[u0] -= f[u0][ch];         }         f[u0][ch0] = 0, f[u0][ch] = 0;         for (int i = 0; i < son[u0].size(); i++)           f[u0][ch0] = max(f[u0][ch0], f[son[u0][i]][ch0] + cnt[son[u0][i]][ch0]);         for (int i = 0; i < son[u0].size(); i++)           f[u0][ch] = max(f[u0][ch], f[son[u0][i]][ch] + cnt[son[u0][i]][ch]);         if (ch0 <= S) {           g[u0] += f[u0][ch0];         }         if (ch <= S) {           g[u0] += f[u0][ch];         }         if (g[u0] > mxd - dep[u0]) {           tot++;         }         if (u0 == 1) {           break;         }       }       if (tot) {         puts( Fou );       } else {         printf( Shi  );         int ans = 0;         for (int i = 1; i <= S; i++) ans += (f[1][i] + mxd - g[1]) * i;         printf( %d n , ans);       }     }     return 0;   }   