import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Main297 { public static void main(String[] args) { new Main297(); } char[] c; public Main297() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); c = new char[n]; for (int i = 0; i < n; i++) c[i] = sc.next().charAt(0); solve(); } ArrayList l = new ArrayList(); int plus = 0; int minus = 0; private void solve() { for (char ch : c) { if (ch == '+') plus++; else if (ch == '-') minus++; else l.add((long) (ch - '0')); } Collections.sort(l); long maxNum = 0; for (int i = l.size() - 1; plus + minus <= i; i--) { maxNum = maxNum * 10 + l.get(i); } // System.out.println(maxNum); long t = 0; for (int i = plus + minus - 1; 0 <= i; i--) { long sign = minus - 1 < i ? 1 : -1; t += l.get(i) * sign; } long max = maxNum + t; long min = Long.MAX_VALUE; if (minus > 0) { min = -maxNum; minus--; plus++; for (int i = plus + minus - 1; 0 <= i; i--) { long sign = plus - 1 < i ? -1 : 1; min += l.get(i) * sign; } } else { long d = 1; min = 0; for (int i = l.size() - 1; 0 <= i; i -= plus + 1) { for (int j = 0; j <= plus; j++) { if (i - j >= 0) { min += l.get(i - j) * d; } } d *= 10; } } System.out.println(max + " " + min); } }