using namespace std; #include #include #include #include #include #include #include typedef long long ll; ll INF = LLONG_MAX; int ma(vector a, int plus, int minus) { int ans = 0; while (minus--) { ans -= a[0]; a.erase(a.begin()); } while (plus--) { ans += a[0]; a.erase(a.begin()); } ll x = 0; reverse(a.begin(), a.end()); while (!a.empty()) { x = x * 10 + a[0]; a.erase(a.begin()); } return ans + x; } int mi(vector a, int plus, int minus) { if (minus) { plus++; minus--; int ans = 0; while (plus--) { ans += a[0]; a.erase(a.begin()); } while (minus--) { ans -= a[0]; a.erase(a.begin()); } ll x = 0; reverse(a.begin(), a.end()); while (!a.empty()) { x = x * 10 + a[0]; a.erase(a.begin()); } return ans - x; } else { reverse(a.begin(), a.end()); int n = plus + 1; vector b(n); for (int i = 0; i < a.size(); i++) b[i % n] = b[i % n] * 10 + a[i]; ll sum = 0; for (int k = 0; k < n; k++) sum += b[k]; return sum; } } int main() { int N; cin >> N; vector a; int plus = 0, minus = 0; while (N--) { string c; cin >> c; if (c == "+") plus++; else if (c == "-") minus++; else a.push_back(c[0] - '0'); } sort(a.begin(), a.end()); cout << ma(a, plus, minus) << ' ' << mi(a, plus, minus) << endl; }