#C12759. Longest Palindromic Substring

    ID: 42221 Type: Default 1000ms 256MiB

Longest Palindromic Substring

Longest Palindromic Substring

Given a string, your task is to find the longest palindromic substring in it after removing all non-alphanumeric characters and converting the remaining characters to lowercase. A palindrome is a string that reads the same backward as forward. Formally, a string \(s\) is a palindrome if \(s = s^R\), where \(s^R\) denotes its reversal.

You must consider both cases of palindrome lengths: odd-length and even-length. The recommended approach is to use the center expansion technique, where for each character (or pair of consecutive characters) in the processed string, you expand outwards to check for palindromic properties.

The input is given via standard input (stdin), and the result should be printed to standard output (stdout).

inputFormat

The input consists of a single line containing a string \(s\). This string may include alphanumeric characters, punctuation, and spaces.

outputFormat

Output the longest palindromic substring obtained after removing any non-alphanumeric characters and converting the string to lowercase. The output should be printed on a single line.

## sample
A man, a plan, a canal, Panama
amanaplanacanalpanama