n=gets.to_i plus=0 minus=0 fig=[] c=gets.split.each{|c| if c==?+ plus+=1 elsif c==?- minus+=1 else fig << c.to_i end } max=min=0 max_fig=fig.sort.reverse minus.times{max-=max_fig.pop} plus.times{max+=max_fig.pop} max+=max_fig.join.to_i if minus==0 min=max else min_fig=fig.sort min=min_fig.shift plus.times{min+=min_fig.shift} (minus-1).times{min-=min_fig.shift} min-=min_fig.reverse.join.to_i end puts [max,min]*" "