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 { int ans = 0; reverse(a.begin(), a.end()); while (plus--) { ans += a[0]; a.erase(a.begin()); } ll x = 0; while (!a.empty()) { x = x * 10 + a[a.size() - 1]; a.erase(a.begin()); } return ans + x; } } 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; }