n = int(input()) C = input().split() p = 0 m = 0 A = [] for c in C: if c == "+": p += 1 elif c == "-": m += 1 else: A.append(int(c)) A.sort() le = p + m + 1 while len(A) > le: a = A.pop() A[-1] += 10 * a tot = sum(A) ma = tot - 2 * sum(A[:m]) A = A[::-1] mi = tot - 2 * sum(A[:m]) print(ma, mi)