Smallest palindrome

Implement a program that, for each given word, prints the smallest
palindrome (in lexicographical order) that can be formed using exactly
all its letters once. The given words as well as the formed palindromes
do not necessary have a meaning. If, for any word, is not possible to
form any palindrome, it must be indicated.

Input

The input consists of a number k ≤ 1000 of words in a line, followed by
k lines, each one with a none empty word. The words are exclusively
formed by at most 500 lowercase letters.

Your program must solve an input as the described one in less than 1
second.

Output

For each word, your program must print a line with the smallest
palindrome that can be formed using exactly once all the letters of the
word. If it is not possible to form any palindrome, it must print
"NO PALINDROME".

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:13:05.774Z

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