n = gets.to_s.to_i a = gets.to_s.split.map(&:to_i).sort b = gets.to_s.split.map(&:to_i) count = 0 current_max_score = 0 a.permutation do |array| i = 0 score = 0 while i < n diff = array[i] - b[i] score += diff if diff > 0 i += 1 end if score > current_max_score count = 1 current_max_score = score elsif score == current_max_score count += 1 end end puts count