Bobo has a very long sequence divided into n consecutive groups.
The i-th group consists of

copies of character

where

is either "`(`" or "`)`".
As the sequence may not be valid parentheses sequence, Bobo can change a character in the i-th group from "`(`" to "`)`" (and vice versa) with cost

.
He would like to know the minimum cost to transform the sequence into a valid one.
Note:
- An empty string is valid.
- If S is valid, (S) is valid.
- If U, V are valid, UV is valid.
输入描述:
The input contains zero or more test cases and is terminated by end-of-file. For each test case:
The first line contains an integer n.
The i-th of the following n lines contains
.
* 
* 
*
is even.
* 
* The sum of n does not exceed
.
输出描述:
For each case, output an integer which denotes the result.
示例1
输入
复制
4
1 ( 1
1 ( 2
1 ( 3
1 ) 4
2
500000000 ) 1000000000
500000000 ( 1000000000
备注:
For the first sample, Bobo should change only the character in the second group.
For the second sample, Bobo should change half of characters in both groups.