#K67942. Partition String into Powers of Two

    ID: 32754 Type: Default 1000ms 256MiB

Partition String into Powers of Two

Partition String into Powers of Two

You are given a string S consisting of digits. Your task is to determine if it is possible to partition S into one or more contiguous segments, such that each segment, when interpreted as an integer (without leading zeros), is a power of 2. A valid segment should not contain extra leading zeros (e.g. "0032" is invalid), and each number must be greater than 0.

Formally, for any partition of S into substrings S = S1S2...Sk (for k ≥ 1), each substring Si must satisfy:

  • Si does not have a leading zero unless it is exactly "0".
  • The integer value of Si is a power of 2, i.e. there exists an integer m such that Si = 2m.

Output "YES" if such a partition exists, otherwise output "NO".

Note: The input will consist of multiple test cases.

inputFormat

The first line contains a single integer T, the number of test cases. Each of the next T lines contains a string S consisting only of digits.

outputFormat

For each test case, output a single line: "YES" if S can be partitioned into segments each forming a power of 2, or "NO" otherwise.

## sample
2
2048
1234
YES

NO

</p>