#include //const static double de_PI = 3.14159265358979323846; //const static int de_MOD = 1000000007; //const static int de_MAX = 999999999; //const static int de_MIN = -999999999; int main(void) { //std::ifstream in("123.txt"); std::cin.rdbuf(in.rdbuf()); int N = 0; std::cin >> N; std::string num; int plus = 0, minus = 0; std::string temp; for (int i = 0; i < N; i++) { std::cin >> temp; switch (temp[0]) { case '+':plus++; break; case '-':minus++; break; default:num.push_back(temp[0]); } } std::sort(num.rbegin(), num.rend()); int digit = num.length() - plus - minus; long long int max = std::stoll(num.substr(0, digit)); for (int i = 0; i < plus; i++) { max += std::stoi(num.substr(digit, 1)); digit++; } for (int i = 0; i < minus; i++) { max -= std::stoi(num.substr(digit, 1)); digit++; } long long int min = 0; if (minus == 0) { std::sort(num.begin(), num.end()); std::vector A(plus + 1); bool flg = false; for (unsigned int i = 0; i < num.length(); i++) { if (i % (plus + 1) == 0) { flg = !flg; } if (flg) { A[i % (plus + 1)].push_back(num[i]); } else { A[plus - (i % (plus + 1))].push_back(num[i]); } } for (int i = 0; i < plus + 1; i++) { min += std::stoll(A[i]); } } else { digit = num.length() - plus - minus; min = std::stoll(num.substr(0, digit))*-1; for (int i = 0; i < minus - 1; i++) { min -= std::stoi(num.substr(digit, 1)); digit++; } for (int i = 0; i < plus + 1; i++) { min += std::stoi(num.substr(digit, 1)); digit++; } } std::cout << max <<" " << min << std::endl; }