CF1499B.Binary Removals

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Binary Removals

You are given a string ss, consisting only of characters '0' or '1'. Let s|s| be the length of ss.

You are asked to choose some integer kk (k>0k \gt 0) and find a sequence aa of length kk such that:

  • 1a1<a2<<aks1 \le a_1 \lt a_2 \lt \dots \lt a_k \le |s|;
  • ai1+1<aia_{i-1} + 1 \lt a_i for all ii from 22 to kk.

The characters at positions a1,a2,,aka_1, a_2, \dots, a_k are removed, the remaining characters are concatenated without changing the order. So, in other words, the positions in the sequence aa should not be adjacent.

Let the resulting string be ss'. ss' is called sorted if for all ii from 22 to s|s'| si1sis'_{i-1} \le s'_i.

Does there exist such a sequence aa that the resulting string ss' is sorted?

Input

The first line contains a single integer tt (1t10001 \le t \le 1000) — the number of testcases.

Then the descriptions of tt testcases follow.

The only line of each testcase contains a string ss (2s1002 \le |s| \le 100). Each character is either '0' or '1'.

Output

For each testcase print "YES" if there exists a sequence aa such that removing the characters at positions a1,a2,,aka_1, a_2, \dots, a_k 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).

Note

In the first testcase you can choose a sequence a=[1,3,6,9]a=[1,3,6,9]. 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 a=[3]a=[3]. s=s'= "11", which is sorted.

In the fifth testcase there is no way to choose a sequence aa such that ss' is sorted.

Samples

5
10101011011
0000
11111
110
1100
YES
YES
YES
YES
NO

在线编程 IDE

建议全屏模式获得最佳体验