n = input()
ans = 0 # 답
temp = 1 # 임시 값
st = [] # 괄호 저장
for i in range(len(n)):
if n[i] == '(':
st.append(n[i])
temp *=2
elif n[i] == ')':
if len(st) == 0 or st[-1] == '[' :
ans = 0
break
if n[i-1] == '(':
ans += temp
st.pop()
temp//=2
elif n[i] == '[':
st.append(n[i])
temp *=3
elif n[i] == ']':
if len(st) == 0 or st[-1] == '(' :
ans = 0
break
if n[i-1] == '[':
ans += temp
st.pop()
temp//=3
# 0이라면
if len(st) !=0:
print(0)
else:
print(ans)
if len(st) == 0 or st[-1] == '[' :
if len(st) == 0 or st[-1] == '(' :
위 처럼 먼저 스택의 비어있는지를 확인하고 그 다음의 st의 값을 확인해야된다.
만약
if st[-1] == '[' or len(st) == 0 :
if st[-1] == '(' or len(st) == 0 :
이처럼 할 시 백준 제출할 때 index오류가 발생한다.