import java.io.*; import java.util.*; class Main { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n=sc.nextInt(); int[]l=new int[n],s=new int[n]; for(int i=0;ihm=new HashMap(); Listlis=new ArrayList(); int step=0; int cur=i; while(true){ if(vis[cur])break; vis[cur]=true; hm.put(cur,step); lis.add(cur); cur=s[cur]; step++; } int min=1<<30; Integer stm=hm.get(cur); int st=stm==null?lis.size():stm; for(int j=st;j