#C233. Minimum Moves to Balance Parentheses

    ID: 45634 Type: Default 1000ms 256MiB

Minimum Moves to Balance Parentheses

Minimum Moves to Balance Parentheses

You are given a string consisting solely of the characters '(' and ')'. Your task is to determine the minimum number of moves required to balance the string. In one move, you can either insert a parenthesis or remove an existing one. A balanced string is one where every opening parenthesis '(' has a corresponding closing parenthesis ')'.

The required number of moves can be computed using the formula \[ \text{moves} = \text{left\_unbalanced} + \text{right\_unbalanced} \] where left_unbalanced and right_unbalanced represent the count of unmatched '(' and ')' respectively.

For example, for the string "())(", the minimum number of moves is 2.

inputFormat

The input consists of a single line containing a non-empty string s made up of characters '(' and ')'.

outputFormat

Output a single integer representing the minimum number of moves required to balance the string.

## sample
())
1

</p>