Under construction

Still being built. Things may change

Cipher Key

Time limit2sMemory limit1024 MB

Summary
Given a lowercase string s of length up to 500000, find the maximum of |t| + f(t)^2 over all substrings t, where f(t) is the longest proper border of t.
Level

Hard8 of 10

Topics
String, String matching
Solved
No attempts yet

Statement

Hercule Poirot is currently exposing an international criminal syndicate that smuggles works of art. Police working with Poirot intercepted an encrypted letter with the place and time of an upcoming deal, which the head of the syndicate will attend. To stop the deal and arrest the head, the intercepted letter must be decrypted.

Hercule knows that the key to the cipher is computed from a string ss. For a string ww, let f(w)f(w) be the length of the longest suffix of ww that is not equal to ww and is also a prefix of ww. For example, f(‘abc‘)=0f(`abc`) = 0, f(‘abab‘)=2f(`abab`) = 2, f(‘aaa‘)=2f(`aaa`) = 2. The key is the maximum of ∣t∣+f(t)2|t| + f(t)^2 over all substrings tt of ss. Help Hercule compute the key.

Input

The only line contains the string ss, consisting of lowercase Latin letters (1≤∣s∣≤5000001 \le |s| \le 500000).

Output

Print a single integer, the key to the cipher.

Examples1

  1. Example 1

    Input
    ababaab
    
    Expected output
    14