#C2225. Longest Palindromic Substring with Preprocessing

    ID: 45518 Type: Default 1000ms 256MiB

Longest Palindromic Substring with Preprocessing

Longest Palindromic Substring with Preprocessing

You are given a string and asked to find the longest palindromic substring after preprocessing the input. The preprocessing step requires you to remove all non-alphanumeric characters and convert all letters to lowercase.

In other words, given an input string \(s\), you must first transform \(s\) to \(s'\) by keeping only the characters \(c\) that satisfy \(c \in [0-9a-zA-Z]\) and converting all alphabetic characters to lowercase. Then, compute the longest substring of \(s'\) that is a palindrome.

If there are multiple substrings of maximum length, return the one found first.

Note: A palindrome is a string that reads the same backward as forward.

inputFormat

The input consists of a single string which may contain spaces, punctuation, and mixed-case letters. All input is provided through standard input (stdin).

outputFormat

Output the longest palindromic substring found in the preprocessed string. The answer should be printed to standard output (stdout).## sample

babad
bab