Milhouse needs to solve a school assignment by tomorrow and requires your help. Here is the task:
You are given a string consisting of parentheses. You must turn it into a well-formed string by inserting as few parentheses as possible, at any position (you cannot delete or modify any of the existing parentheses).
A string of parentheses is considered well-formed if it satisfies the following conditions:
The empty string is well-formed.
If is a well-formed string, then is also well-formed.
If and are well-formed strings, their concatenation is well-formed.
For example, "(()())", "" and "(())()" are well-formed, while "())(", "()(" and ")" are not.
The input consists of a string of parentheses with length from to characters inclusive.
Output the minimum number of parentheses that must be inserted to make the given string well-formed.
Example 1