#include #include #include #include using namespace std; int main(){ int n; char* k; int num_p = 0; int num_m = 0; priority_queue, less > q_max; priority_queue, less > q_min; int c = 0; cin >> n; k = new char[n]; for(int i=0;i> k[i]; if(k[i] == '+'){ num_p += 1; } else if(k[i] == '-'){ num_m += 1; } else{ c += 1; int d = (int)(k[i]-'0'); q_max.push(d); q_min.push(d); } } int num_d = q_max.size(); int max_d = num_d-num_p-num_m; int result_max = 0; int result_min = 0; // MAX int i = max_d; int tmp = 0; while(i>0){ tmp += q_max.top()*pow(10,i-1); q_max.pop(); i -= 1; } result_max += tmp; int p=num_p; while(p>0){ result_max += q_max.top(); q_max.pop(); p -= 1; } int m = num_m; while(m>0){ result_max -= q_max.top(); q_max.pop(); m -= 1; } if(num_m!=0){ // contain at least 1 minus(es) // min i = max_d; tmp = 0; while(i>0){ tmp += q_min.top()*pow(10,i-1); q_min.pop(); i -= 1; } result_min -= tmp; int m = num_m; while(m>1){ result_min -= q_min.top(); q_min.pop(); m -= 1; } int p = num_p; while(p>=0){ result_min += q_min.top(); q_min.pop(); p -= 1; } } else{ // all plus int count = 0; int digit = 0; while(!q_min.empty()){ result_min += q_min.top()*pow(10,digit); q_min.pop(); count += 1; if(count > num_p) { count = 0; digit += 1; } } } cout << result_max << " " << result_min << endl; return 0; }