n, a, b = 3.times.map { gets } n = n.to_i a = a.split(' ').map(&:to_i) b = b.split(' ').map(&:to_i) count = 0 current_max_score = 0 GC.disable a.sort.permutation.each 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