import math N = input() c = map(str, raw_input().split()) operators, nums = [], [] for i in xrange(N): if c[i] == '+' or c[i] == '-': operators.append(c[i]) else: nums.append(int(c[i])) nums.sort() nums = map(str, nums) min_sep = [] for i in xrange(len(operators)): min_sep.append(int(nums[i])) nums.reverse() maximum = int("".join(nums[:len(nums)-len(operators)])) nums.reverse() plus = operators.count('+') minus = operators.count('-') M = maximum min_sep.reverse() for i in xrange(plus): M += min_sep[i] for i in xrange(plus, plus+minus): M -= min_sep[i] print M min_sep.reverse() m = 0 if minus == 0: sep = len(operators)+1 r = len(nums)%sep digit = int(math.ceil(1.0*len(nums)/sep)) if r != 0: for i in xrange(r): m += int(nums[i]) m *= 10**(digit-1) digit -= 1 j = 0 while digit > 0: for i in xrange(sep): m += int(nums[i+j*sep+r]) m *= 10**(digit-1) digit -= 1 j += 1 else: m += min_sep[0] for i in xrange(1, plus+1): m += min_sep[i] for i in xrange(plus, plus+minus-1): m -= min_sep[i] m -= maximum print M, m