#P3015. Balanced Parentheses Score Computation

    ID: 16273 Type: Default 1000ms 256MiB

Balanced Parentheses Score Computation

Balanced Parentheses Score Computation

Given a balanced parentheses string, compute its score using the following rules:

  • The string () has a score of 1.
  • If a string A has score \(s(A)\), then the string (A) has score \(2\times s(A)\).
  • If strings A and B have scores \(s(A)\) and \(s(B)\) respectively, then the concatenated string AB has score \(s(A)+s(B)\).

For example, the string (())() is scored as follows: \(s((())()) = s((())) + s(()) = 2\times1 + 1 = 3\).

inputFormat

The input consists of a single line containing a balanced parentheses string of length \(N\) where \(2 \le N \le 100000\).

outputFormat

Output a single integer representing the score of the given parentheses string.

sample

()
1

</p>