Parentheses
题号:NC52866
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
Special Judge, 64bit IO Format: %lld

题目描述

Bobo has a very long sequence divided into n consecutive groups.
The i-th group consists of l_i copies of character c_i where c_i 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 d_i.
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 l_i, c_i, d_i.

*
*
* 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

输出

复制
2
500000000000000000

备注:

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.