cswork / OAOpen practice workspace

AmazonOA #385

Maximize Repeated Substring Length

Estimated MediumJudge-ready

Topics (AI-labelled)StringsTwo Pointers

You are given a string of lowercase letters and question marks; each question mark can be independently replaced with any lowercase letter. Find the maximum even length of a contiguous substring whose first and second halves are identical; the two halves must be adjacent.

Input

A single line containing the string. The original gives no length bound; this site adds 0≤length≤5000, with characters a..z or ?. Output 0 for an empty string or when no non-empty valid substring exists.

Output

Output a single integer answer.

Example 1

Input:

a??a

Output:

4

Example 2

Input:

abc

Output:

0

Example 3

Input:

Output:

0

Example notes

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

Editorial

Loading solution…