A valid bracket sequence consisting of (
and )
is defined as follows:
- An empty sequence is valid.
- If
is a valid bracket sequence, then(
)
is a valid bracket sequence. - If
and are valid bracket sequences, then the concatenation of and , , is a valid bracket sequence.
For example, (())
, ()()
, and (()())()
are all valid bracket sequences, while (
and ())
are invalid bracket sequences.
A professor gave you a sequence of brackets of length (
or )
brackets into the interval
For example:
Let the original string be xxxxxxx
.
Then, xxxxx((((((xx
or xxxxxxx)))))
are all valid insertions.
If it is possible, output YES
; otherwise, output NO
.
Constraints
For all subtasks:
Subtask 1 [20%]
Subtask 2 [80%]
No additional constraints.
Input Specification
The first line consists of two integers
The next line consists of a bracket sequence of length
The following
Output Specification
Output YES
and NO
on
Sample Input
8 8
(())()((
5 6
2 7
6 7
4 5
5 7
7 8
3 4
6 7
Sample Output
YES
NO
NO
NO
YES
YES
YES
NO
Comments