from itertools import zip_longest def main(): n = input() l = input().split() num = sorted([int(i) for i in l if i.isnumeric()]) ope = sorted([i for i in l if not i.isnumeric()]) nums = [x for x in num[:len(ope)]] nums.append(int("".join(map(str, sorted(num[len(ope):], reverse=True))))) max_ans = eval("".join([str(a) + b for a, b in zip_longest(sorted(nums, reverse=True), ope, fillvalue='')])) min_ans = eval("".join([str(a) + b for a, b in zip_longest(sorted(nums), ope, fillvalue='')])) if '-' not in ope: l = ["" for i in range(len(ope) + 1)] for i, x in enumerate(num): l[i % len(l)] += str(x) min_ans = sum(map(int, l)) print(max_ans, min_ans) if __name__ == '__main__': main()