io = STDIN io.gets aa = io.gets.split(' ').map(&:to_i) ba = io.gets.split(' ').map(&:to_i) max_point = 0 max_point_count = 0 aa.permutation do |a_seq| sum = 0 a_seq.zip(ba) do |a, b| point = a - b sum += point if point.positive? end if max_point < sum max_point = sum max_point_count = 1 elsif max_point == sum max_point_count += 1 end end puts max_point_count