#include using namespace std; int main(void){ int plus = 0; int minus = 0; vector num; int N, numnum; char in; cin >> N; for(int i=0; i < N; i++){ cin >> in; if('0' <= in && in <= '9') num.push_back(in - '0'); else if(in == '+') plus++; else minus++; } numnum = N - plus - minus; sort(num.begin(), num.end(), greater()); int opnum = plus + minus + 1; int maxop = 0; for(int i=0; i < numnum - (plus+minus); i++){ maxop *= 10; maxop += num[i]; } for(int i=numnum - (plus+minus); i < numnum - minus; i++){ maxop += num[i]; } for(int i=numnum - minus; i < numnum; i++){ maxop -= num[i]; } cout << maxop << " "; maxop = 0; for(int i=0; i < numnum - (plus+minus); i++){ maxop *= 10; maxop += num[i]; } if(minus > 0){ minus--; plus++; maxop = -maxop; } for(int i=numnum - (plus+minus); i < numnum - plus; i++){ maxop -= num[i]; } for(int i=numnum - plus; i < numnum; i++){ maxop += num[i]; } cout << maxop << endl; return 0; }