P1210 [USACO1.3] Longest Palindrome Calf Flac

Description

It is said that if you give infinitely many cows and infinitely many giant portable computers (with very large keyboards), the cows will create the best palindrome in the world. Your job is to find this marvel (the finest palindrome) produced by the cows. When searching for the palindrome, ignore punctuation and spaces (but keep them so they can be printed in the answer). Only consider the letters ${\tt A}\sim {\tt Z}$ and ${\tt a}\sim {\tt z}$. The text in which you must find the longest palindrome is a string of at most $20{,}000$ characters. We guarantee that the longest palindrome will not exceed $2{,}000$ characters (before removing punctuation and spaces).

Input Format

The input file will not exceed $20{,}000$ characters. This file may have one or more lines, but each line will not exceed $80$ characters (excluding the final newline).

Output Format

The first line should contain the length of the longest palindrome found. The next line or lines should contain this palindrome in its original text (without removing punctuation and spaces), printed across one or more lines (if the palindrome contains newline characters). If multiple palindromes have the same maximal length, output the one that appears earliest.

Explanation/Hint

The problem translation comes from NOCOW. USACO Training Section 1.3. Translated by ChatGPT 5