#include using namespace std; void get_max(vector &num, int64_t mxnum, int pls, int mus, int offset) { int64_t ans = mxnum; for (int i = 0; i < pls; i++) ans += num[i + offset]; for (int i = 0; i < mus; i++) ans -= num[i + offset + pls]; cout << ans << " "; } void mus_ne_0(vector &num, int64_t mxnum, int pls, int mus, int offset) { assert(mus != 0); mus--; int64_t ans = -mxnum; for (int i = 0; i < mus; i++) { ans -= num[i + offset]; } for (int i = 0; i <= pls; i++) { ans += num[i + offset + mus]; } cout << ans << endl; } void mus_eq_0(vector &num, int64_t mxnum, int pls, int mus, int offset) { int64_t ans = 0; for (int i = 0, place = 0; i < num.size(); place++) { for (int _ = 0; _ <= pls; _++) { if (i >= num.size()) break; int64_t nxt = num[i++]; for (int j = 0; j < place; j++) nxt *= 10; ans += nxt; } } cout << ans << endl; } int main() { int n; cin >> n; string s(n, ' '); vector num; int mus = 0, pls = 0; for (char &c : s) { cin >> c; if (c == '+') pls++; else if (c == '-') mus++; else num.push_back(c - '0'); } sort(num.begin(), num.end(), greater()); int64_t mxnum = 0, offset = max((int)num.size() * 2 - n, 0); for (int i = 0; i < num.size() * 2 - n; i++) mxnum = mxnum * 10 + num[i]; get_max(num, mxnum, pls, mus, offset); if (mus) { mus_ne_0(num, mxnum, pls, mus, offset); } else { mus_eq_0(num, mxnum, pls, mus, offset); } return 0; }