#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% N = int(readline()) nums = [] plus = 1 minus = 0 for x in readline().decode().split(): if x == '+': plus += 1 elif x == '-': minus += 1 else: nums.append(int(x)) nums.sort() # %% def get_largest(nums, plus, minus): ret = -sum(nums[:minus]) ret += sum(nums[minus:minus + plus]) for i, x in enumerate(nums[minus + plus:], 1): ret += x * 10 ** i return ret # %% def get_smallest(nums, plus, minus): return -get_largest(nums, minus, plus) # %% print(get_largest(nums, plus, minus), get_smallest(nums, plus, minus))