Score : 600 points
A bracket sequence is a string that is one of the following:
(
, A, and )
in this order, for some bracket sequence A ;Given are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?
(
and )
.Input is given from Standard Input in the following format:
N S_1 : S_N
If a bracket sequence can be formed by concatenating all the N strings in some order, print Yes
; otherwise, print No
.
2 ) (()
Yes
Concatenating (()
and )
in this order forms a bracket sequence.
2 )( ()
No
4 ((())) (((((( )))))) ()()()
Yes
3 ((( ) )
No