#include "bits/stdc++.h" using namespace std; #define int long long #define REP(i, n) for(int i=0; i<(n); i++) #define ALL(a) (a).begin(),(a).end() int N,T; vector nums; int calc_max(int plus, int minus) { int maxc = 0; int j = 0; while(plus + minus) { if (minus) { maxc -= nums[j++]; minus--; continue; } if (plus) { maxc += nums[j++]; plus--; continue; } } int k = 1; while(j < nums.size()) { maxc += nums[j++] * k; k *= 10; } return maxc; } int calc_min(int plus, int minus) { int maxc = 0; int j = 0; plus += 1; while(plus + minus) { if (minus == 0 && plus == 1) { int k = pow(10, nums.size() - j - 1); while(j < nums.size()) { maxc += nums[j++] * k; k /= 10; } break; } if (plus) { maxc += nums[j++]; plus--; continue; } if (minus == 1) { int k = 1; while(j < nums.size()) { maxc -= nums[j++] * k; k *= 10; } break; } if (minus) { maxc -= nums[j++]; minus--; continue; } } return maxc; } signed main() { cin >> N; char c; int plus = 0; int minus = 0; REP(i,N) { cin >> c; if (c == '+') plus++; else if (c == '-') minus++; else { nums.push_back(c - '0'); } } sort(ALL(nums)); cout << calc_max(plus, minus) << " " << calc_min(plus, minus) << endl; return 0; }