Under construction

Still being built. Things may change

Star in Parentheses

Interview

Time limit2sMemory limit512 MB

Summary
Given balanced parentheses with one star, count the matching pairs that enclose the star's position.
Level

Easy3 of 10

Topics
Stack, String, Implementation
Solved
No attempts yet

Problem

You are given a string SS, 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 TT is balanced parentheses, concatenation of (, TT, 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 S_iS\_i be the ii-th character of a string SS. The pair of S_lS\_l and S_rS\_r (l<r)(l < r) is called a matching pair of parentheses if S_lS\_l is (, S_rS\_r 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.

S$S$

SS is balanced parentheses with exactly one * inserted somewhere. The length of SS is between 11 and 100100, inclusive.

Output

Print the answer in one line.

Examples5

  1. Example 1

    Input
    ((*)())
    
    Expected output
    2
    
  2. Example 2

    Input
    (*)
    
    Expected output
    1
    
  3. Example 3

    Input
    (()())*
    
    Expected output
    0
    
  4. Example 4

    Input
    ()*()
    
    Expected output
    0
    
  5. Example 5

    Input
    ((((((((((*))))))))))
    
    Expected output
    10