def factorial (num)
  return 0 if num < 1
  (1..num).inject(&:*)
end

N = gets.strip.to_i
P = gets.strip.split(' ').map(&:to_i)
Q = gets.strip.split(' ').map(&:to_i)
p = 0
q = 0
overp = 0
overq = 0
N.times do |n|
  overp += 1 if n > 0 && P[n] > P[n-1]
  overq += 1 if n > 0 && Q[n] > Q[n-1]
  p1 = (P[n] - overp - n) * factorial(N - n - 1)
  q1 = (Q[n] - overq - n) * factorial(N - n - 1)
  p += p1
  q += q1
end
puts (p - q).abs