Codeforces Round 1026 (Div. 2)
B
Down with Brackets
Codeforces
900
原题
← AC →
翻译中…

In 2077, robots decided to get rid of balanced bracket sequences once and for all!

翻译中…

A bracket sequence is called balanced if it can be constructed by the following formal grammar.

翻译中…
  1. The empty sequence $\varnothing$ is balanced.
  2. If the bracket sequence $A$ is balanced, then $\mathtt{(}A\mathtt{)}$ is also balanced.
  3. If the bracket sequences $A$ and $B$ are balanced, then the concatenated sequence $A B$ is also balanced.
翻译中…

You are the head of the department for combating balanced bracket sequences, and your main task is to determine which brackets you can destroy and which you cannot.

翻译中…

You are given a balanced bracket sequence represented by a string $s$, consisting of the characters ( and ). Since the robots' capabilities are not limitless, they can remove exactly one opening bracket and exactly one closing bracket from the string.

翻译中…

Your task is to determine whether the robots can delete such two brackets so that the string $s$ is no longer a balanced bracket sequence.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

Each test case consists of a single string $s$ ($2 \leq |s| \leq 2 \cdot 10^5$) — a sequence of the characters ( and ).

翻译中…

It is guaranteed that $s$ is a balanced bracket sequence.

翻译中…

It is also guaranteed that the sum of $|s|$ across all test cases does not exceed $2\cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output "YES" if the robots can make the string stop being a balanced bracket sequence, and "NO" otherwise.

翻译中…

You may output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

翻译中…

Note

翻译中…

In the first test case, it can be shown that the robots will not be able to break the correct bracket sequence.

翻译中…

In the second test case, one of the options for removing brackets is as follows:

翻译中…

$\texttt{(())}\color{red}{\texttt{(}}\texttt{)(}\color{red}{\texttt{)}} \rightarrow \texttt{(()))(}$, which is not a correct bracket sequence.

翻译中…

In the fourth test case, one of the options for removal is as follows:

翻译中…

$\texttt{(}\color{red}{\texttt{(}}\texttt{))((}\color{red}{\texttt{)}}\texttt{)}\rightarrow \texttt{())(()}$, which is not a correct bracket sequence.

翻译中…

样例

Input #1
4
(())
(())()()
()
(())(())
Output #1
NO
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
2110B
时间限制
1 s
内存限制
256 MB
标签
字符串

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