def solve(): N = int(input()) C = input().split() np = nm = 0 I = [] for c in C: if c == '+': np += 1 elif c == '-': nm += 1 else: I += c I.sort() J = [] for i in range(np + nm): J.append(int(I[i])) J.append(int(''.join(I[np + nm:][::-1]))) K = J[::-1] mi = ma = 0 for i in range(np + 1): mi += J[i] ma += K[i] for i in range(np + 1, np + nm + 1): mi -= J[i] ma -= K[i] print(ma, mi) if __name__ == '__main__': solve()