#P1210. The Greatest Palindrome

    ID: 14204 Type: Default 1000ms 256MiB

The Greatest Palindrome

The Greatest Palindrome

Cows with access to infinite giant portable computers are said to produce the most marvelous palindromes in the world. Your task is to find this masterpiece: the longest palindrome produced by the cows.

You will be given an article as a string of no more than 20,000 characters. When determining if a substring is a palindrome, ignore punctuation and spaces, and only consider the letters A-Z and a-z (case‐insensitively). However, when you output your answer, you should output the substring exactly as it appears (i.e. preserving all punctuation and spaces).

The palindrome you need to find is the contiguous substring whose filtered form (i.e. after removing non-letter characters and ignoring case) is a palindrome and has the maximum number of letters. It is guaranteed that the longest palindrome’s filtered letter count does not exceed 2,000.

If there are multiple answers, output the one that appears first.

inputFormat

The input consists of a single string (possibly spanning multiple lines) representing the article. Its total length does not exceed 20,000 characters.

outputFormat

Output the longest contiguous substring from the input whose filtered version (removing all non-alphabet characters and ignoring case) is a palindrome. The output should preserve the original punctuation and spaces.

sample

Madam, I'm Adam
Madam, I'm Adam