from itertools import*;(n,),a,b=eval('tuple(map(int,input().split())),'*3);i=list(permutations(list(range(1,n+1)))).index;print((abs(i(a)-i(b))))
from itertools import*

n,a,b=eval('eval(input().replace(" ",",")),'*3)

i=list(permutations(list(range(1,n+1)))).index

print((abs(i(a)-i(b))))
from itertools import *

(n,), a, b = eval("tuple(map(int,input().split()))," * 3)
i = list(permutations(list(range(1, n + 1)))).index
print((abs(i(a) - i(b))))

from itertools import *

n, a, b = eval('eval(input().replace(" ",",")),' * 3)
i = list(permutations(list(range(1, n + 1)))).index
print((abs(i(a) - i(b))))

-(n,), a, b = eval("tuple(map(int,input().split()))," * 3) +n, a, b = eval('eval(input().replace(" ",",")),' * 3)