void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto g=new int[][](n+1, 0);
  auto can=new int[](n+1);

  void f(int i){
    if(g[i].length==0){can[i]=0; return;}
    foreach(j; g[i]) f(j);
    foreach(j; g[i])if(can[j]==0){
      can[i]=can[j]=1;
    }
    can[i]=max(can[i], 0);
  }

  foreach(i; 1..n+1){
    int p; rd(p);
    g[p]~=i;
    fill(can, -1);
    f(0);
    int sm=reduce!("a+max(0, b)")(0, can);
    assert(sm%2==0);
    writeln(sm/2);
    // writeln(can);
  }

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}