Problems > Canonical Palindrome

Canonical Palindrome

Difficulty: 1300 3000 ms 128 MB

strings

Rearrange the characters of S into a palindrome, or print NO SOLUTION. To make the answer unique, output the palindrome whose first half is SORTED alphabetically (the odd-count character, if any, goes in the middle).

Input: one line with a lowercase string.

Output: the canonical palindrome, or NO SOLUTION.

Constraints:

  • 1 ≤ |S| ≤ 105

Sample Tests

Input 1
aabbc
Output 1
abcba
Input 2
aabbcd
Output 2
NO SOLUTION

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.