#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() template inline bool chmax(A &a, B b) { if (a inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pll; typedef pair P; const ll INF = 1ll<<29; const ll MOD = 1000000007; const double EPS = 1e-10; int n; int cnt[12]; int main() { cin >> n; REP(i, n) { char c; scanf(" %c", &c); if (c == '+') cnt[10]++; else if (c == '-') cnt[11]++; else cnt[c - '0']++; } ll ma = 0; int tmp[12]; copy(cnt, cnt + 12, tmp); // max REP(i, cnt[11]) { int now; REP(j, 10) if (cnt[j]) {now = j; break;} ma -= now; cnt[now]--; } REP(i, cnt[10]) { int now; REP(j, 10) if (cnt[j]) {now = j; break;} ma += now; cnt[now]--; } ll t = 0; for (int i = 9; i >= 0; i--) { for (int j = 0; j < cnt[i]; j++) t = t * 10 + i; } ma += t; // min ll mi = 0; copy(tmp, tmp + 12, cnt); if (cnt[11] == 0) { vector v(15, 0); int c = 0; REP(i, 10) c += cnt[i]; REP(i, cnt[10] + 1) v[i] += c / (cnt[10] + 1); REP(i, c % (cnt[10] + 1)) v[i]++; vector num(15, 0); while (true) { bool f = true; REP(i, 15) if (v[i]) f = false; if (f) break; int now; REP(i, 10) if (cnt[i]) {now = i; break;} cnt[now]--; pii pos(0, -1); REP(i, 15) chmax(pos, pii(v[i], i)); v[pos.second]--; num[pos.second] = num[pos.second] * 10 + now; } REP(i, 15) mi += num[i]; } else { REP(i, cnt[10] + 1) { int now; REP(j, 10) if (cnt[j]) {now = j; break;} mi += now; cnt[now]--; } REP(i, cnt[11] - 1) { int now; REP(j, 10) if (cnt[j]) {now = j; break;} mi -= now; cnt[now]--; } t = 0; for (int i = 9; i >= 0; i--) { for (int j = 0; j < cnt[i]; j++) t = t * 10 + i; } mi -= t; } printf("%lld %lld\n", ma, mi); return 0; }