from itertools import permutations n=int(input()) C=input().split() X=list(permutations(range(n))) MAX=-1<<60 MIN=1<<60 for x in X: S="" for y in x: S+=C[y] flag=1 for i in range(1,len(S)): if S[0] in "+-" or S[-1] in "+-" or (S[i] in "+-" and S[i-1] in "+-"): break else: MAX=max(MAX,eval(S)) MIN=min(MIN,eval(S)) print(MAX,MIN)