#!/usr/bin/python # -*- coding: utf-8 -*- N = input() inputs = raw_input().split() numbers = [] symbols = [] for n in inputs: if n.isdigit(): numbers.append(n) else: symbols.append(n) numbers = map(int, numbers) s_numbers = sorted(numbers, reverse=True) # [5,4,3,2,1] smalls = [] for loop in xrange(len(symbols)): smalls.append(s_numbers.pop()) #small numbers str_numbers = map(str, s_numbers) big = ''.join(str_numbers) big = int(big) #biggest number possible n_plus = symbols.count('+') n_minus = symbols.count('-') BIG = big big_smalls = smalls for n in xrange(n_plus): BIG += big_smalls.pop() for n in xrange(n_minus): BIG -= big_smalls.pop() if n_minus > 0: SMALL = 0 sma_smalls = smalls sma_smalls.append(BIG) for n in xrange(n_minus): SMALL -= sma_smalls.pop() for n in xrange(n_plus): SMALL += sma_smalls.pop() elif n_minus == 0: #ここから解説見た smalls = [[] for loop in xrange(n_plus+1)] for i in xrange(len(numbers)): smalls[i%len(smalls)].append(numbers[i]) smalls = map(sorted, smalls) SMALL = 0 for lst in smalls: lst = [str(n) for n in lst] n = int(''.join(lst)) SMALL += n print BIG, SMALL