- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.LinkedList;
- import java.util.Queue;
- import java.util.Scanner;
-
-
- /* IMPORTANT: Multiple classes and nested static classes are supported */
-
- /*
- * uncomment this if you want to read input.
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- */
-
-
- class TestClass {
- public static void main(String args[] ) throws Exception {
- /*
- * Read input from stdin and provide input before running
-
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String line = br.readLine();
- int N = Integer.parseInt(line);
- for (int i = 0; i < N; i++) {
- System.out.println("hello world");
- }
- */
-
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- Queue<Integer> queue = new LinkedList<Integer>();
- for(int i=0;i<n;i++){
- queue.add(sc.nextInt());
- }
- int[] correct = new int[n];
- for(int i=0;i<n;i++){
- correct[i] = sc.nextInt();
- }
- int time = 0;
- for(int i=0;i<n;i++){
- int num = correct[i];
- int a;
- while((a = queue.poll())!=num){
- queue.add(a);
- time++;
- }
- time++;
- }
- System.out.println(time);
-
- }
- }
Language: Java 8