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='')])) print(max_ans, min_ans) if __name__ == '__main__': main()