class Yukicoder def initialize n = gets.to_i c = gets.chomp.split nums = c.select{|i| i =~ /\d/}.sort.reverse operation = c.select{|i| i =~ /(\+|\-)/}.sort divide_num = operation.size + 1 list = [nums[0..-divide_num].join, nums[-divide_num+1..-1]].flatten puts [eval(list.zip(operation).join), eval(list.reverse.zip(operation).join)].join(' ') end end Yukicoder.new