import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static long min = Long.MAX_VALUE; public static long max = Long.MIN_VALUE; public static long estimate_max(int n_count, int[] numbers, int o_count, int[] ops) { long ret = 0; for(int i = 9, rest = n_count - o_count, plus = ops[0]; i >= 0; i--){ final int times = Math.min(numbers[i], rest); rest -= times; for(int j = 0; j < times; j++){ ret *= 10; ret += i; } for(int j = 0; j < (numbers[i] - times); j++){ if(plus > 0){ plus--; ret += i; }else{ ret -= i; } } } return ret; } public static long estimate_min(int n_count, int[] numbers, int o_count, int[] ops) { long ret = 0; if(ops[1] > 0){ int min_value = -1; for(int i = 0; i < 10; i++){ if(numbers[i] > 0){ min_value = i; break; } } ops[1]--; numbers[min_value]--; o_count--; n_count--; ret = min_value; long minus_value = 0; for(int i = 9, rest = n_count - o_count, minus = ops[1]; i >= 0; i--){ final int times = Math.min(numbers[i], rest); rest -= times; for(int j = 0; j < times; j++){ minus_value *= 10; minus_value += i; } for(int j = 0; j < (numbers[i] - times); j++){ if(minus > 0){ minus--; ret -= i; }else{ ret += i; } } } ret -= minus_value; ops[1]++; numbers[min_value]++; o_count++; n_count++; }else{ for(int i = 0, rest = n_count - o_count; i < 10; i++){ final int times = Math.min(numbers[i], rest); rest -= times; for(int j = 0; j < times; j++){ ret *= 10; ret += i; } for(int j = 0; j < (numbers[i] - times); j++){ ret += i; } } } return ret; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); char[] inputs = new char[N]; for (int i = 0; i < N; i++) { inputs[i] = sc.next().charAt(0); } int n_count = 0, o_count = 0; int[] ops = new int[2]; int[] numbers = new int[10]; for (int i = 0; i < inputs.length; i++) { switch (inputs[i]) { case '+': ops[0]++; o_count++; break; case '-': ops[1]++; o_count++; break; default: numbers[Character.getNumericValue(inputs[i])]++; n_count++; } } System.out.println(estimate_max(n_count, numbers, o_count, ops) + " " + estimate_min(n_count, numbers, o_count, ops)); } }