#include <cstdio>
//----------------------------------------------------
int n;
int i,j,k;
int next[110000];
int che[110000];
int set[110000];
int sta[110000],tai;
int ans[110000];
//----------------------------------------------------
int main( )
{
freopen( "treat.in" , "r" , stdin );
freopen( "treat.out" , "w" , stdout );
scanf("%d",&n);
for (i=1; i<=n; i++)
scanf("%d",&next[i]);
for (i=1; i<=n; i++)
if (!ans[i])
{
for (j=i+(tai=0); !che[j]; j=next[j])
{
che[j]=1;
set[j]=++tai;
sta[tai]=j;
}
if (ans[j])
for (ans[sta[tai]]=ans[j]+1; --tai; )
ans[sta[tai]]=ans[sta[tai+1]]+1;
else
{
for (k=tai; k>=set[j]; k--)
ans[sta[k]]=tai-set[j]+1;
for (; k; k--)
ans[sta[k]]=ans[sta[k+1]]+1;
}
}
for (i=1; i<=n; i++)
printf("%d\n",ans[i]);
}