#include using namespace std; using ll = long long; #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define ALL(v) (v).begin(), (v).end() #define p(s) cout<<(s)<> N; ll plus = 0; ll minus = 0; string s; FOR(i, 0, N){ char c; cin >> c; if(c=='+') plus++; if(c=='-') minus++; if(isdigit(c)) s.push_back(c); } string s_max; string s_min; // 全て+ if(minus==0){ // 最小値 string t = s; sort(ALL(t)); ll L = plus+1; string box[L]; ll index = 0; for(char c : s){ box[index].push_back(c); index++; index %= L; } stringstream ss; FOR(i, 0, L){ if(i){ ss << '+'; } ss << box[i]; } s_min = ss.str(); // pn(s_min); // 最大値 stringstream ss_max; t = s; L = s.size(); sort(ALL(t), greater()); ss_max << t.substr(0, L-plus); FOR(i, L-plus, L){ ss_max << '+' << s[i]; } s_max = ss_max.str(); // pn(s_max); } else if(plus==0 && minus>0){ // マイナスのみ // 最大値 string t = s; sort(ALL(t), greater()); ll L = t.size(); stringstream ss; ss << t.substr(0, L-minus); string sub = t.substr(L-minus); for(char c : sub){ ss << '-' << c; } s_max = ss.str(); // pn(s_max); // 最小値 t = s; sort(ALL(t)); stringstream ss_min; FOR(i, 0, minus){ ss_min << t[i] << '-'; } sub = t.substr(minus); sort(ALL(sub), greater()); ss_min << sub; s_min = ss_min.str(); // pn(s_min); } else{ // +, -の混合 // 最大値 string t = s; sort(ALL(t)); string s_for_minus = t.substr(0, minus); string s_for_plus = t.substr(minus, plus); string rest = t.substr(minus+plus); sort(ALL(rest), greater()); stringstream ss; ss << rest; for(char c : s_for_plus){ ss << '+' << c; } for(char c : s_for_minus){ ss << '-' << c; } s_max = ss.str(); // pn(s_max); // 最小値 t = s; sort(ALL(t)); s_for_plus = t.substr(0, plus); s_for_minus = t.substr(plus, minus); rest = t.substr(plus+minus); sort(ALL(rest), greater()); stringstream ss2; for(char c : s_for_plus){ ss2 << c << '+'; } for(char c : s_for_minus){ ss2 << c << '-'; } ss2 << rest; s_min = ss2.str(); // pn(s_min); } State it = s_max.begin(); ll ma = expression(it); State it2 = s_min.begin(); ll mi = expression(it2); p2(ma, mi); return 0; }