n = gets.to_i
ary_p = gets.split.map(&:to_i)
ary_q = gets.split.map(&:to_i)

def f(n, ary)
  x = 0
  m = n
  b = (1..n).inject(1, :*)
  while i = ary.shift
    b /= m
    x += (i - 1) * b
    ary.map! { |z| z > i ? z - 1 : z }
    m -= 1
  end
  x
end

puts (f(n, ary_p) - f(n, ary_q)).abs
