cswork / OAOpen practice workspace

MicrosoftOA #64

Str with Longest Len

Estimated MediumJudge-ready

Topics (AI-labelled)Strings

Find the length of the longest string that is both a proper prefix and a proper suffix of the given string. It must be shorter than the whole string, the prefix and suffix may overlap, and the empty string of length 0 is valid.

This site uses a standard input/output protocol.

Input

One line containing a lowercase string S of length 1..1000000.

Output

Output a single integer, the answer.

Example 1

Input:

abbabba

Output:

4

Example 2

Input:

codility

Output:

0

Example 3

Input:

aaaa

Output:

3

Example notes

Example 1: abba appears at both the start and the end, so the length is 4. Example 2: there is no non-empty common proper prefix and suffix, so 0. Example 3: aaa is allowed to overlap, so the length is 3.

Editorial

Loading solution…