#include #include #include #include #include template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } template struct CoordComp { std::vector v; bool sorted; CoordComp() : sorted(false) {} int size() { return v.size(); } void add(T x) { v.push_back(x); } void build() { std::sort(v.begin(), v.end()); v.erase(std::unique(v.begin(), v.end()), v.end()); sorted = true; } int get_idx(T x) { assert(sorted); return lower_bound(v.begin(), v.end(), x) - v.begin(); } T &operator[](int i) { return v[i]; } }; #define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i)) #define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i)) #define rep(i, n) For(i, 0, n) #define rrep(i, n) rFor(i, n, 0) #define fi first #define se second using namespace std; using lint = long long; using pii = pair; using pll = pair; using namespace atcoder; int op(int a, int b) { return a + b; } int e() { return 0; } int target; bool f(int x) { return x < target; } lint solve(string &s) { int n = s.size(); segtree st1(n), st2(n), st3(n); // ^, *, ) rep(i, n) { if (s[i] == '^') st1.set(i, 1); if (s[i] == '*') st2.set(i, 1); if (s[i] == ')') st3.set(i, 1); } lint ans = 0; rep(i, n) if (s[i] == '(') { target = 2; int a = st1.max_right(i + 1); if (a == n) continue; target = 1; int b = st2.max_right(a + 1); if (b == n) continue; ans += st3.prod(b + 1, n); } return ans; } int main() { string s; cin >> s; printf("%lld ", solve(s)); reverse(s.begin(), s.end()); rep(i, s.size()) { if (s[i] == '(') s[i] = ')'; else if (s[i] == ')') s[i] = '('; } printf("%lld\n", solve(s)); }