#K9356. Minimum Moves to Balance Parentheses

    ID: 38446 Type: Default 1000ms 256MiB

Minimum Moves to Balance Parentheses

Minimum Moves to Balance Parentheses

You are given a string s consisting solely of the characters '(' and ')'. Your task is to determine the minimum number of moves required to make the parentheses balanced.

A move consists of taking a parenthesis and relocating it to any position in the string. The final balanced string should have each opening parenthesis matched with a corresponding closing parenthesis.

The number of moves needed is equal to the sum of unmatched '(' and unmatched ')'. In mathematical term, if left_balance is the number of unmatched '(' and right_balance is the number of unmatched ')', then the answer is given by:

$$\text{moves} = left\_balance + right\_balance$$

Read the input from standard input and output the result to standard output.

inputFormat

The input consists of a single line containing the string s composed only of the characters '(' and ')'.

outputFormat

Output a single integer — the minimum number of moves required to balance the parentheses.

## sample
()
0

</p>