#include "bits/stdc++.h" #define REP(i,n,N) for(int i=(n); i<(N); i++) #define RREP(i,n,N) for(ll i=(N-1); i>=n; i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define ALL(v) (v).begin(),(v).end() #define p(s) cout<<(s)<> typedef long long ll; using namespace std; const ll inf = 1e18+7; int main() { int N; cin>>N; char c[16]; ll mx=0,mn=inf; REP(i,0,N){ cin>>c[i]; } sort(c,c+N); do{ if(!isdigit(c[N-1])) continue; bool pren=true; bool ok=true; char en = '+'; ll sum=0; ll tmp=0; REP(i,0,N){ if(isdigit(c[i])){ pren=false; tmp*=10; tmp+=c[i]-'0'; }else{ if(pren) { ok=false; break; }else{ if(en=='+') sum+=tmp; else sum-=tmp; tmp=0; en = c[i]; pren =true; } } } if(ok){ if(en=='+') sum+=tmp; else sum-=tmp; mx=max(mx,sum); mn=min(mn,sum); } }while(next_permutation(c,c+N)); p2(mx,mn); return 0; }