class Solution(object):
def scoreOfParentheses(self, s):
"""
:type s: str
:rtype: int
"""
st = [0]
for c in s:
if c == "(":
st.append(0)
else:
t = st.pop()
if t == 0:
st[-1] += 1
else:
st[-1] += 2 * t
return st[-1]