// yukicoder: No.457 (^^*) // 2019.6.26 bal4u #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif void ins(char *s) // 文字列の入力 スペース以下の文字で入力終了 { do *s = gc(); while (*s++ > ' '); *(s-1) = 0; } int L[4], R[4]; int al, ar; char S[10005]; int main() { char *s; ins(s = S); while (*s) { if (*s == '(') L[0]++, R[0]++; else if (*s == '^') { if (L[1]) L[2] += L[1], L[1] = 0; if (L[0]) L[1] += L[0], L[0] = 0; if (R[2]) R[3] += R[2], R[2] = 0; if (R[1]) R[2] += R[1], R[1] = 0; } else if (*s == '*') { if (L[2]) L[3] += L[2], L[2] = 0; if (R[0]) R[1] += R[0], R[0] = 0; } else if (*s == ')') al += L[3], ar += R[3]; s++; } printf("%d %d\n", al, ar); return 0; }