beecrowd | 1228

Start Grid

Maratona de Programação da SBC Brazil

Timelimit: 1

Nlogonia will hold the sensational world final of the Formula 17 drivers championship. Competitors line up at the start and compete for the race. You will have access to the start and finish grids. The question is to determine the minimum number of overtakes that were made during the competition.

Input

The input contains several test cases. Each test case uses three lines. The first line of a test case contains an integer N (2 ≤ N ≤ 24) indicating the number of competitors. Each competitor is identified by a number from 1 to N. The second line contains the N competitors in order of the starting grid. The third line of each case has the same competitors, but now in the order they finish the race.

Output

For each test case print a line containing a single integer, the minimum number of overtakes necessary to get from the starting grid to the finishing grid.

Sample Input Sample Output

5
1 2 3 4 5
3 1 2 5 4
5
3 1 2 5 4
1 2 3 4 5
5
3 1 2 5 4
5 3 2 1 4

3
3
4