https://www.acmicpc.net/problem/1662
# 메모리 초과 코드
import sys
input = sys.stdin.readline
stack = []
temp = ''
str = input().rstrip('\n')
for i in str:
if i != ')':
stack.append(i)
else:
while True:
if stack[-1] == '(':
stack.pop()
break
else:
temp += stack.pop()
stack.append(temp * int(stack.pop()))
temp = ''
cnt = 0
for i in stack:
cnt += len(i)
print(cnt)
# 옳은 코드
import sys
input = sys.stdin.readline
stack = []
temp = 0
length = 0
str = input().rstrip('\n')
flag = 0
for i in str:
if i != ')':
stack.append(i)
elif i == ')' and flag == 1:
while True:
if stack[-1] == '(':
stack.pop()
break
else:
if type(stack[-1]) == int:
temp += stack.pop()
else:
temp += 1
stack.pop()
stack.append(temp * int(stack.pop()))
temp = 0
elif i == ')' and flag == 0:
while True:
if stack[-1] == '(':
stack.pop()
break
else:
length += 1
stack.pop()
stack.append(length * int(stack.pop()))
flag = 1
cnt = 0
for i in stack:
if isinstance(i, int):
cnt += i
else:
cnt += len(i)
print(cnt)