#include #define whole(xs) xs.begin(),xs.end() using namespace std; namespace { typedef double real; typedef long long ll; template ostream& operator<<(ostream& os, const vector& vs) { if (vs.empty()) return os << "[]"; os << "[" << vs[0]; for (int i = 1; i < vs.size(); i++) os << " " << vs[i]; return os << "]"; } template istream& operator>>(istream& is, vector& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } ll to_i(string s) { istringstream is(s); ll n; is >> n; return n; } int N; vector C; void input() { cin >> N; C.resize(N); cin >> C; } vector X; void solve() { ll P = 0; ll M = 0; for (int i = 0; i < N; i++) { if (C[i] == '+') { P++; } else if (C[i] == '-') { M++; } else { X.push_back(ll(C[i] - '0')); } } sort(whole(X)); ll Max = 0; for (int i = 0; i < M; i++) { Max -= X[i]; } for (int i = 0; i < P; i++) { Max += X[M + i]; } string s; for (int i = P + M; i < X.size(); i++) { s.push_back(char(X[i]+'0')); } reverse(whole(s)); Max += to_i(s); ll Min = 0; if (M > 0) { for (int i = 0; i < P + 1; i++) { Min += X[i]; } for (int i = P + 1; i < P + 1 + M - 1; i++) { Min -= X[i]; } string s; for (int i = P + M; i < X.size(); i++) { s.push_back(char(X[i] + '0')); } reverse(whole(s)); Min -= to_i(s); } else { priority_queue, greater> Q; for (int i = 0; i < X.size(); i++) Q.push(X[i]); vector ss(P + 1, ""); int n = 0; while (not Q.empty()) { ll c = Q.top(); Q.pop(); ss[n].push_back(char(c+'0')); n = (n + 1) % (P + 1); } for (int i = 0; i < P + 1; i++) { Min += to_i(ss[i]); } } cout << Max << " " << Min << endl; } } int main() { input(); solve(); return 0; }