Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
import java.util.*;
public class Main
{
static Scanner scn = new Scanner(System.in);
public static void main (String[] args) throws Exception
{
// your code goes here
Queue<Integer> q = new LinkedList<>();
int n = scn.nextInt();
int[] process = new int[n];
for (int i = 0; i < n; i++) {
q.add(scn.nextInt());
}
for(int i = 0;i < n;i++){
process[i] = scn.nextInt();
}
System.out.print(ImpofTime(q,process));
}
public static int ImpofTime(Queue q,int[] orig_order) throws Exception{
// Write your Code here
int n = orig_order.length;
int time=0;
for(int i=0; i<n; i++)
{
while(!q.peek().equals(orig_order[i]))
{
q.add(q.remove());
time++;
}
if(q.peek().equals(orig_order[i])){
q.remove();
time++;
}
}
//System.out.println(time);
return time;
}
}