n, p, q = gets.to_i, gets.split.map(&:to_i), gets.split.map(&:to_i)
fact = 1.upto(n).inject(&:*)
p, q = p.map{|i| i-1}, q.map{|i| i-1}
ap, aq = 1, 1
n.times do |i|
  fact /= n-i
  ap += fact * p[i]
  aq += fact * q[i]
  (i + 1).upto(n-1) do |i2|
    p[i2] -= 1 if p[i] < p[i2]
    q[i2] -= 1 if q[i] < q[i2]
  end
end
puts (ap - aq).abs