n = int(eval(input()))

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

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



import itertools

X= []

a = 0

b = 0

for p in itertools.permutations(list(range(1, n+1))):

    for i in range(n):

        if p[i] < P[i]:

            a += 1

            break

        elif p[i] > P[i]:

            break

        else:

            continue

    for i in range(n):

        if p[i] < Q[i]:

            b += 1

            break

        elif p[i] > Q[i]:

            break

        else:

            continue



print((abs((a+1)-(b+1))))

n = int(eval(input()))

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

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

##print(P)

#print(Q)

import itertools

X = []

for p in itertools.permutations(list(range(1, n+1))):

    X.append(p)

#print(X)

for i in range(len(X)):

    if P == X[i]:

        a = i

        break

for i in range(len(X)):

    if Q == X[i]:

        b = i

        break

print((abs(a-b)))

n = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
import itertools

X = []
a = 0
b = 0
for p in itertools.permutations(list(range(1, n + 1))):
    for i in range(n):
        if p[i] < P[i]:
            a += 1
            break
        elif p[i] > P[i]:
            break
        else:
            continue
    for i in range(n):
        if p[i] < Q[i]:
            b += 1
            break
        elif p[i] > Q[i]:
            break
        else:
            continue
print((abs((a + 1) - (b + 1))))

n = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
##print(P)
# print(Q)
import itertools

X = []
for p in itertools.permutations(list(range(1, n + 1))):
    X.append(p)
# print(X)
for i in range(len(X)):
    if P == X[i]:
        a = i
        break
for i in range(len(X)):
    if Q == X[i]:
        b = i
        break
print((abs(a - b)))

-P = list(map(int, input().split())) -Q = list(map(int, input().split())) +P = tuple(map(int, input().split())) +Q = tuple(map(int, input().split())) +##print(P) +# print(Q) -a = 0 -b = 0 -    for i in range(n): -        if p[i] < P[i]: -            a += 1 -            break -        elif p[i] > P[i]: -            break -        else: -            continue -    for i in range(n): -        if p[i] < Q[i]: -            b += 1 -            break -        elif p[i] > Q[i]: -            break -        else: -            continue -print((abs((a + 1) - (b + 1)))) +    X.append(p) +# print(X) +for i in range(len(X)): +    if P == X[i]: +        a = i +        break +for i in range(len(X)): +    if Q == X[i]: +        b = i +        break +print((abs(a - b)))