#C11705. Palindromic Substrings

    ID: 41051 Type: Default 1000ms 256MiB

Palindromic Substrings

Palindromic Substrings

Given a string \( s \), find all unique palindromic substrings. A substring \( s[i:j+1] \) is considered a palindrome if it satisfies \( s[i:j+1] = \text{reverse}(s[i:j+1]) \), that is, it reads the same forwards and backwards. The output substrings must be sorted in ascending order first by their length and then lexicographically if they are of the same length.

For example, if \( s = "ababa" \), the palindromic substrings are: a, b, aba, bab, ababa (after sorting, printed as a b aba bab ababa).

inputFormat

The input consists of a single line containing the string \( s \). You may assume that \( s \) is non-empty and contains only lowercase English letters.

outputFormat

Output the unique palindromic substrings of \( s \) sorted by their length (and lexicographically for substrings with equal length) as a single line of space-separated values.

## sample
ababa
a b aba bab ababa