Description

Given a balanced parentheses string s, return its score. () has score 1, AB has score A+B, (A) has score 2*A.

Examples

Input:s = "(()(()))"
Output:6
Explanation:

(()()) = 2*(1+2) = 6.

Input:s = "()(())"
Output:3
Explanation:

() + (()) = 1 + 2*1 = 1 + 2 = 3. The first () scores 1, the second (()) contains one () which scores 1, then doubled to 2, for a total of 3.

Input:s = "((()))"
Output:4
Explanation:

((())) = 2*(2*(1)) = 2*2 = 4. Starting from the innermost (), which scores 1, each surrounding pair of parentheses doubles the score: (()) = 2*1 = 2, then ((())) = 2*2 = 4.

Constraints

  • 2 ≤ s.length ≤ 50

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!