var
c,d,n:longint;
a,b,ans:array[1..100000]of longint;
procedure treat(w:longint);
var
i,j:longint;
begin
i:=w;
while (b[a[i]]<>c)and(ans[a[i]]=0) do
begin
b[a[i]]:=c;
i:=a[i];
inc(ans[c]);
end;
if (ans[a[i]]>0)and(b[a[i]]<>c) then ans[c]:=ans[c]+ans[a[i]];
if b[a[i]]=c then
begin
i:=a[i];
j:=w;
while j<>i do
begin
ans[a[j]]:=ans[j]-1;
j:=a[j];
end;
j:=a[j];
while j<>i do
begin
ans[j]:=ans[i];
j:=a[j];
end;
end;
end;
begin
assign(input,'treat.in');
assign(output,'treat.out');
reset(input);
rewrite(output);
read(n);
for c:=1 to n do
read(a[c]);
for c:=1 to n do
if ans[c]=0 then
begin
ans[c]:=1;
b[c]:=c;
treat(c);
end;
for c:=1 to n do
writeln(ans[c]);
close(input);close(output);
end.