Third word P58037


Statement
 

pdf   zip

You have a word, and you can change the order of its letters however you like. Of all the possible results, which would be the third, in alphabetical order?

Input

Input consists of several non-empty words ss, each with at most 10510^5 lowercase letters.

Output

For every ss, among all the possible reorderings of its letters, print the third in alphabetical order. If there is no such third word, print “NO”.

Public test cases
  • Input

    tca
    baba
    z
    

    Output

    cat
    abba
    NO
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++