N = gets.to_i cn,oprs = gets.split.group_by{|x| %w(+ -).include? x}.values cn = cn.sort.reverse oprs = oprs.sort ansmax,ansmin = [0,0] slot = oprs.size + 1 max = cn[0..(-slot)].join.to_i ansmax = max cn.last(slot-1).zip(oprs) do |c,opr| ansmax = opr.to_sym.to_proc.call(ansmax,c.to_i) end if oprs.last == "-" ansmin = -max oprs.pop oprs = oprs.reverse << "+" cn.last(slot-1).zip(oprs) do |c,opr| ansmin = opr.to_sym.to_proc.call(ansmin,c.to_i) end else a = Array.new(slot){ "" } index = (0..slot-1).cycle cn.each{|c| i = index.next; a[i] = c + a[i]} ansmin = a.map(&:to_i).inject(:+) end puts [ansmax,ansmin]