n, a, b = 3.times.map { gets } n = n.to_i a = a.split(' ').map(&:to_i) b = b.split(' ').map(&:to_i) scores = [] a.permutation.each do |array| scores << n.times.sum do |i| diff = array[i] - b[i] diff >= 0 ? diff : 0 end end max_score = scores.max puts(scores.count {|s| s == max_score})