ll@n,@p[n],s[n+1]{},v[],i,j,k;rep(i,n)v[p[i]]=i;rep(a,1,n+1)if(!s[i=v[a]]){for(j=k=i+1;s[j];j=s[j]);for(;s[k];k=s[k])s[k]=j;if(j