Missing Brackets
Alice typed a long formula into her calculator, but she only copied its round brackets into her
notes: a string s made of the characters ( and ). Some brackets got lost along the way, so the
string may not be balanced any more.
A string of brackets is balanced if every ( can be paired with a ) somewhere after it, and
every ) with a ( somewhere before it, with each bracket used in exactly one pair. For example,
(())() and the empty string are balanced, while )(, (() and ()) are not.
Alice may insert brackets anywhere in the string: at the start, at the end, or between any two characters. She cannot delete or move the brackets already there. What is the smallest number of brackets she must insert to make the string balanced?
Input
The first line contains n (1 ≤ n ≤ 2·10^5), the length of the string.
The second line contains the string s of exactly n characters, each ( or ).
Output
Print one integer: the minimum number of brackets to insert.
Notes
In the first example, (() needs one ) at the end to become (()).
In the second example, ())(() has as many ( as ), yet it is not balanced: the third character
) has no ( left to pair with, and the ( at position 4 has no ) after it. Inserting a (
before the third character and a ) at the end gives ()()(()), so the answer is 2.