#include using namespace std; #define rep(i,a,b) for(int i=a;i vc; typedef long long ll; int main() { int N; cin >> N; int plus = 0, minus = 0; vc nums; rep(i, 0, N) { char c; cin >> c; if (c == '+') plus++; else if (c == '-') minus++; else nums.push_back(c); } sort(nums.begin(), nums.end(), greater()); ll ans_max = 0, ans_min = 0, d; if (0 < minus) { rep(i, 0, minus) ans_max -= nums[nums.size() - 1 - i] - '0'; rep(i, 0, plus) ans_max += nums[nums.size() - 1 - minus - i] - '0'; d = 0; rep(i, 0, nums.size() - minus - plus) d = d * 10 + nums[i] - '0'; ans_max += d; rep(i, 0, plus + 1) ans_min += nums[nums.size() - 1 - i] - '0'; rep(i, 0, minus - 1) ans_min -= nums[nums.size() - 1 - plus - i] - '0'; d = 0; rep(i, 0, nums.size() - minus - plus) d = d * 10 + nums[i] - '0'; ans_min -= d; } else { rep(i, 0, minus) ans_max -= nums[nums.size() - 1 - i] - '0'; rep(i, 0, plus) ans_max += nums[nums.size() - 1 - minus - i] - '0'; d = 0; rep(i, 0, nums.size() - minus - plus) d = d * 10 + nums[i] - '0'; ans_max += d; vector list(plus + 1, vc()); sort(nums.begin(), nums.end()); rep(i, 0, nums.size()) list[i % (plus + 1)].push_back(nums[i]); rep(i, 0, plus + 1) { d = 0; rep(j, 0, list[i].size()) d = 10 * d + list[i][j] - '0'; ans_min += d; } } cout << ans_max << " " << ans_min << endl; }