import java.util.Scanner; public class Main_yukicoder297 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char[] c = new char[n]; int p = 0; int m = 0; int[] d = new int[10]; for (int i = 0; i < n; i++) { c[i] = sc.next().charAt(0); if (c[i] == '+') { p++; } else if (c[i] == '-') { m++; } else { d[c[i] - '0']++; } } long[] num = new long[p + m + 1]; for (int i = 0; i < p + m + 1 - 1; i++) { for (int j = 0; j < 10; j++) { if (d[j] > 0) { num[i] = j; d[j]--; break; } } } long tmp = 0; for (int i = 9; i >= 0; i--) { while (d[i] > 0) { tmp = tmp * 10 + i; d[i]--; } } num[p + m + 1 - 1] = tmp; long max = 0; int tmpp = p; int tmpm = m; for (int i = p + m; i >= 0; i--) { if (i == p + m) { max += num[i]; } else if (tmpp > 0) { max += num[i]; tmpp--; } else if (tmpm > 0) { max -= num[i]; tmpm--; } } long min = 0; tmpp = p; tmpm = m; for (int i = 0; i < p + m + 1; i++) { if (i == 0) { min += num[i]; } else if (tmpp > 0) { min += num[i]; tmpp--; } else if (tmpm > 0) { min -= num[i]; tmpm--; } } if (m == 0) { for (int i = 0; i < n; i++) { if (c[i] == '+') { } else if (c[i] == '-') { } else { d[c[i] - '0']++; } } num = new long[p + m + 1]; int i = p + m; for (int j = 0; j < 10; j++) { while (d[j] > 0) { num[i] = num[i] * 10 + j; d[j]--; i--; if (i < 0) { i = p + m; } } } max = 0; for (int j = 0; j < p + m + 1; j++) { max += num[j]; } } System.out.printf("%d %d\n", max, min); sc.close(); } }