#include #include #include #include #include #include #include #include #include #include #include #include #include #define repd(i,a,b) for (int i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define var auto #define mod 1000000007 #define inf 2147483647 #define nil -1 typedef long long ll; using namespace std; int inputValue(){ int a; cin >> a; return a; } template void output(T a, int precision) { if(precision > 0){ cout << fixed << setprecision(precision) << a << "\n"; } else{ cout << a << "\n"; } } // end of template int main() { cin.tie(0); // source code int N; cin >> N; vector C; int plus = 0; int minus = 0; rep(i, N){ char c; cin >> c; if (c == '+') { plus++; } else if (c == '-'){ minus++; } else{ C.push_back(c - '0'); } } sort(C.begin(), C.end()); ll retmax = 0; ll retmin = 0; int ops = plus + minus; if (plus == 0) { ll big = 0; reverse(C.begin(), C.end()); rep(i, C.size() - ops){ big *= 10; big += C[i]; } retmax = big; retmin = C[C.size() - 1]; repd(i, (int)C.size() - ops, C.size()){ retmax -= C[i]; if (i != C.size() - 1) { retmin -= C[i]; } } retmin -= big; cout << retmax << " " << retmin << endl; } else if(minus == 0){ ll retmin = 0; ll retmax = 0; rep(i, C.size() - ops){ retmin *= 10; retmax *= 10; retmin += C[i]; retmax += C[C.size() - 1 - i]; } repd(i, (int)C.size() - ops, C.size()){ retmin += C[i]; retmax += C[C.size() - 1 - i]; } cout << retmax << " " << retmin << endl; } else{ ll big = 0; reverse(C.begin(), C.end()); rep(i, C.size() - ops){ big *= 10; big += C[i]; } int tmpP = plus; retmax = big; // max repd(i, (int)C.size() - ops, C.size()){ if (tmpP) { retmax += C[i]; tmpP--; continue; } retmax -= C[i]; } int tmpM = minus - 1; retmin = -big; repd(i, (int)C.size() - ops, C.size()){ if (tmpM) { retmin -= C[i]; tmpM--; continue; } retmin += C[i]; } cout << retmax << " " << retmin << endl; } return 0; }