program a1;
var
n,i,k,j,c,max,maxx:longint;
pp:boolean;
f:array[0..200000] of boolean;
s,ans,a:array[0..200000] of longint;
procedure dfs(x,mm:longint);
begin
if not(f[x]) then
begin
c:=x;
max:=mm-s[x];
ans[x]:=max;
exit;
end;
f[x]:=false;
s[x]:=mm;
dfs(a[x],mm+1);
f[x]:=true;
s[x]:=0;
if x=c then
pp:=true
else
begin
if pp then
begin
inc(maxx);
ans[x]:=maxx+max;
end
else
begin
ans[x]:=max;
end;
end;
end;
begin
assign(input,'treat.in');
reset(input);
assign(output,'treat.out');
rewrite(output);
readln(n);
for i:=1 to n do
readln(a[i]);
fillchar(f,sizeof(f),true);
for i:=1 to n do
if ans[i]=0 then
begin
pp:=false;
maxx:=0;
max:=0;
dfs(i,1);
writeln(ans[i]);
end
else
writeln(ans[i]);
close(input);
close(output);
end.