#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define pi M_PI typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVI; typedef pair P; typedef pair PL; int calc(string s){ int n = s.length(); VVI dp(n+1, VI(5)); REP(i,n){ if (s[i] == '('){ dp[i+1][0] = dp[i][0] + 1; dp[i+1][1] = dp[i][1]; dp[i+1][2] = dp[i][2]; dp[i+1][3] = dp[i][3]; }else if (s[i] == '*'){ dp[i+1][1] = dp[i][1] + dp[i][0]; dp[i+1][2] = dp[i][2]; dp[i+1][3] = dp[i][3]; }else if (s[i] == '^'){ dp[i+1][0] = dp[i][0]; dp[i+1][2] = dp[i][1]; dp[i+1][3] = dp[i][3] + dp[i][2]; }else{ dp[i+1][0] = dp[i][0]; dp[i+1][1] = dp[i][1]; dp[i+1][2] = dp[i][2]; dp[i+1][3] = dp[i][3]; dp[i+1][4] = dp[i][3]; } } int res = 0; REP(i,n+1) res += dp[i][4]; return res; } int main() { string s; cin >> s; ll a = calc(s); reverse(s.begin(), s.end()); REP(i,s.length()){ if (s[i] == '(') s[i] = ')'; else if (s[i] == ')') s[i] = '('; } cout << s << endl; ll b = calc(s); printf("%lld %lld\n", b, a); return 0; }