#include #include #include #include int max(std::list v, int plus, int minus){ v.sort(); int ans = 0; while(v.size() != plus + minus){ ans = ans * 10 + v.back(); v.pop_back(); } while(plus){ ans += v.back(); v.pop_back(); plus--; } v.push_back(ans); for (size_t i = 0; i < minus; i++) { int num = v.back(); v.pop_back(); int num2 = v.back(); v.pop_back(); v.push_back(num - num2); v.sort(); } return v.front(); } int min(std::list v, int plus, int minus){ v.sort(); for (size_t i = 0; i < plus; i++) { int num = v.front(); v.pop_front(); int num2 = v.front(); v.pop_front(); v.push_back(num2 + num); v.sort(); } int ans = 0; while(v.size() != minus){ ans = ans * 10 + v.back(); v.pop_back(); } v.push_back(ans); v.sort(); while(v.size() != 1){ int mi = v.front();v.pop_front(); int ma = v.front();v.pop_front(); v.push_back(mi - ma); v.sort(); } return v.front(); } int main(){ int n; std::cin >> n; std::list v; int plus = 0, minus = 0; for(int i = 0; i < n; i++) { char c; std::cin >> c; if(c == '+') plus++; else if(c == '-') minus++; else v.push_back(c - '0'); } std::list v2 = v; int m = max(v, plus, minus); int mi = min(v2, plus, minus); std::cout << m << " " << mi << std::endl; return 0; }