S = input().strip() n = len(S) # Precompute next_hat (^) and next_star (*) for each position next_hat = [-1] * (n + 1) # next occurrence of ^ from position i next_star = [-1] * (n + 1) # next occurrence of * from position i last_hat = -1 last_star = -1 for i in range(n-1, -1, -1): if S[i] == '^': last_hat = i next_hat[i] = last_hat if S[i] == '*': last_star = i next_star[i] = last_star # Precompute suffix_close: number of ')' from position i to end suffix_close = [0] * (n + 2) for i in range(n-1, -1, -1): suffix_close[i] = suffix_close[i+1] + (1 if S[i] == ')' else 0) left_count = 0 right_count = 0 for a in range(n): if S[a] != '(': continue # Check left pattern: ^^* # Find earliest triplet starting after a # b is the first ^ after a+1 start_b = a + 1 if start_b >= n: b = -1 else: b = next_hat[start_b] if b == -1: contrib_left = 0 else: # Find c, next ^ after b+1 start_c = b + 1 if start_c >= n: c = -1 else: c = next_hat[start_c] if c == -1: contrib_left = 0 else: # Find d, next * after c+1 start_d = c + 1 if start_d >= n: d = -1 else: d = next_star[start_d] if d == -1 or d >= n: contrib_left = 0 else: contrib_left = suffix_close[d + 1] left_count += contrib_left # Check right pattern: *^^ start_b = a + 1 if start_b >= n: b = -1 else: b = next_star[start_b] if b == -1: contrib_right = 0 else: # Find c, next ^ after b+1 start_c = b + 1 if start_c >= n: c = -1 else: c = next_hat[start_c] if c == -1: contrib_right = 0 else: # Find d, next ^ after c+1 start_d = c + 1 if start_d >= n: d = -1 else: d = next_hat[start_d] if d == -1 or d >= n: contrib_right = 0 else: contrib_right = suffix_close[d + 1] right_count += contrib_right print(left_count, right_count)