n=input() c=raw_input().split() a=sorted([i for i in c if i.isdigit()]) p,m=c.count("+"),c.count("-") #print a,p,m #big b=a[p+m:][::-1] c=a[:p+m] for i in range(m): b+=["-",c.pop(0)] for i in range(p): b+=["+",c.pop()] big=eval("".join(b)) #print b #small if m>0: b=[a[0]] c=a[1:] for i in range(p): b+=["+",c.pop(0)] for i in range(m-1): b+=["-",c.pop(0)] #print b,c if len(c)>0: b+=["-"]+c[::-1] small=eval("".join(b)) else: b=[""for i in range(p+1)] for i in range(len(a)): b[i%(p+1)]+=a[i] #print b small=sum(int(i)for i in b) print big,small