#C13547. Longest Palindromic Substring

    ID: 43097 Type: Default 1000ms 256MiB

Longest Palindromic Substring

Longest Palindromic Substring

Given a string s, your task is to find the longest palindromic substring contained within it. A palindrome is a sequence that reads the same backward as forward. The palindrome may be of odd or even length.

Your solution should:

  • Return the longest palindromic substring. If there are multiple palindromic substrings of maximum length, any one of them is acceptable.
  • Return an empty string if the input string is empty or if no palindrome is found.
  • Handle incorrect input types by raising an error, though in the competition environment the input is guaranteed to be a string.

Note: If multiple valid answers exist, you may output any one of them.

inputFormat

The input is provided via standard input (stdin) as a single line containing the string s.

outputFormat

Output to standard output (stdout) the longest palindromic substring found in the input. In case of multiple possible answers, any valid palindrome is acceptable. If the string is empty or no valid palindrome exists, output an empty string.

## sample
babad
bab