import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
public static boolean check(int []ip, int []op){
Stack<Integer> st=new Stack<>();
int j=0;
for(int i=0;i<ip.length;i++){
st.push(ip[i]);
while (!st.isEmpty() && st.peek()==op[j]) {
st.pop();
j++;
}
}
return st.isEmpty();
}
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int n = sc.nextInt();
int ip[] =new int [n];
int op[] = new int [n];
for (int i=0;i<n;i++)
ip[i] = sc.nextInt();
for (int i=0;i<n;i++)
op[i] = sc.nextInt();
System.out.println(check(ip,op));
}
}
To embed this program on your website, copy the following code and paste it into your website's HTML: