n = gets.to_i a = gets.split b = gets.split ap = a.permutation(n).to_a ab = ap.zip([b] * ap.length) p ab aaa = ab.map { |i| (i[0] > i[1]) ? (i[0] - i[1]) : 0 } p aaa