cswork / OAOpen practice workspace

CiscoOA #29

Longest Palindromic Substring

Estimated MediumJudge-ready

Topics (AI-labelled)PalindromesTwo Pointers

Return a palindromic contiguous substring of maximum length from the original string. If there are several longest answers, return any one of them; the lexicographically smallest or the earliest one must not be additionally required. A single character is also a palindrome.

Input

One line containing a string s of ASCII English letters or digits. The original bound 1≤|s|≤1000 is kept, and the string is case-sensitive.

Output

Output any one longest palindromic substring, optionally followed by one terminating newline; do not output quotes or explanatory text.

Example 1

Input:

babad

Output:

aba

Example 2

Input:

cbbd

Output:

bb

Example 3

Input:

7

Output:

7

Example notes

The outputs of the three public examples are, in order: aba; bb; 7. Verified by independent enumeration or direct simulation.

Editorial

Loading solution…