N = int(raw_input()) c = raw_input().split() p = m = 0 inc = 0 while inc < N - p - m: if c[inc].isdigit(): inc += 1 elif c.pop(inc) == "+": p += 1 else: m += 1 op = m + p N -= op c.sort(reverse = True) max_v = min_v = 0 if m == 0: min_v = sum(int(c[i])*10**(i/(op+1)) for i in xrange(N)) max_v = int("".join(c[:N-op])) + sum(map(int,c[N-op:])) else: min_v = int(c[-1])-int("".join(c[:N+min(1-op,-1)]))-sum(map(int,c[N-op+1:N+min(m-op,-1)]))+sum(map(int,c[N-op+m:N-1])) max_v = int("".join(c[:N-op]))+sum(map(int,c[N-op:N-op+p]))-sum(map(int,c[N-op+p:])) print max_v, min_v