Problem list
Log in
#coci00400 · COI 2016

Palinilap

Diamond IV 1.0 s 256 MB

A palindrome is a word that reads the same backwards as forwards. For example, “a”, “abba” and “anavolimilovana” are palindromes A sample is a string of one or more lower case letters of the English alphabet, and the weight of a sample is the number of its substrings (words) that are palindromes, counting each word occurrence separately. More precisely, let $w$ be a sample of length $n$. The word wa,b is obtained by taking all characters from position $a$ to position $b$ in sample $w$. The weight of sample $w$ is defined as the number of different pairs of integers $a$, $b$ ($1 \le a \le b \le n$) such that the word $w_{a,b}$ is a palindrome. You are given the sample $w$. It can either be left unchanged, or exactly one position can be chosen and the letter on that position arbitrarily changed. Find the maximal possible sample weight that can be obtained as described above.

Input

The first line of input contains the given sample $w$ – a string of lower case letters of the English alphabet.

Output

You must output the required maximal possible weight.

Constraints

Let $n$ be the length of the given sample. Subtask Score Limitations 1 17 $1 \le n \le 100$ 2 37 $101 \le n \le 5,000$ 3 46 $5001 \le n \le 100,000$

Example 1

Input
aaaa
Output
10

Example 2

Input
baccb
Output
9

Example 3

Input
slavko
Output
7
Source
COI 2016
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code