#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) #define minimize(a, x) a = std::min(a, x) #define maximize(a, x) a = std::max(a, x) using ll = long long; int const inf = 1<<29; ll concat(vector::const_iterator start, vector::const_iterator end) { ll res = 0; for(auto iter = start; iter!=end; iter++) { res *= 10; res += *iter; } return res; } int main() { int N; cin >> N; vector digits; int plus = 0, minus = 0; rep(i, N) { char c; cin >> c; if(isdigit(c)) { digits.push_back(c-'0'); } else { if(c == '+') { plus ++; } else { minus ++; } } } auto D = digits; sort(all(digits)); sort(D.rbegin(), D.rend()); int mx = -1, mn = inf; if(minus == 0) { mx = accumulate(digits.begin(), digits.begin() + plus + 1, 0); mx += concat(D.begin(), D.begin() + (int)D.size() - plus - 1); mn = accumulate(all(digits), 0); } else if(plus == 0) { mx = concat(D.begin(), D.begin() + (int)D.size() - minus); mx -= accumulate(digits.begin(), digits.begin() + minus, 0); mn = digits[0]; if(minus > 1) { int consDigits = minus - 1; mn -= accumulate(digits.begin() + 1, digits.begin() + 1 + consDigits, 0); } mn -= concat(D.begin(), D.begin() + ((int)D.size() - (1 + (minus - 1)))); } else { mx = digits[minus] - accumulate(digits.begin(), digits.begin() + minus, 0); if(plus > 1) { mx += accumulate(digits.begin() + minus + 1, digits.begin() + minus + (plus - 1) + 1, 0); } mx += concat(D.begin(), D.begin() + (int)D.size() - (minus + (plus - 1) + 1)); mn = accumulate(digits.begin(), digits.begin() + plus + 1, 0); if(minus > 1) { int consDigits = minus - 1; mn -= accumulate(digits.begin() + plus + 1, digits.begin() + plus + 1 + consDigits, 0); } mn -= concat(D.begin(), D.begin() + (int)D.size() - (plus + 1 + minus - 1)); } cout << mx << " " << mn << endl; return 0; }