#include using namespace std; int main() { string s; cin >> s; int64_t ansL = 0; // (^^*) // 01234 vector cntL(4); for (int i = 0; i < s.size(); i++) { if (s[i] == '(') { cntL[0] += 1; } if (s[i] == '^') { cntL[2] += cntL[1]; cntL[1] = cntL[0]; cntL[0] = 0; } if (s[i] == '*') { cntL[3] += cntL[2]; cntL[2] = 0; } if (s[i] == ')') { ansL += cntL[3]; } } int64_t ansR = 0; // (*^^) // 01234 vector cntR(4); for (int i = 0; i < s.size(); i++) { if (s[i] == '(') { cntR[0] += 1; } if (s[i] == '*') { cntR[1] += cntR[0]; cntR[0] = 0; } if (s[i] == '^') { cntR[3] += cntR[2]; cntR[2] = cntR[1]; cntR[1] = 0; } if (s[i] == ')') { ansR += cntR[3]; } } cout << ansL << " " << ansR << endl; }