#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include "bits/stdc++.h" #define REP(i,a,b) for(int i=a;i= right_parenthesis_id && s[i] == ')') { right_parenthesis_cnt--; } } if (star_id < hat_id2) { chstar(hat_id2, star_id, right_parenthesis_id, right_parenthesis_cnt); } } if (s[i] == '*') { if (star_id <= i) { chstar(star_id, star_id, right_parenthesis_id, right_parenthesis_cnt); } } if (s[i] == ')') { if (right_parenthesis_id <= i) { ch_parenthesis(right_parenthesis_id, right_parenthesis_id, right_parenthesis_cnt); } } if (s[i] == '(' && hat_id1 != INF && hat_id2 != INF && star_id != INF) { res += right_parenthesis_cnt; } } dump(right_parenthesis_cnt); return res; } //int left_calc() { // int res = 0; // rep(i, s.size()) { // if (s[i] == '(') { // int stage = 0; // int right_parenthesis_cnt = 0; // REP(j, i, s.size()) { // if (stage == 0 && s[j] == '^') stage = 1; // else if (stage == 1 && s[j] == '^') stage = 2; // else if (stage == 2 && s[j] == '*') stage = 3; // else if (stage == 3 && s[j] == ')') { // right_parenthesis_cnt++; // } // } // res += right_parenthesis_cnt; // } // } // return res; //} int right_calc() { int res = 0; rep(i, s.size()) { if (s[i] == '(') { int stage = 0; int right_parenthesis_cnt = 0; REP(j, i, s.size()) { if (stage == 0 && s[j] == '*') stage = 1; else if (stage == 1 && s[j] == '^') stage = 2; else if (stage == 2 && s[j] == '^') stage = 3; else if (stage == 3 && s[j] == ')') { right_parenthesis_cnt++; } } res += right_parenthesis_cnt; } } return res; } void solve() { cin >> s; ll res_left = left_calc(); ll res_right = right_calc(); cout << res_left << " " << res_right << endl; } signed main() { freopen("debug_log.txt", "w", stderr); cout << fixed << setprecision(20); rep(i, 1) solve(); return 0; }