#include #include #include #include #include #include #include #include using namespace std; typedef pair PLL; char R[547]; vector V; vector O; vector >T; PLL zrataj(int from, int to){ if (T[from][to].first >= 0) return T[from][to]; if (from+1 == to) { T[from][to].first = T[from][to].second = V[from]; return T[from][to]; } for (int i = from; i < to-1; i++){ PLL a, b, pom; a = zrataj(from, i+1); b = zrataj(i+1, to); if(O[i] == '+'){ pom.first = a.first+b.first; pom.second = a.second+b.second; } else if(O[i] == '*'){ pom.first = a.first*b.first; pom.second = a.second*b.second; } if (T[from][to].first == -1) { T[from][to] = pom; continue; } if (pom.first < T[from][to].first) T[from][to].first = pom.first; if (pom.second > T[from][to].second) T[from][to].second = pom.second; } //cout << from << " " << to << ": " << T[from][to].first << ", " << T[from][to].second << endl; return T[from][to]; } int main(void){ while(8){ fgets(R, 500, stdin); if (string(R) == "END\n") break; O.resize(0); V.resize(0); T.resize(0); int l = (int)strlen(R), pom = 0; for (int i = 0; i < l; i++){ if(isdigit(R[i])){ pom *= 10; pom += R[i] - '0'; } else{ V.push_back(pom); pom = 0; if (R[i] == '+' || R[i] == '*') O.push_back(R[i]); } } T.resize(V.size()+47, vector(V.size()+47, PLL(-1, -1))); zrataj(0, (int)V.size()); printf("%lld %lld\n", T[0][V.size()].first, T[0][V.size()].second); } }