Powers of words

Let tt be a string and kk be a natural number. We define tkt^k as the result of concatening tt exactly kk times. For instance, the third power of “abbc” is “abbcabbcabbc”.

Given a string ss, rearrange its letters so that the result is the kk-th power of some string tt, where k2k \ge 2.

Input

Input consists of several strings, each with between 2 and 10510^5 lowercase letters.

Output

For each given string, print a way to rearrange its letters so that the result is tkt^k, for some string tt and some k2k \ge 2. If there is more than one solution, choose the alphabetically largest. If there is no solution, print “NO”.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T12:00:15.974Z

© Jutge.org, 2006–2026.
https://jutge.org