#include #include #include #include #include #include using namespace std; int main() { int n; char c; cin >> n; vector nums; int plus = 0, minus = 0; for (int i = 0; i < n; i++) { cin >> c; if (c == '+') { plus++; } else if (c == '-') { minus++; } else { nums.push_back(c - '0'); } } int plus2 = plus; int minus2 = minus; // for max long long ans1 = 0; sort(nums.begin(), nums.end(), greater()); int idx = 0; while (idx < nums.size() - (plus + minus)) { ans1 *= 10; ans1 += nums[idx]; idx++; } while (plus > 0) { ans1 += nums[idx]; idx++; plus--; } while (minus > 0) { ans1 -= nums[idx]; idx++; minus--; } // for minus plus = plus2; minus = minus2; idx = 0; long long ans2 = 0; if (minus > 0) { sort(nums.begin(), nums.end(), greater()); while (idx < nums.size() - (plus + minus)) { ans2 *= 10; ans2 += nums[idx]; idx++; } ans2 *= -1; minus--; plus++; } else { sort(nums.begin(), nums.end()); while (idx < nums.size() - (plus + minus)) { ans2 *= 10; ans2 += nums[idx]; idx++; } } while (minus > 0) { ans2 -= nums[idx]; idx++; minus--; } while (plus > 0) { ans2 += nums[idx]; idx++; plus--; } cout << ans1 << " " << ans2 << endl; return 0; }