#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //#define __int64 long long #define long __int64 #define REP(i,a,b) for(int i=a;i que,que2; cin >> n; rep(i,n){ cin >> c[num_cnt]; if(c[num_cnt] == "+"){ cnt[1] ++; }else if(c[num_cnt] == "-"){ cnt[0] ++; }else{ data[num_cnt] = c[num_cnt][0] - '0'; num_cnt ++; } } sort(data, data + num_cnt, greater()); rep(i,num_cnt){ //降順 que.push(data[i]); } //最大値算出 ans = 0; while(que.size() > (cnt[0] + cnt[1])){ ans *= 10; ans += que.front(); que.pop(); } while(que.size() > cnt[0]){ ans += que.front(); que.pop(); } while(!que.empty()){ ans -= que.front(); que.pop(); } cout << ans; //最小値算出 ans = 0; if(cnt[0] > 0){ rep(i,num_cnt){ que2.push(data[i]); //降順 } while(que2.size() > (cnt[0] + cnt[1])){ ans *= 10; ans -= que2.front(); que2.pop(); } while(que2.size() > cnt[1] + 1){ ans -= que2.front(); que2.pop(); } while(!que2.empty()){ ans += que2.front(); que2.pop(); } cout << " " << ans << endl; }else{ reverse(data, data + num_cnt); rep(i,num_cnt){ //昇順 que2.push(data[i]); } int calc[10] = {0}; int mo = cnt[1] + 1; for(int i=0; !que2.empty(); i++){ calc[i % mo] *= 10; calc[i % mo] += que2.front(); que2.pop(); } for(int i=0; i