You are on page 1of 2

5/21/22, 7:03 PM Problem - E - Codeforces

alfa_flex
| Logout

  HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP  
 
 

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

  Mashup  
E. Pair Matching Contest is running
time limit per test: 2 s.
04:56:55
memory limit per test: 256 MB
input: standard input Contestant
output: standard output

You have an array consisting of n bracket sequences. You pick a pair of bracket sequences. A
pair is called good if you concatenate elements of this pair and they form a regular bracket   → Submit?  
sequence. You want to find out what is the maximum number of good pairs you can make
such that each bracket sequence occurs in at most one pair.
Language: GNU G++17 7.3.0
A regular bracket sequence is a bracket sequence that can be transformed into a correct
Choose
arithmetic expression by inserting characters "1" and "+" between the original characters of the Choose File No file chosen
file:
sequence
Submit

Input
The first line contains one integer n (1 ≤ n ≤ 10
5
) — the number of bracket sequences.

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

The sum of lengths of all bracket sequences in the input is at most 5 × 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 that can be made, adhering to the
conditions in the statement.

Examples
input Copy

)())

((

((

output Copy

input Copy

((

(((

(())

output Copy

input Copy

(())

()

output Copy

https://codeforces.com/gym/382540/problem/E 1/2
5/21/22, 7:03 PM Problem - E - Codeforces

Codeforces (c) Copyright 2010-2022 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: May/21/2022 19:03:03UTC+5.5 (k3).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

https://codeforces.com/gym/382540/problem/E 2/2

You might also like