#include #include #include #include using namespace std; int evaluate(const string& s) { enum State { STATE_OPERATOR, STATE_NUMBER }; State state = STATE_OPERATOR; int result = 0; char lastOperator = 0; int number = 0; for (size_t i = 0; i <= s.size(); ++i) { char ch = s.c_str()[i]; switch (state) { case STATE_OPERATOR: if (isdigit(ch)) { number *= 10; number += (int)(ch - '0'); state = STATE_NUMBER; } else { return numeric_limits::min(); } break; case STATE_NUMBER: if (isdigit(ch)) { number *= 10; number += (int)(ch - '0'); } else if (ch == '+' || ch == '-') { result += number * (lastOperator == '-' ? -1 : 1); number = 0; lastOperator = ch; state = STATE_OPERATOR; } else if (ch == 0) { result += number * (lastOperator == '-' ? -1 : 1); return result; } else { return numeric_limits::min(); } break; } } return numeric_limits::min(); } int main() { string s; cin >> s; int result = numeric_limits::min(); for (size_t start = 0; start < s.size(); ++start) { string expression = s.substr(start) + s.substr(0, start); result = max(result, evaluate(expression)); } cout << result << endl; return 0; }