cswork / OA打开练习工作台

AmazonOA #385

Maximize Repeated Substring Length

估计中等可在线判题

考点(AI 标注)字符串双指针滑窗

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.

输入格式

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 a single integer answer.

样例 1

输入:

a??a

输出:

4

样例 2

输入:

abc

输出:

0

样例 3

输入:

输出:

0

样例说明

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