class Solution:
    def scoreOfParentheses(self, S: str) -> int:
        stack = [0]
        
        for p in S:
            if p == "(":
                stack.append(0)
            else:
                elem = stack.pop()
                stack[-1] +=max(2*elem,1)
                
        return stack.pop()

6f1a57c7a55b73f8043c5ff75d1b9083dbd8d36a
<mask token>

class Solution:
    <mask token>

class Solution:

    def scoreOfParentheses(self, S: str) ->int:
        stack = [0]
        for p in S:
            if p == '(':
                stack.append(0)
            else:
                elem = stack.pop()
                stack[-1] += max(2 * elem, 1)
        return stack.pop()

class Solution:
    def scoreOfParentheses(self, S: str) -> int:
        stack = [0]
        
        for p in S:
            if p == "(":
                stack.append(0)
            else:
                elem = stack.pop()
                stack[-1] +=max(2*elem,1)
                
        return stack.pop()
