import java.util.*; public class Main { static long max = Long.MIN_VALUE; static long min = Long.MAX_VALUE; static int nCount; static int oCount; static int n; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] nums = new int[10]; int plus = 0; int minus = 0; n = sc.nextInt(); for (int i = 0; i < n; i++) { char c = sc.next().charAt(0); if (c == '+') { plus++; } else if (c == '-') { minus++; } else { nums[c - '0']++; nCount++; } } oCount = plus + minus; calc(0, plus, minus, nums, 0, 0, true, false); System.out.println(max + " " + min); } static void calc(int idx, int plus, int minus, int[] nums, long value1, long value2, boolean isPlus, boolean canOp) { if (idx == n) { long result; if (isPlus) { result = value1 + value2; } else { result = value1 - value2; } max = Math.max(max, result); min = Math.min(min, result); return; } if (n - idx - plus - minus > plus + minus) { for (int i = 0; i < 10; i++) { if (nums[i] == 0) { continue; } nums[i]--; calc(idx + 1, plus, minus, nums, value1, value2 * 10 + i, isPlus, true); nums[i]++; } } if (canOp) { if (plus > 0) { if (isPlus) { calc(idx + 1, plus - 1, minus, nums, value1 + value2, 0, true, false); } else { calc(idx + 1, plus - 1, minus, nums, value1 - value2, 0, true, false); } } if (minus > 0) { if (isPlus) { calc(idx + 1, plus, minus - 1, nums, value1 + value2, 0, false, false); } else { calc(idx + 1, plus, minus - 1, nums, value1 - value2, 0, false, false); } } } } }