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 void dfs(long total, long sign, long current, boolean first, final int n_count, int[] numbers, final int o_count, int[] ops){ if(n_count == 0 && o_count == 0){ total += current * sign; min = Math.min(min, total); max = Math.max(max, total); return; } if(first || n_count > o_count){ for(int i = 0; i < 10; i++){ if(numbers[i] > 0){ numbers[i]--; dfs(total, sign, current * 10 + i, false, n_count - 1, numbers, o_count, ops); numbers[i]++; } } } if(!first){ if(ops[0] > 0){ ops[0]--; dfs(total + current * sign, 1, 0, true, n_count, numbers, o_count - 1, ops); ops[0]++; } if(ops[1] > 0){ ops[1]--; dfs(total + current * sign, -1, 0, true, n_count, numbers, o_count - 1, ops); ops[1]++; } } } 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++; } } dfs(0, 1, 0, true, n_count, numbers, o_count, ops); System.out.println(max + " " + min); } }