# -*- coding: utf-8 -*-

from itertools import permutations as perm



N = int(eval(input()))

P = tuple(list(map(int, input().split())))

Q = tuple(list(map(int, input().split())))



a = 0

b = 0



for Pi in sorted(perm(P)):

    if P != Pi:

        a += 1

    if P == Pi:

        a += 1

        break

    

for Qi in sorted(perm(Q)):

    if Q != Qi:

        b += 1

    if Q == Qi:

        b += 1

        break



print((abs(a-b)))
# -*- coding: utf-8 -*-

from itertools import permutations as p

N = int(eval(input()))

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

P = tuple(list(map(int, input().split())))

Q = tuple(list(map(int, input().split())))

cntp = 1

cntq = 1

for i in sorted(p(A)):

    if i != P:

        cntp += 1

    if i == P:

        cntp += 1

        break

for i in sorted(p(A)):

    if i != Q:

        cntq += 1

    if i == Q:

        cntq += 1

        break

print((abs(cntp-cntq)))
# -*- coding: utf-8 -*-
from itertools import permutations as perm

N = int(eval(input()))
P = tuple(list(map(int, input().split())))
Q = tuple(list(map(int, input().split())))
a = 0
b = 0
for Pi in sorted(perm(P)):
    if P != Pi:
        a += 1
    if P == Pi:
        a += 1
        break
for Qi in sorted(perm(Q)):
    if Q != Qi:
        b += 1
    if Q == Qi:
        b += 1
        break
print((abs(a - b)))

# -*- coding: utf-8 -*-
from itertools import permutations as p

N = int(eval(input()))
A = [i for i in range(1, N + 1)]
P = tuple(list(map(int, input().split())))
Q = tuple(list(map(int, input().split())))
cntp = 1
cntq = 1
for i in sorted(p(A)):
    if i != P:
        cntp += 1
    if i == P:
        cntp += 1
        break
for i in sorted(p(A)):
    if i != Q:
        cntq += 1
    if i == Q:
        cntq += 1
        break
print((abs(cntp - cntq)))

-from itertools import permutations as perm +from itertools import permutations as p +A = [i for i in range(1, N + 1)] -a = 0 -b = 0 -for Pi in sorted(perm(P)): -    if P != Pi: -        a += 1 -    if P == Pi: -        a += 1 +cntp = 1 +cntq = 1 +for i in sorted(p(A)): +    if i != P: +        cntp += 1 +    if i == P: +        cntp += 1 -for Qi in sorted(perm(Q)): -    if Q != Qi: -        b += 1 -    if Q == Qi: -        b += 1 +for i in sorted(p(A)): +    if i != Q: +        cntq += 1 +    if i == Q: +        cntq += 1 -print((abs(a - b))) +print((abs(cntp - cntq)))