func_code_string: #include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char now[1 << 16], *S, *T;     if (T == S) {       T = (S = now) + fread(now, 1, 1 << 16, stdin);       if (T == S) return EOF;     }     return *S++;   }   inline long long read() {     register long long x = 0, f = 1;     char ch = gc();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = gc();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = gc();     }     return (f == 1) ? x : -x;   }   struct edge {     int to, nxt, dis;   } g[1200001];   int head[1200001], tot, n, m;   inline void made(int from, int to, int dis) {     g[++tot].to = to;     g[tot].nxt = head[from];     head[from] = tot;     g[tot].dis = dis;   }   int sz[1200001], dep[1200001], wson[1200001];   int s[1200001], a[1200001], F[10000001], ans[1200001];   void dfs0(int u, int fa) {     sz[u] = 1;     dep[u] = dep[fa] + 1;     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa) continue;       s[v] = a[v] ^ s[u] ^ g[i].dis;       dfs0(v, u);       sz[u] += sz[v];       if (sz[wson[u]] < sz[v]) wson[u] = v;     }   }   void get(int u, int fa, int wht) {     if (wht)       F[s[u]] = max(F[s[u]], dep[u]);     else       F[s[u]] = 0;     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa) continue;       get(v, u, wht);     }   }   void calc(int zx, int u, int fa) {     if (F[s[u]]) ans[zx] = max(F[s[u]] + dep[u] - 2 * dep[zx], ans[zx]);     for (int i = 0, two = 1; i < 22; i++, two <<= 1) {       if (F[s[u] ^ two])         ans[zx] = max(F[s[u] ^ two] + dep[u] - 2 * dep[zx], ans[zx]);     }     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa) continue;       calc(zx, v, u);     }   }   void doit(int u, int fa, int wht) {     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa || v == wson[u]) continue;       doit(v, u, 0);     }     if (wson[u]) doit(wson[u], u, 1);     if (F[s[u]]) ans[u] = max(F[s[u]] - dep[u], ans[u]);     for (int i = 0, two = 1; i < 22; i++, two <<= 1) {       if (F[s[u] ^ two]) ans[u] = max(F[s[u] ^ two] - dep[u], ans[u]);     }     F[s[u]] = max(F[s[u]], dep[u]);     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa || v == wson[u]) continue;       calc(u, v, u);       get(v, u, 1);     }     if (!wht) get(u, fa, 0);   }   void dfs1(int u, int fa) {     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa) continue;       dfs1(v, u);       ans[u] = max(ans[u], ans[v]);     }   }   int main() {     n = read();     for (int i = 1; i < n; i++) {       int u = read();       char ch = gc();       while (!isalpha(ch)) ch = gc();       made(i + 1, u, (1 << (ch -  a )));       made(u, i + 1, (1 << (ch -  a )));     }     dfs0(1, 0);     doit(1, 0, 0);     dfs1(1, 0);     for (int i = 1; i <= n; i++) {       printf( %d  , ans[i]);     }     return 0;   }   