import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Scanner; class Main { public static void main(String[] args) { new Main().run(); } void run() { FastScanner sc=new FastScanner(); int N=sc.nextInt(); int[] A=new int[N]; int[] B=new int[N]; int[] to=new int[N]; for(int i=0;ilast) { ans[B[i]]=true; last=to[B[i]]; } } for(int i=0;i Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }