# -*- coding: utf-8 -*- N = int(raw_input()) nums = [] opes = [] for l in raw_input().split(): if l.isdigit(): nums.append(int(l)) elif l in ["+", "-"]: opes.append(l) else: raise Exception() nums.sort(reverse=True) # + -> - にならべる opes.sort() def bestChoiceValue(nums, opes): N = len(nums) return int("".join(map(str, nums[:N - len(opes)]))) def maxValue(nums, opes): N = len(nums) total = bestChoiceValue(nums, opes) k = len(nums) - len(opes) for i in xrange(len(opes)): if opes[i] == "+": total += nums[k + i] else: total -= nums[k + i] return total def minValue(nums, opes): # -が1文字でもある場合 if "-" in opes: # 並び替えて- -> + にする opes.reverse() total = -bestChoiceValue(nums, opes) k = len(nums) - len(opes) # 1つのマイナスは上で使用 for i in xrange(1, len(opes)): j = k + i - 1 if opes[i] == "+": total += nums[j] else: total -= nums[j] # 最小値は先頭に持ってくるためプラスにする total += nums[len(nums) - 1] return total else: # -がない場合 i = 0 digit = 1 total = 0 # 最小値を作るために大きい物から順に小さい桁に入れていく。 while i < len(nums): j = 0 while j < len(opes) + 1 and i < len(nums): total += nums[i] * digit i += 1 j += 1 # 次の桁へ digit *= 10 return total mx = maxValue(nums, opes) mn = minValue(nums, opes) print mx, mn