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 a.permutation.each do |array| score = 0 n.times do |i| diff = array[i] - b[i] score << diff if diff >= 0 end if score > current_max_score count = 1 current_max_score = score elsif score == current_max_score count += 1 end end puts count