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)) #small b=[a[0]] c=a[1:] for i in range(p): b+=["+",c.pop(0)] for i in range(m): b+=["-",c.pop()] b+=c[::-1] small=eval("".join(b)) print big,small