#include using namespace std; // max long long f(vector a, int x, int y) { sort(a.begin(), a.end()); int pos = 0; long long ret = 0; for (int i = 0; i < y; i++) ret -= a[pos++]; for (int i = 0; i < x; i++) ret += a[pos++]; long long base = 1; while (pos < a.size()) { base *= 10; ret += base * a[pos++]; } return ret; } long long p10(int x) { long long ret = 1; for (int i = 0; i < x; i++) ret *= 10; return ret; } // min long long g(vector a, int x, int y) { sort(a.begin(), a.end()); int pos = 0; long long ret = 0; if (y == 0) { int n = a.size(); for (int i = 0; i < a.size(); i++) { ret += a[n-1-i] * p10(i / x); } return ret; } for (int i = 0; i < x; i++) ret += a[pos++]; for (int i = 0; i < y; i++) ret -= a[pos++]; long long base = 1; while (pos < a.size()) { base *= 10; ret -= base * a[pos++]; } return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int x = 1, y = 0; vector a; for (int i = 0; i < n; i++) { char c; cin >> c; if (isdigit(c)) a.push_back(c - '0'); else if (c == '+') ++x; else ++y; } cout << f(a, x, y) << " " << g(a, x, y) << endl; return 0; }