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] if nm == 0: mi = 0 for i in range(np): mi += int(I[-i - 1]) mi += int(''.join(I[:-np])) print(ma, mi) if __name__ == '__main__': solve()