#include #define pr(s) std::cout << s << std::endl int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int n; std::cin >> n; int c[10] = { 0 }; int d[10] = { 0 }; char t; int minus = 0, plus = 0; for (int i = 0; i < n; ++i) { std::cin >> t; if (t == '-') { ++minus; } else if (t == '+') { ++plus; } else { ++c[t - 48]; ++d[t - 48]; } } long long max = 0, min = 0; for (int i = 0; i < n - 2*(minus + plus); ++i) { for (int j = 9; j >= 0; --j) { if (c[j] > 0) { max = max * 10 + j; --c[j]; break; } } } for (int i = 0; i < minus; ++i) { for (int j = 0; j < 10; ++j) { if (c[j] > 0) { max -= j; --c[j]; break; } } } for (int i = 0; i < 10; ++i) { max += c[i] * i; } std::cout << max << " "; if (minus > 0) { for (int i = 0; i < n - 2*(minus + plus); ++i) { for (int j = 9; j >= 0; --j) { if (d[j] > 0) { min = min * 10 + j; --d[j]; break; } } } min *= -1; --minus; for (int i = 0; i < minus; ++i) { for (int j = 9; j >= 0; --j) { if (d[j] > 0) { min -= j; --d[j]; break; } } } for (int i = 0; i < 10; ++i) { min += d[i] * i; } } else { int sepa = (n - plus) / (plus + 1); int sepaer = (n - plus) - sepa*(plus + 1); int sum = 0; for (int i = 0; i < sepaer; ++i, sum = 0) { for (int j = 0; j < sepa + 1; ++j) { for (int k = 0; k < 10; ++k) { if (d[k] > 0) { sum = sum * 10 + k; --d[k]; break; } } } min += sum; } for (int i = 0; i < plus + 1 - sepaer; ++i, sum = 0) { for (int j = 0; j < sepa; ++j) { for (int k = 0; k < 10; ++k) { if (d[k] > 0) { sum = sum * 10 + k; --d[k]; break; } } } min += sum; } } std::cout << min << std::endl; }