func_code_string: #include <bits/stdc++.h>   namespace FASTIO {   char buf[1 << 21];   char *p1, *p2;   template <typename T>   inline void wt(T x, char c =   n ) {     if (x < 0) {       x = -x;       putchar( - );     }     static char sta[sizeof(T) * 8];     T top = 0;     do {       sta[top++] = x % 10;       x /= 10;     } while (x);     while (top) putchar(sta[--top] +  0 );     putchar(c);   }   template <typename T>   inline T rd() {     T sum = 0, fl = 1;     char ch =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)              ? EOF              : *p1++);     for (; ch <  0  || ch >  9 ;          ch = (p1 == p2 &&                        (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                    ? EOF                    : *p1++))       if (ch ==  - )         fl = -1;       else if (ch == EOF)         exit(0);     for (;  0  <= ch && ch <=  9 ;          ch = (p1 == p2 &&                        (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                    ? EOF                    : *p1++))       sum = sum * 10 + ch -  0 ;     return sum * fl;   }   }  // namespace FASTIO   using namespace FASTIO;   const int N = 3e5 + 2, logN = 19;   int dep[N], anc[N][logN];   inline int lca(int x, int y) {     if (dep[x] < dep[y]) std::swap(x, y);     {       int dt = dep[x] - dep[y];       if (dt)         for (int i = (31 - __builtin_clz(dt)); i >= 0; i--)           if (dt & 1 << i) x = anc[x][i];     }     if (x == y) return x;     for (int i = (31 - __builtin_clz(dep[x])); i >= 0; i--)       if (anc[x][i] != anc[y][i]) {         x = anc[x][i];         y = anc[y][i];       }     return anc[x][0];   }   inline int dist(const int x, const int y) {     return dep[x] + dep[y] - dep[lca(x, y)] * 2;   }   std::vector<int> s1, s2;   int main() {     const int n = rd<int>() + 1;     s1.reserve(n + 1);     s2.reserve(n + 1);     s1.push_back(1);     dep[1] = 1;     for (int i = 2, maxd = 0, d1, d2; i <= n; i++) {       dep[i] = dep[anc[i][0] = rd<int>()] + 1;       for (int j = 1; 1 << j <= dep[i]; j++)         anc[i][j] = anc[anc[i][j - 1]][j - 1];       d1 = s1.empty() ? 0 : dist(i, s1.back());       d2 = s2.empty() ? 0 : dist(i, s2.back());       if (std::max(d1, d2) > maxd) {         maxd = std::max(d1, d2);         if (maxd != d1) {           s1.swap(s2);           std::swap(d1, d2);         }         for (const int &x : s2)           if (dist(x, i) == d1) s1.push_back(x);         s2.clear();       }       if (std::max(d1, d2) == maxd) (maxd == d1 ? s2 : s1).push_back(i);       wt(s1.size() + s2.size());     }     return 0;   }   