import itertools as it

s=list(range(1,int(eval(input()))+1))

A=list(it.permutations(s))

P,Q=[tuple(map(int,input().split())) for i in range(2)]

print((abs(A.index(P)-A.index(Q))))
import math

n=int(eval(input()))

A,B=[list(range(1,n+1)) for i in range(2)]

P,Q=[list(map(int,input().split())) for i in range(2)]

p=0

for i in range(n-1):

    p+=(A.index(P[i]))*math.factorial(n-i-1)

    A.remove(P[i])

q=0

for i in range(n-1):

    q+=(B.index(Q[i]))*math.factorial(n-i-1)

    B.remove(Q[i])

print((abs(p-q)))
import itertools as it

s = list(range(1, int(eval(input())) + 1))
A = list(it.permutations(s))
P, Q = [tuple(map(int, input().split())) for i in range(2)]
print((abs(A.index(P) - A.index(Q))))

import math

n = int(eval(input()))
A, B = [list(range(1, n + 1)) for i in range(2)]
P, Q = [list(map(int, input().split())) for i in range(2)]
p = 0
for i in range(n - 1):
    p += (A.index(P[i])) * math.factorial(n - i - 1)
    A.remove(P[i])
q = 0
for i in range(n - 1):
    q += (B.index(Q[i])) * math.factorial(n - i - 1)
    B.remove(Q[i])
print((abs(p - q)))

-import itertools as it +import math -s = list(range(1, int(eval(input())) + 1)) -A = list(it.permutations(s)) -P, Q = [tuple(map(int, input().split())) for i in range(2)] -print((abs(A.index(P) - A.index(Q)))) +n = int(eval(input())) +A, B = [list(range(1, n + 1)) for i in range(2)] +P, Q = [list(map(int, input().split())) for i in range(2)] +p = 0 +for i in range(n - 1): +    p += (A.index(P[i])) * math.factorial(n - i - 1) +    A.remove(P[i]) +q = 0 +for i in range(n - 1): +    q += (B.index(Q[i])) * math.factorial(n - i - 1) +    B.remove(Q[i]) +print((abs(p - q)))