N = int(input()) c = list(map(str, input().split())) pp, mm = 0, 0 n = [] for i in range(N): if c[i] == '+': pp += 1 elif c[i] == '-': mm += 1 else: n.append(int(c[i])) ma = 0 p, m = pp, mm n.sort(reverse=True) nn = len(n)-(p+m) for i in range(len(n)): if i0: ma += n[i] p-=1 else: ma -= n[i] p, m = pp, mm if m>0: n.sort() nn = len(n)-(p+m) mi = n[0] sm = '' for i in range(1,len(n)): if p+m-1>0: if p>0: mi += n[i] p-=1 else: mi -= n[i] else: sm += str(n[i]) mi -= int(sm[::-1]) else: mi = 0 n.sort(reverse=(True)) num = ['']*(p+1) idx = 0 for i in range(len(n)): num[idx] += str(n[i]) idx += 1 idx %= len(num) for j in range(len(num)): mi += int(num[j][::-1]) print(ma, mi)