#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_extra(int plus, int minus) { while(nums.size() % plus != 0) nums.insert(nums.begin(), 0); int k = nums.size() / plus; int ret = 0; int j = 0; while(k) { int _k = pow(10, k-1); REP(i,plus) { ret += _k * nums[j++]; } k--; } return ret; } int calc_min(int plus, int minus) { int maxc = 0; int j = 0; plus += 1; if (minus == 0) { return calc_extra(plus, minus); } while(plus + minus) { 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; }