CF BUDDY
← Problems·

1951E · No Palindromes

2000 · brute force, constructive algorithms, divide and conquer

Problem: You are given a string ss consisting of lowercase Latin characters. You need to partition^\dagger this string into some substrings, such that each substring is not a palindrome^\ddagger.

^\dagger A partition of a string ss is an ordered sequence of some kk strings t1,t2,,tkt_1, t_2, \ldots, t_k, such that t1+t2++tk=st_1 + t_2 + \ldots + t_k = s, where ++ here represents the concatenation operation.

^\ddagger A string ss is considered a palindrome if it reads the same backwards as forwards. For example, racecar\mathtt{racecar}, abccba\mathtt{abccba}, and a\mathtt{a} are palindromes, but ab\mathtt{ab}, dokibird\mathtt{dokibird}, and kurosanji\mathtt{kurosanji} are not.

Input Format: Each test contains multiple test cases. The first line contains an integer tt (1t1041 \le t \le 10^4) — the number of test cases.

Each test case contains a string ss consisting of lowercase Latin characters (1s1061 \le |s| \le 10^6).

It is guaranteed that the sum of s|s| over all test cases does not exceed 10610^6.

Output Format: For each test case, print on one line "YES" if there exists a partition of ss whose parts are not palindromes, or "NO" if there is no such partition.

If the answer is "YES", on the second line, print an integer kk — the number of parts that ss needs to be partitioned to such that each part is not a palindrome. On the third line, print kk strings t1,t2,,tkt_1, t_2, \ldots, t_k representing such a partition. If there are multiple such partitions, print any of them.

Note: In the first test case, since sinktheyacht\mathtt{sinktheyacht} is already non-palindrome, the partition [sinktheyacht][\mathtt{sinktheyacht}] is valid.

In the second test case, as any substring of the string ss is palindrome, there are no valid partitions.

In the third test case, another valid partition is [uw,uo,wou,wu][\mathtt{uw},\mathtt{uo}, \mathtt{wou}, \mathtt{wu}].

Sample Cases

Case 1

Input

3
sinktheyacht
lllllllll
uwuowouwu

Output

YES
1
sinktheyacht
NO
YES
3
uw uow ouwu

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback