// yukicoder: No.193 筒の数式 // 2019.4.13 bal4u #include #include #include //// 高速入力 #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int ins(char *s) // 文字列の入力 スペース以下の文字で入力終了 { char *p = s; do *s = gc(); while (*s++ > ' '); *--s = 0; return s - p; } char S[30]; char *num(int *k, char *s) { int n = 0; while (isdigit(*s)) n = 10 * n + (*s++ & 0xf); *k = n; return s; } int parse(char *s) { int a, op, ans; s = num(&ans, s); while (*s) { op = *s++; s = num(&a, s); if (op == '+') ans += a; else ans -= a; } return ans; } int main() { int i, c, w, a, ans; w = ins(S); memcpy(S + w, S, w); ans = -0x7fffffff; for (i = 0; i < w; i++) { if (isdigit(S[i]) && isdigit(S[i + w - 1])) { c = S[i + w], S[i + w] = 0; if ((a = parse(S + i)) > ans) ans = a; S[i + w] = c; } } printf("%d\n", ans); return 0; }