#include using namespace std; #define FOR(i, n) for(int i = 0; i < (n); i++) #define FORR(x, arr) for(auto& x:arr) #define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define MEM(a, x) memset(a, x, sizeof(a)) #define ALL(a) a.begin(), a.end() #define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) typedef long long ll; typedef pair P; int n, a[15]; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin >> n; vector c(n); int plus = 0, minus = 0; FOR(i, n) { cin >> c[i]; if (c[i]=='+') plus++; else if (c[i]=='-') minus++; else a[c[i]-'0']++; } int cnt = plus + minus; sort(c.rbegin(), c.rend()); string s = ""; FOR(i, n-2*cnt) s += string(1, c[i]); vector v(cnt+1, stoll(s)); for (int i = 1; i <= cnt; i++) { v[i] = c[n-2*cnt+i-1]-'0'; } ll ma = v[0]; FOR(i, plus) ma += v[i+1]; FOR(i, minus) ma -= v[plus+i+1]; ll mi = v.back(); FOR(i, minus) mi -= v[i]; FOR(i, plus) mi += v[minus+i]; cout << ma << " " << mi << endl; return 0; }