#include #include #include #include #include #include #include #include #include #include #include #include //#include "toollib.h" #define INT_MAX 2147483647 #define Loop(i, n) for(int i = 0; i < (int)n; i++) #pragma warning (disable:4018) using namespace std; typedef long long int lint; typedef struct { int x; int y; }coordinate; //***** Main Program ***** int main() { int N; cin >> N; int countplus = 0, countminus = 0; vector list; Loop(i, N) { char buff; cin >> buff; if (buff == '+') countplus++; else if (buff == '-') countminus++; else { list.push_back((int)(buff - '0')); } } int ret1 = 0, ret2 = 0; sort(list.begin(), list.end(), greater()); int a = list.size() - countplus - countminus; Loop(i, a) ret1 += list[i] * (int)pow(10, a - 1 - i); Loop(i, countplus) { ret1 += list[a + i]; } Loop(i, countminus) { ret1 -= list[a + countplus + i]; } cout << ret1 << " "; if (countminus != 0) { Loop(i, a) ret2 -= list[i] * (int)pow(10, a - 1 - i); Loop(i, countminus - 1) { ret2 -= list[a + i]; } Loop(i, countplus+1) { ret2 += list[a + countminus - 1 + i]; } } else { int b = countplus + 1; int p = 0, q = 1; Loop(i, list.size()) { if (p == b) { p = 0; q *= 10; } ret2 += list[i] * q; p++; } } cout << ret2 << endl; return 0; }