#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) (x).begin(),(x).end() #define rep(i,m,n) for(int i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(int i = m;i >= n;--i) #define INF INT_MAX/2 using namespace std; using ll = long long; using R = double; using Data = pair>; const ll MOD = 1e9 + 7; const ll inf = 1LL << 50; struct edge { ll from; ll to; ll cost; }; int main() { int n; cin >> n; vectors(n); vectornum; rep(i, 0, n)cin >> s[i]; int cnt = 0; int cntpl = 0; int cntmi = 0; rep(i, 0, n) { if (s[i] == '+' || s[i] == '-') { if (s[i] == '+')cntpl++; else cntmi++; cnt++; } else { num.pb(s[i] - '0'); } } sort(all(num)); reverse(all(num)); ll mx = 0; ll dgt = 1; int po = num.size()-cnt-1; rep(i, 0, num.size() - cnt) { mx += dgt * num[po]; dgt *= 10; po--; } po = num.size() - cnt; rep(i,0,cntpl) { mx += num[po]; po++; } rep(i, 0, cntmi) { mx -= num[po]; po++; } ll mi = 0; dgt = 1; if (cntmi> 0) { po = num.size() - cnt - 1; rep(i, 0, num.size() - cnt) { mi -= dgt * num[po]; dgt *= 10; po--; } po = num.size() - cnt; rep(i, 0, cntmi - 1) { mi -= num[po]; po++; } rep(i, 0, cntpl+1) { mi += num[po]; po++; } } else { dgt = 1; rep(i, 0, num.size()) { if (i != 0 && i % (cnt + 1) == 0)dgt *= 10; mi += dgt * num[i]; } } cout << mx << " " << mi << endl; return 0; }