func_code_string: #include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::string;   using std::vector;   static const int MOD = 1000000000 + 7;   static long long gcd(long long x, long long y) {     return (!y) ? x : gcd(y, x % y);   }   int read_int() {     int x = 0, c = 0;     c = getchar();     while (c <= 32) c = getchar();     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x;   }   static const int N = 300000 + 8;   static const int SH = 20;   int n, c1, c2;   int dep[N], fa[N][SH], p1[N], p2[N];   int lca(int a, int b) {     if (dep[a] < dep[b]) ::std::swap(a, b);     int dif = dep[a] - dep[b];     for (int i = 0; (1 << i) <= dif; i++) {       if (dif & (1 << i)) a = fa[a][i];     }     if (a == b) return a;     for (int i = SH - 1; i >= 0; i--) {       if (fa[a][i] ^ fa[b][i]) {         a = fa[a][i];         b = fa[b][i];       }     }     return fa[a][0];   }   int get(int a, int b) { return dep[a] + dep[b] - 2 * dep[lca(a, b)]; }   int solve() {     int mx = 0;     n = read_int();     p1[++c1] = 1;     for (int i = 2; i <= n + 1; i++) {       int pos = read_int();       fa[i][0] = pos;       dep[i] = dep[pos] + 1;       for (int j = 1; (1 << j) <= dep[i]; j++) {         fa[i][j] = fa[fa[i][j - 1]][j - 1];       }       int d1 = (c1 == 0 ? 0 : get(p1[1], i));       int d2 = (c2 == 0 ? 0 : get(p2[1], i));       if (d1 > mx) {         for (int j = 1; j <= c2; j++) {           if (get(p2[j], i) == d1) {             p1[++c1] = p2[j];           }         }         c2 = 1;         p2[1] = i;       } else if (d2 > mx) {         for (int j = 1; j <= c1; j++) {           if (get(p1[j], i) == d2) {             p2[++c2] = p1[j];           }         }         c1 = 1;         p1[1] = i;       } else if (d1 == mx)         p2[++c2] = i;       else if (d2 == mx)         p1[++c1] = i;       mx = ::std::max(mx, ::std::max(d1, d2));       printf( %d n , c1 + c2);     }     return 0;   }   int main(int argc, char* argv[]) {     ::std::ios::sync_with_stdio(false);     ::std::cin.tie(0);     ::std::cout.tie(0);     int test_count = 1;     while (test_count--) solve();     return 0;   }   