#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, mi = 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 copy(tmp, tmp + 12, cnt); bool f = cnt[11] == 0; 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; }