from itertools import permutations as perm





def inpl():

    return list(map(int, input().split()))





N = int(eval(input()))

P = tuple(inpl())

Q = tuple(inpl())



A = list(perm([i for i in range(1, N + 1)]))

A.sort()



for i, a in enumerate(A):

    # print(a)

    if a == P:

        p = i

    if a == Q:

        q = i



print((abs(p - q)))

from itertools import permutations as perm





def inpl():

    return tuple(map(int, input().split()))





N = int(eval(input()))

P = inpl()

Q = inpl()



for i, p in enumerate(perm([j+1 for j in range(N)])):

    if p == P:

        pi = i

    if p == Q:

        qi = i

print((abs(pi-qi)))

from itertools import permutations as perm


def inpl():
    return list(map(int, input().split()))


N = int(eval(input()))
P = tuple(inpl())
Q = tuple(inpl())
A = list(perm([i for i in range(1, N + 1)]))
A.sort()
for i, a in enumerate(A):
    # print(a)
    if a == P:
        p = i
    if a == Q:
        q = i
print((abs(p - q)))

from itertools import permutations as perm


def inpl():
    return tuple(map(int, input().split()))


N = int(eval(input()))
P = inpl()
Q = inpl()
for i, p in enumerate(perm([j + 1 for j in range(N)])):
    if p == P:
        pi = i
    if p == Q:
        qi = i
print((abs(pi - qi)))

-    return list(map(int, input().split())) +    return tuple(map(int, input().split())) -P = tuple(inpl()) -Q = tuple(inpl()) -A = list(perm([i for i in range(1, N + 1)])) -A.sort() -for i, a in enumerate(A): -    # print(a) -    if a == P: -        p = i -    if a == Q: -        q = i -print((abs(p - q))) +P = inpl() +Q = inpl() +for i, p in enumerate(perm([j + 1 for j in range(N)])): +    if p == P: +        pi = i +    if p == Q: +        qi = i +print((abs(pi - qi)))