from Queue import * # Queue, LifoQueue, PriorityQueue from bisect import * #bisect, insort from collections import * #deque, Counter,OrderedDict,defaultdict #set([]) import math import copy import itertools import string import sys myread = lambda : map(int,raw_input().split()) def calc(nums, plus, minus): op = plus + minus s = "" for i in xrange(len(nums)-op): s += nums[i] for i in xrange(plus): s += '+' s += nums[len(nums) - op + i] for i in xrange(minus): s += '-' s += nums[len(nums) - minus + i] #print s return eval(s) def calc2(nums, plus, minus): s = "" if minus > 0: op = plus + minus for i in xrange(plus): s += nums[i] s += '+' for i in xrange(minus): s += nums[plus + i] s += '-' for i in xrange(len(nums)-op): s += nums[-i-1] else: numsx = ["" for _ in xrange(plus+1)] for i in xrange(len(nums)): c = i % (plus + 1) numsx[c] += nums[i] for i in xrange(plus+1): if i != 0: s += "+" s += numsx[i] #print s return eval(s) def solver(): N = int(raw_input()) plus,minus = 0,0 nums = [] S = raw_input().split() for i in xrange(N): if S[i] == '+': plus += 1 elif S[i] == '-': minus += 1 else: nums.append(S[i]) nums.sort() minv = calc2(nums,plus,minus) nums.reverse() maxv = calc(nums,plus,minus) print maxv,minv if __name__ == "__main__": solver()