Hello 2019
C
Yuhao and a Parenthesis
Codeforces
1400
原题
← BD →
翻译中…

One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences.

翻译中…

A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket sequence if it's possible to obtain a correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, the sequences "(())()", "()" and "(()(()))" are correct, while the bracket sequences ")(", "(()" and "(()))(" are not correct.

翻译中…

Yuhao found this problem too simple for him so he decided to make the problem harder. You are given many (not necessarily correct) bracket sequences. The task is to connect some of them into ordered pairs so that each bracket sequence occurs in at most one pair and the concatenation of the bracket sequences in each pair is a correct bracket sequence. The goal is to create as many pairs as possible.

翻译中…

This problem unfortunately turned out to be too difficult for Yuhao. Can you help him and solve it?

翻译中…

Input

翻译中…

The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of bracket sequences.

翻译中…

Each of the following $n$ lines contains one bracket sequence — a non-empty string which consists only of characters "(" and ")".

翻译中…

The sum of lengths of all bracket sequences in the input is at most $5 \cdot 10^5$.

翻译中…

Note that a bracket sequence may appear in the input multiple times. In this case, you can use each copy of the sequence separately. Also note that the order in which strings appear in the input doesn't matter.

翻译中…

Output

翻译中…

Print a single integer — the maximum number of pairs which can be made, adhering to the conditions in the statement.

翻译中…

Note

翻译中…

In the first example, it's optimal to construct two pairs: "((     )())" and "(     )".

翻译中…

样例

Input #1
7
)())
)
((
((
(
)
)
Output #1
2
InputCopy OutputCopy
Input #2
4
(
((
(((
(())
Output #2
0
InputCopy OutputCopy
Input #3
2
(())
()
Output #3
1
InputCopy OutputCopy
题目信息
题号
1097C
所属比赛
时间限制
2 s
内存限制
256 MB
标签
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。