/* -*- coding: utf-8 -*- * * 297.cc: No.297 カードの数式 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 15; const int INF = 1 << 30; /* typedef */ typedef vector vi; /* global variables */ int ds[10]; /* subroutines */ /* main */ int main() { int n; cin >> n; int dn = 0, opn = 0, omn = 0; for (int i = 0; i < n; i++) { char ch; cin >> ch; if (ch == '+') opn++; else if (ch == '-') omn++; else ds[ch - '0']++, dn++; } int on = opn + omn; int di = 0; vi v; for (int i = 0; i < on; i++) { while (ds[di] == 0) di++; v.push_back(di); ds[di]--; } int maxd = 0; for (int di = 9; di >= 0;) { if (ds[di] > 0) maxd = maxd * 10 + di, ds[di]--; else di--; } v.push_back(maxd); //printf("maxd=%d\n", maxd); int maxv = v[on]; for (int i = 0; i < on; i++) { if (i < opn) maxv += v[on - 1 - i]; else maxv -= v[on - 1 - i]; } int minv = v[0]; for (int i = 0; i < on; i++) { if (i < opn) minv += v[i + 1]; else minv -= v[i + 1]; } printf("%d %d\n", maxv, minv); return 0; }