LogiQuest

204. Minimum Brackets to Add

MediumCounting

Print the minimum number of ( or ) to insert to make the bracket string valid.

Input format

A single line of ( and ).

Output format

The minimum insertions.

Example 1

Input

())

Output

1

Example 2

Input

(((

Output

3

Constraints

1 ≤ length ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…