This page is still under construction.

Parts of this page are still being built. What you see may change.

Palindrome

Time limit2sMemory limit128 MB

Summary
Find the palindromic substring that maximizes its length times its number of occurrences in the given string.
Level

Medium7 of 10

Topics
String matching, String
Solved
No attempts yet

Problem

You are given a string of lowercase letters. The appearance value of a substring is the number of times it occurs in the string multiplied by its length. Write a program that prints the largest appearance value among all palindrome substrings.

Input

The first line contains a string of lowercase letters (a-z). The length is at most 300,000.

Output

Print the largest appearance value among palindrome substrings on one line.

Hint

Let ∣s∣|s| denote the length of string ss. A substring is a non-empty string sisi+1…sjs_i s_{i+1} \ldots s_j with 1≤i≤j≤∣s∣1 \leq i \leq j \leq |s|. A palindrome reads the same from left to right and from right to left. A large appearance value can come from a short substring that appears many times or from a long palindrome that appears once.

Examples6

  1. Example 1

    Input
    abacaba
    
    Expected output
    7
    
  2. Example 2

    Input
    aaaaa
    
    Expected output
    9
    
  3. Example 3

    Input
    a
    
    Expected output
    1
    
  4. Example 4

    Input
    ab
    
    Expected output
    1
    
  5. Example 5

    Input
    zz
    
    Expected output
    2
    
  6. Example 6

    Input
    racecar
    
    Expected output
    7