N = gets.chomp.to_i
str = gets.split
a = Array.new(N)
for i in 0...N do
    a[i] = str[i].to_i
end
str = gets.split
b = Array.new(N)
for i in 0...N do
    b[i] = str[i].to_i
end
c = Array.new(N,1)
for i in 1...N do
    c[N-1-i] = c[N-i]*i
end
d = Array.new(0)
for i in 1..N do
    d.push(i)
end
e = Array.new(0)
for i in 1..N do
    e.push(i)
end

f = 1
i = 0
while d.size >= 2
    x = a[i]
    j = 0
    while x != d[j]
       j += 1 
    end
    f += c[i]*j
    d.delete_at(j)
    i += 1
end
g = 1
i = 0
while e.size >= 2
    x = b[i]
    j = 0
    while x != e[j]
       j += 1 
    end
    g += c[i]*j
    e.delete_at(j)
    i += 1
end

answer = (f-g).abs
puts answer