io = STDIN io.gets aa = io.gets.split(' ').map(&:to_i) ba = io.gets.split(' ').map(&:to_i) max = 0 aa.sort.reverse.zip(ba.sort) do |a, b| point = a - b max += point.positive? ? point : 0 end 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 count += 1 if sum == max end puts count