import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static long max = Long.MIN_VALUE; static long min = Long.MAX_VALUE; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] counts = new int[12]; int oCount = 0; int nCount = 0; for (int i = 0; i < n; i++) { char c = sc.next().charAt(0); if (c == '+') { counts[10]++; oCount++; } else if (c == '-') { counts[11]++; oCount++; } else { counts[c - '0']++; nCount++; } } check(0, 0, oCount, nCount, counts, true, true); System.out.println(max + " " + min); } static void check(long total, long current, int oCount, int nCount, int[] counts, boolean isPlus, boolean needNum) { if (oCount == 0 && nCount == 0) { if (isPlus) { total += current; } else { total -= current; } max = Math.max(total, max); min = Math.min(total, min); return; } if (oCount < nCount) { for (int i = 0; i < 10; i++) { if (counts[i] == 0) { continue; } counts[i]--; check(total, current * 10 + i, oCount, nCount - 1, counts, isPlus, false); counts[i]++; } } if (needNum) { return; } if (oCount > 0) { long next = total; if (isPlus) { next += current; } else { next -= current; } if (counts[10] > 0) { counts[10]--; check(next, 0, oCount - 1, nCount, counts, true, true); counts[10]++; } if (counts[11] > 0) { counts[11]--; check(next, 0, oCount - 1, nCount, counts, false, true); counts[11]++; } } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }