#C10658. Minimum Insertions to Make Valid Parentheses Sequence

    ID: 39887 Type: Default 1000ms 256MiB

Minimum Insertions to Make Valid Parentheses Sequence

Minimum Insertions to Make Valid Parentheses Sequence

You are given a string S consisting solely of characters '(' and ')'. The task is to determine the minimum number of insertions required to make the bracket sequence valid.

A valid bracket sequence is one in which every opening bracket '(' has a matching closing bracket ')'. More formally, if we denote the number of unmatched opening brackets by left_balance and unmatched closing brackets by right_balance, then the minimum number of insertions needed is given by:

$$\text{insertions} = \text{left_balance} + \text{right_balance} $$

Implement a solution that reads the input string from stdin and prints the answer to stdout.

inputFormat

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

outputFormat

Print a single integer representing the minimum number of insertions required to make the bracket sequence valid.

## sample
()
0