atcoder#ABC283D. [ABC283D] Scope
[ABC283D] Scope
Score : points
Problem Statement
A string consisting of lowercase English letters, (
, and )
is said to be a good string if you can make it an empty string by the following procedure:
- First, remove all lowercase English letters.
- Then, repeatedly remove consecutive
()
while possible.
For example, ((a)ba)
is a good string, because removing all lowercase English letters yields (())
, from which we can remove consecutive ()
at the -nd and -rd characters to obtain ()
, which in turn ends up in an empty string.
You are given a good string . We denote by the -th character of .
For each lowercase English letter a
, b
, , and z
, we have a ball with the letter written on it.
Additionally, we have an empty box.
For each in this order, Takahashi performs the following operation unless he faints.
- If is a lowercase English letter, put the ball with the letter written on it into the box. If the ball is already in the box, he faints.
- If is
(
, do nothing. - If is
)
, take the maximum integer less than such that the -th through -th characters of form a good string. (We can prove that such an integer always exists.) Take out from the box all the balls that he has put in the -th through -th operations.
Determine if Takahashi can complete the sequence of operations without fainting.
Constraints
- is a good string.
Input
The input is given from Standard Input in the following format:
Output
Print Yes
if he can complete the sequence of operations without fainting; print No
otherwise.
((a)ba)
Yes
For , he does nothing.
For , he does nothing.
For , he puts the ball with a
written on it into the box.
For , is the maximum integer less than such that the -th through -th characters of form a good string, so he takes out the ball with a
written on it from the box.
For , he puts the ball with b
written on it into the box.
For , he puts the ball with a
written on it into the box.
For , is the maximum integer less than such that the -th through -th characters of form a good string, so he takes out the ball with a
written on it, and another with b
, from the box.
Therefore, the answer to this case is Yes
.
(a(ba))
No
For , he does nothing.
For , he puts the ball with a
written on it into the box.
For , he does nothing.
For , he puts the ball with b
written on it into the box.
For , the ball with a
written on it is already in the box, so he faints, aborting the sequence of operations.
Therefore, the answer to this case is No
.
(((())))
Yes
abca
No