#include using namespace std; int main(){ int n; string str = "",tmp; cin >> n; for(int i = 0; i < n; i++){ cin >> tmp; str += tmp; } sort(str.begin(),str.end()); int plus = 0,minus = 0; for(int i = 0; i < n; i++){ if(str[i] == '+') plus++; else if(str[i] == '-') minus++; else break; } sort(str.begin(),str.end(),greater()); vector data(plus+minus+1); int j; for(j = 0; j < n - ((plus+minus) * 2); j++){ data[0] += str[j]; } int x = 1; for(int k = j; k < n - (plus + minus); k++){ data[x] = str[k]; x++; } long long max = stoll(data[0]); long long plus2 = plus, minus2 = minus; for(long long i = 1; i < data.size(); i++){ if(plus > 0){ max += stoi(data[i]); plus--; }else{ max -= stoi(data[i]); minus--; } } long long min = 0; if(minus2 > 0){ min = -1 * stoll(data[0]); minus2--; for(long long i = 1; i < data.size(); i++){ if(minus2 > 0){ min -= stoi(data[i]); minus2--; }else{ min += stoi(data[i]); plus2--; } } }else{ int up = 1; for(long long i = 0; i < n - plus2; i++){ // cout << ((int)str[i] - 48) << " " << min << endl; // cout << up << " " << ((int)str[i] - 48) << endl; // cout << (i+1) << " " << up << endl; min += up * ((int)str[i] - 48); if((i+1) % (plus2+1) == 0) up *= 10; } } cout << max << " " << min << endl; return 0; }