import itertools N=int(input()) c=input().split() f=1;M=0;m=0 prev=tuple() for e in itertools.permutations(sorted(c),N): if e <= prev: continue prev=e S=0;s="";ncnt=0;pm=1 for n in range(0,N): if e[n].isdigit():s=s+e[n];ncnt=ncnt+1 else: if ncnt==0:break else: S+=pm*int(s) s="";ncnt=0;pm=1 if e[n] is "-":pm=-1 if ncnt==0:continue S+=pm*int(s) if f==1:M=S;m=S;f=0 else:M=max(M,S);m=min(m,S) print('%d %d'%(M,m))