import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from itertools import permutations as perm

n = int(readline())

p = tuple(map(int, readline().split()))

q = tuple(map(int, readline().split()))

lst = list(perm(list(range(1, n+1)),n))

lst.sort()

pn=qn=0

for i,j in enumerate(lst, 1):

  if p == j:

    pn = i

  if q == j:

    qn = i

  if pn*qn!=0:

    break

print((abs(pn-qn)))
from itertools import permutations as perm

import sys

readline = sys.stdin.buffer.readline



n = int(readline())

p = tuple(map(int, readline().split()))

q = tuple(map(int, readline().split()))



p_lst = list(perm(list(range(1, n + 1)), n))  # 排列

pn = qn = 0

for i,j in enumerate(p_lst, 1):

  if p == j:

    pn = i

  if q == j:

    qn = i

  if pn * qn != 0:

    break

print((abs(pn - qn)))
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import permutations as perm

n = int(readline())
p = tuple(map(int, readline().split()))
q = tuple(map(int, readline().split()))
lst = list(perm(list(range(1, n + 1)), n))
lst.sort()
pn = qn = 0
for i, j in enumerate(lst, 1):
    if p == j:
        pn = i
    if q == j:
        qn = i
    if pn * qn != 0:
        break
print((abs(pn - qn)))

from itertools import permutations as perm
import sys

readline = sys.stdin.buffer.readline
n = int(readline())
p = tuple(map(int, readline().split()))
q = tuple(map(int, readline().split()))
p_lst = list(perm(list(range(1, n + 1)), n))  # 排列
pn = qn = 0
for i, j in enumerate(p_lst, 1):
    if p == j:
        pn = i
    if q == j:
        qn = i
    if pn * qn != 0:
        break
print((abs(pn - qn)))

+from itertools import permutations as perm -read = sys.stdin.buffer.read -readlines = sys.stdin.buffer.readlines -from itertools import permutations as perm - -lst = list(perm(list(range(1, n + 1)), n)) -lst.sort() +p_lst = list(perm(list(range(1, n + 1)), n))  # 排列 -for i, j in enumerate(lst, 1): +for i, j in enumerate(p_lst, 1):