#P5799. [SEERC 2019] Cycle String?

[SEERC 2019] Cycle String?

Description

The Archmage gave Alice and Bob a cyclic string of length 2n2 \cdot n. In this cyclic string, there are no repeated substrings of length nn. In a cyclic string, the character si+1s_{i+1} comes after sis_i, and s1s_1 comes after s2ns_{2n}.

Unfortunately, the devil scrambled the order of the characters in the string. Help Alice and Bob restore the string to an original string that satisfies the requirement above.

Input Format

The first line contains a string ss of length 2n (22n1 000 000)2 \cdot n \ (2 \leq 2 \cdot n \leq 1 \ 000 \ 000). The string contains only lowercase letters.

Output Format

If the string can be restored to a string that satisfies the requirement, output NO in the first line. If it cannot be restored, output YES in the first line.

If a solution exists, output the restored string in the second line. If there are multiple solutions, output any one.

cbbabcacbb
YES
abbabcbccb
aa
NO
afedbc
YES
afedbc

Hint

In the first sample, the substrings in the restored string are: abbab, bbabc, babcb, abcbc, bcbcc, cbccb, bccba, ccbab, babba.

Note that in the first sample output, there are no repeated substrings, but there are other outputs that also satisfy the requirement. Therefore, the answer is not unique, and the sample only provides one valid output.

In the second sample, it is impossible to restore the string to an original string that satisfies the requirement.

In the third sample, no operation is needed because the requirement is already satisfied.

Translated by ChatGPT 5