using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; class Meguru { public Meguru() { } public static int Main() { new Meguru().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int N = cin.nextInt(); List num = new List(); int plus = 0; int minus = 0; for (int i = 0; i < N; i++) { char c = cin.next()[0]; if (char.IsNumber(c)) { num.Add(c - '0'); } else if (c == '+') plus++; else minus++; } num.Sort(); List num2 = new List(num); long ansmax = 0; for (int i = 0; i < minus; i++) { ansmax -= num2[0]; num2.RemoveAt(0); } for (int i = 0; i < plus; i++) { ansmax += num2[0]; num2.RemoveAt(0); } long add = 0; for (int i = 0; i < num2.Count; i++) { add *= 10; add += num2[num2.Count - 1 - i]; } ansmax += add; long ansmin = 0; if (minus == 0) { num2 = new List(num); num2.Reverse(); long[] pow10 = new long[16]; pow10[0] = 1; for (int i = 1; i < pow10.Length; i++) { pow10[i] = pow10[i - 1] * 10; } for (int i = 0; i < num2.Count; i++) { ansmin += num2[i] * pow10[i / (plus + 1)]; } } else { num2 = new List(num); for (int i = 0; i < plus + 1; i++) { ansmin += num2[0]; num2.RemoveAt(0); } for (int i = 0; i < minus - 1; i++) { ansmin -= num2[0]; num2.RemoveAt(0); } add = 0; for (int i = 0; i < num2.Count; i++) { add *= 10; add += num2[num2.Count - 1 - i]; } ansmin -= add; } Console.WriteLine(ansmax + " " + ansmin); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }