#include <bits/stdc++.h>   using namespace std;   int q, n;   int par[1 << 20][32], dep[1 << 20];   int da[500000];   void add(int v) {     par[n][0] = par[n + 1][0] = v;     dep[n] = dep[n + 1] = dep[v] + 1;     for (int i = (int)(0); i < (int)(20); i++)       par[n][i + 1] = par[n + 1][i + 1] = par[par[n][i]][i];   }   int lca(int u, int v) {     if (dep[u] > dep[v]) swap(u, v);     int dif = dep[v] - dep[u];     for (int i = (int)(0); i < (int)(21); i++)       if (dif & (1 << i)) v = par[v][i];     if (u == v) return u;     for (int i = 20; i >= 0; i--)       if (par[u][i] != par[v][i]) {         u = par[u][i];         v = par[v][i];       }     return par[u][0];   }   int dist(int u, int v) { return dep[u] + dep[v] - 2 * dep[lca(u, v)]; }   void solve() {     int u = 2, v = 3, d = 2, x, i = 0, jos = q;     ;     dep[2] = dep[3] = dep[4] = 1;     par[2][0] = par[3][0] = par[4][0] = 1;     n = 5;     while (q--) {       scanf( %d , &x);       add(x);       int du = dist(n, u), dv = dist(n, v);       if (du > d)         v = n, d = du;       else if (dv > d)         u = n, d = dv;       n += 2;       da[i] = d;       i++;     }     int j;     for (j = 0; j < jos; j++) {       printf( %d n , da[j]);     }   }   int main() {     scanf( %d , &q);     solve();     return 0;   }   