# ----------- # yukicoder # No.457 (^^*) # http://yukicoder.me/problems/no/457 # ------- s = input() left_pos = [i for i, k in enumerate(s) if k == '('] def left_solve(): res = 0 tmp_stock = None first_index = None for i in left_pos: if tmp_stock is not None: if i < first_index: res += tmp_stock continue else: tmp_stock = None first_index = None tmp = s[i+1:] count = 0 for j, elm in enumerate(tmp): if count < 2: if elm == '^': if first_index is None: first_index = i + j count += 1 else: if elm == '*': tmp_stock = tmp[j+1:].count(')') res += tmp_stock break return res def right_solve(): res = 0 tmp_stock = None first_index = None for i in left_pos: if tmp_stock is not None: if i < first_index: res += tmp_stock continue else: tmp_stock = None first_index = None tmp = s[i+1:] count = 0 for j, elm in enumerate(tmp): if count < 1: if elm == '*': if first_index is None: first_index = i + j count += 1 elif count < 2: if elm == '^': count += 1 else: if elm == '^': tmp_stock = tmp[j+1:].count(')') res += tmp_stock break return res print(left_solve(), right_solve())