题目描述
Problem Description
The Tenka1 Magic Power Plant is a power plant that can generate electricity using a mysterious magic.
The fuel used for magic power generation is a string $ S $ consisting of ( and ), and the length of $ S $ is even.
By rewriting this string into a balanced string using the Tenka1 Word Processor, the magic power generation is successful.
A balanced string is defined as follows:
()is a balanced string.- If
Tis a balanced string, then(T)is also a balanced string. - If
TandUare balanced strings, thenTUis also a balanced string.
The Tenka1 Word Processor has the following four operations:
Initially, the cursor points to the first character of $ S $.
- Move the cursor to the right (it does not move if the cursor is already at the end).
- Move the cursor to the left (it does not move if the cursor is already at the beginning).
- If the character pointed by the cursor is
(, change it to). - If the character pointed by the cursor is
), change it to(.
For example, if $ S $ is the following string:
```
())(()))
By performing operations 1 and 4, we can change it to:
```
(()(()))
which is a balanced string.
Fude-kun, the responsible person at the power plant, wants to rewrite the string into a balanced string with the fewest operations possible.
Given $ S $, find the minimum number of operations required to rewrite it into a balanced string.
Input Format
The input is given from the standard input in the following format:
$ S $
Output Format
Output the minimum number of operations required to rewrite the string into a balanced string. End the output with a newline.
Sample Input and Output
Sample Input #1
())(()))
Sample Output #1
2
Sample Input #2
((((
Sample Output #2
5
Sample Input #3
)))(((
Sample Output #3
9
Notes/Hints
Constraints
- The length of $ S $, $ |S| $, is even.
- $2 \leq |S| \leq 100$
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分