#include #include #include #include #include #include #include #include #include // require sort next_permutation count __gcd reverse etc. #include // require abs exit atof atoi #include // require scanf printf #include #include // require accumulate #include // require fabs #include #include #include #include // require setw #include // require stringstream #include // require memset #include // require tolower, toupper #include // require freopen #include // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() #define INF 1<<28 using namespace std; typedef long long ll; typedef pair P; vector pre_trans (string eq ){ vector res; res.clear(); int n = eq.length(); string ope = ""; rep (i, n ){ if (isdigit(eq[i] ) ){ ope += eq[i]; }else{ res.push_back (ope ); ope = ""; ope += eq[i]; res.push_back (ope ); ope = ""; } // end if } // end if if (!ope.empty() ) res.push_back (ope ); return res; } // 中置記法を逆ポーランド記法に変換 vector trans (string q ){ // 式に出て来るオペランド(数値)とオペレーター(演算子)に優先順位の番号を付ける map pri; rep (i, 10 ) pri[(char)('0'+i)] = 0; // pri['*'] = 1, pri['/'] = 1, pri['%'] = 1; pri['+'] = 2, pri['-'] = 1; // pri['('] = 3, pri[')'] = 3; vector p; stack s; vector eq = pre_trans (q ); string ope = ""; if (!isdigit(eq[0][0] ) ) return vector(); s.push(eq[0]); string ss = ""; int n = eq.size(); for (int i = 1; i < n; i++ ){ int cp = pri[eq[i][0]]; ss = s.top(); while (!s.empty() && cp > pri[ss[0]] ){ p.push_back (s.top() ); s.pop(); } // end while s.push (eq[i] ); } // end for while (!s.empty() ){ p.push_back (s.top() ); s.pop(); } // end while return p; } int s2i(string s ){ stringstream ss (s ); int res; ss >> res; return res; } int calc (vector s ){ if (s.empty() ) return INF; int n = s.size(); stack num; stack ope; rep (i, n ){ if (isdigit(s[i][0] ) ){ num.push (s2i(s[i] ) ); }else{ int a, b; char c; int curr; ope.push (s[i][0] ); if (!num.empty() ){ b = num.top(); num.pop(); }else{ return INF; } // end if if (!num.empty() ){ a = num.top(); num.pop(); }else{ return INF; } // end if if (!ope.empty() ){ c = ope.top(); ope.pop(); }else{ return INF; } // end if switch (c ){ case '+': curr = a + b; num.push (curr ); break; case '-': curr = a - b; num.push (curr ); break; } // end switch } // end if } // end rep if (num.empty() ) return INF; return num.top(); } string disp(vector s ){ string res = ""; int n = s.size(); rep (i, n ){ res += s[i]; res += (i != n - 1 ? ',' : ' '); } // end rep return res; } int main() { ios_base::sync_with_stdio(0); string s; cin >> s; int n = s.length(); int res = -INF; rep (i, n ){ string t = s.substr(i) + s.substr(0,i); vector curr = trans (t ); int cur2 = calc(curr ); // cerr << t << ' '; // cerr << disp(curr ); // cerr << cur2 << endl; // cerr << t << endl; if (cur2 == INF ) continue; res = max (res, cur2 ); } // end rep cout << res << endl; return 0; }