=begin
N
P1 P2 ... Pn
Q1 Q2 ... Qn
=end

require "set"

n = gets.chomp.to_i
ps = gets.chomp.split(" ").map(&:to_i)
qs = gets.chomp.split(" ").map(&:to_i)

candidates = n.times.map {|i| i + 1}.to_set

def order_num(candidates, targets, smaller)
  if targets.count == 0
    return 1
  end

  result = nil

  if smaller
    prod = 1
    (1..(candidates.count)).each do |i|
      prod = prod * i
    end

    result = prod
  else
    target = targets.first

    o1 = order_num(candidates.dup.delete(target), targets[1..-1], false)
    
    o2 = 0
    candidates.select {|c| c < target}.each do |c|
      o2 += order_num(candidates.dup.delete(c), targets[1..-1], true)
    end

    result = o1 + o2
  end

  # p [candidates, targets, smaller, result]
  result
end

a = order_num(candidates.dup, ps, false)
b = order_num(candidates.dup, qs, false)

# p a
# p b

p((a-b).abs)
