#jag2017summerday3a. [jag2017summer_day3_a]Star in Parentheses
[jag2017summer_day3_a]Star in Parentheses
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 16px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
You are given a string , which is balanced parentheses with a star symbol *
inserted.
Any balanced parentheses can be constructed using the following rules:
- An empty string is balanced.
- Concatenation of two balanced parentheses is balanced.
- If is balanced parentheses, concatenation of
(
, , and)
in this order is balanced.
For example, ()()
and (()())
are balanced parentheses. )(
and )()(()
are not balanced parentheses.
Your task is to count how many matching pairs of parentheses surround the star.
Let be the -th character of a string . The pair of and is called a matching pair of parentheses if is (
, is )
and the surrounded string by them is balanced when ignoring a star symbol.
Input
The input consists of a single test case formatted as follows.
is balanced parentheses with exactly one *
inserted somewhere. The length of is between and , inclusive.
Output
Print the answer in one line.
Sample Input 1
((*)())
Output for Sample Input 1
2
Sample Input 2
(*)
Output for Sample Input 2
1
Sample Input 3
(()())*
Output for Sample Input 3
0
Sample Input 4
()*()
Output for Sample Input 4
0
Sample Input 5
((((((((((*))))))))))
Output for Sample Input 5
10
Sample Input 6
*
Output for Sample Input 6
0