#include #include #include using namespace std; #define RREP(i,s,e) for (int i = e-1; i >= s; i--) #define rrep(i,n) RREP(i,0,n) #define REP(i,s,e) for (int i = s; i < e; i++) #define rep(i,n) REP(i,0,n) long long calc(string s) { if (s.empty()) return 0; size_t len; long long x = stol(s,&len); return x + calc(s.substr(len)); } int main() { int n; cin >> n; string op; string num; rep(i,n) { char c; cin >> c; if (isdigit(c)) num.push_back(c); else op.push_back(c); } sort(op.begin(),op.end()); sort(num.begin(),num.end(),greater{}); int pos = num.size() - op.size(); string ans = num.substr(0,pos); for (auto p = op.begin(), q = num.begin() + pos; p != op.end(); p++, q++) { ans.push_back(*p); ans.push_back(*q); } cout << calc(ans) << " "; ans = ""; auto p = op.begin(); auto q = num.rbegin(); for (; p != op.end(); p++, q++) { ans.push_back(*q); ans.push_back(*p); } ans.append(num.substr(0,pos)); cout << calc(ans) << endl; return 0; }