#icpc2014springe. [icpc2014spring_e]Parentheses
[icpc2014spring_e]Parentheses
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
You are given strings $\\mathit{str}\_1, \\mathit{str}\_2, \\ldots, \\mathit{str}\_n$, each consisting of (
and )
. The objective is to determine whether it is possible to permute the strings so that the concatenation of the strings represents a valid string.
Validity of strings are defined as follows:
-
The empty string is valid.
-
If and are valid, then the concatenation of and is valid.
-
If is valid, then the string obtained by putting in a pair of matching parentheses is valid.
-
Any other string is not valid.
For example, "()()" and "(())" are valid, while "())" and "((()" are not valid.
Input
The first line of the input contains an integer (), representing the number of strings. Then lines follow, each of which contains (). All characters in are (
or )
.
Output
Output a line with "Yes" (without quotes) if you can make a valid string, or "No" otherwise.
Sample Input 1
3
()(()((
))()()(()
)())(())```
### Output for the Sample Input 1
```plain
Yes```
* * *
### Sample Input 2
```plain
2
))()((
))((())(```
### Output for the Sample Input 2
```plain
No```
* * *
### Source Name
[Japan Alumni Group Spring Contest 2014](http://acm-icpc.aitea.net/index.php?2013%2FPractice%2F%BD%D5%A5%B3%A5%F3%A5%C6%A5%B9%A5%C8%2F%B0%C6%C6%E2)
* * *