#include #include #include #include int max(std::list v, int plus, int minus){ v.sort(); for (size_t i = 0; i < minus; 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() != plus){ ans = ans * 10 + v.back(); v.pop_back(); } while(!v.empty()){ ans += v.front(); v.pop_front(); } return ans; } 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(); std::vector vv; while(v.size() > 1){ int mi = v.front();v.pop_front(); int ma = v.back();v.pop_back(); vv.push_back(mi - ma); } if(v.size() == 1) vv.push_back(v.back()); ans = 0; while(!vv.empty()){ int num = vv.back(); vv.pop_back(); ans += num; } return ans; } 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; }