//#include #include //#include using namespace std; //using namespace atcoder; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair p; const int INF = 1e9; const ll LINF = ll(1e18); const int MOD = 1000000007; const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) \ { \ cout << x << ' '; \ } \ cout << endl; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //cout<> n; int pc = 0; int mc = 0; vector a; rep(i, n) { char temp; cin >> temp; if (temp == '+') pc++; else if (temp == '-') mc++; else a.push_back(temp - '0'); } if (mc) { sort(ALL(a), greater()); vector b; int m = a.size() - (pc + mc); ll base = 1; ll big = 0; for (int i = m - 1; i >= 0; i--) { big += base * a[i]; base *= 10; } b.push_back(big); for (int i = m; i < a.size(); i++) { b.push_back(ll(a[i])); } ll ansm = b[0]; int pcc = pc; int mcc = mc; rep(i, b.size() - 1) { if (pcc) { ansm += b[i + 1]; pcc--; } else { ansm -= b[i + 1]; } } cout << ansm << " "; reverse(ALL(b)); ansm = b[0]; rep(i, b.size() - 1) { if (pc) { ansm += b[i + 1]; pc--; } else { ansm -= b[i + 1]; } } cout << ansm << "\n"; } else { sort(ALL(a), greater()); vector b; int m = a.size() - (pc + mc); ll base = 1; ll big = 0; for (int i = m - 1; i >= 0; i--) { big += base * a[i]; base *= 10; } b.push_back(big); for (int i = m; i < a.size(); i++) { b.push_back(ll(a[i])); } ll ansm = b[0]; rep(i, b.size() - 1) { ansm += b[i + 1]; } cout << ansm << " "; sort(ALL(a)); vector> c(pc+1); int j=0; rep(i,a.size()){ c[j].push_back(a[i]); j++; if(j==pc+1)j=0; } ansm=0; rep(i,c.size()){ ll base=1; for(int k=c[i].size()-1;k>=0;k--){ ansm+=base*c[i][k]; base*=10; } } cout<