Powers of words P83564


Statement
 

pdf   zip

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”.

Public test cases
  • Input

    abba
    xyz
    ww
    oppoop
    aaaaaaaaiiii
    

    Output

    baba
    NO
    ww
    popopo
    iiaaaaiiaaaa
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++