#P1499B. Binary Removals
Binary Removals
No submission language available for this problem.
Description
You are given a string , consisting only of characters '0' or '1'. Let be the length of .
You are asked to choose some integer () and find a sequence of length such that:
- ;
- for all from to .
The characters at positions are removed, the remaining characters are concatenated without changing the order. So, in other words, the positions in the sequence should not be adjacent.
Let the resulting string be . is called sorted if for all from to .
Does there exist such a sequence that the resulting string is sorted?
The first line contains a single integer () — the number of testcases.
Then the descriptions of testcases follow.
The only line of each testcase contains a string (). Each character is either '0' or '1'.
For each testcase print "YES" if there exists a sequence such that removing the characters at positions and concatenating the parts without changing the order produces a sorted string.
Otherwise, print "NO".
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Input
The first line contains a single integer () — the number of testcases.
Then the descriptions of testcases follow.
The only line of each testcase contains a string (). Each character is either '0' or '1'.
Output
For each testcase print "YES" if there exists a sequence such that removing the characters at positions and concatenating the parts without changing the order produces a sorted string.
Otherwise, print "NO".
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Samples
Note
In the first testcase you can choose a sequence . Removing the underlined letters from "10101011011" will produce a string "0011111", which is sorted.
In the second and the third testcases the sequences are already sorted.
In the fourth testcase you can choose a sequence . "11", which is sorted.
In the fifth testcase there is no way to choose a sequence such that is sorted.