#P3804. Maximum Substring Occurrence Product

    ID: 17054 Type: Default 1000ms 256MiB

Maximum Substring Occurrence Product

Maximum Substring Occurrence Product

You are given a string \(S\) consisting only of lowercase letters. Your task is to find the maximum value of \(\text{occurrence} \times \text{length}\) over all substrings of \(S\) that appear at least twice (i.e. their occurrence count is not equal to 1).

Formally, for any substring \(t\) of \(S\) such that its occurrence count \(c_t \neq 1\), consider the product: \[ P(t) = c_t \times |t| \] and find the maximum value among all such substrings. If no substring appears at least twice, output 0.

Note: Substrings are continuous segments of \(S\). The answer is defined to be 0 if there is no substring with an occurrence count greater than 1.

inputFormat

The input consists of a single line containing the string \(S\) (with only lowercase letters).

outputFormat

Output a single integer, which is the maximum \(\text{occurrence} \times \text{length}\) value among all substrings that appear at least twice. If no substring qualifies, output 0.

sample

abc
0