#C13382. Minimum Parentheses Correction

    ID: 42914 Type: Default 1000ms 256MiB

Minimum Parentheses Correction

Minimum Parentheses Correction

You are given a string s consisting solely of the characters ('). The goal is to determine the minimum number of insertions and deletions required to make the parentheses string valid. A valid parentheses string is defined as:

  • An empty string is valid.
  • If A is valid, then (A) is valid.
  • If A and B are valid, then the concatenation AB is valid.

Mathematically, if we denote balance(s) as the net difference between the number of opening and closing parentheses while scanning the string, the minimum number of operations required can be expressed as:

$$\text{operations} = \text{max}(\text{unmatched_open}, 0) + \text{max}(\text{unmatched_close}, 0) $$

Your task is to compute this number.

inputFormat

The input is read from standard input (stdin). It consists of a single line containing the string s (which only contains characters '(' and ')').

outputFormat

Output a single integer representing the minimum number of insertions and deletions needed to make the string valid. The output should be written to standard output (stdout).

## sample
0