ones, fives = gets.chomp.split.map(&:to_i) list, sum = Array.new, 0 1.upto(ones){ list << sum += 1 } sum = 0 1.upto(fives){list << sum += 5 } sum = 0 1.upto(ones){ list << sum += 1 list << sum += 5 if ones == fives } sum = 0 1.upto(fives){ list << sum += 5 list << sum += 1 if ones == fives } sum = 0 1.upto(ones){ list << sum += 1 if ones == fives list << sum += 5 sum -= 5 end } sum = 0 1.upto(fives){ list << sum += 5 if ones == fives list << sum += 1 sum -= 1 end } puts list.uniq.sort