Palinilap

A lowercase string may be modified at exactly one position or left alone; find the maximum number of palindromic substrings achievable.

Medium6StringDynamic programmingBrute forceNo attempts yetTime limit1sMemory limit512 MB

Problem

A palindrome is a word that reads the same forwards and backwards. For example, a, abba and anavolimilovana are palindromes.

A sample is a string of one or more lower case letters of the English alphabet. The weight of a sample is the number of its substrings that are palindromes, and a word that appears at several positions is counted once per occurrence.

More precisely, let ww be a sample of length nn. The word wa,bw_{a,b} consists of all characters from position aa to position bb of ww. The weight of ww is the number of pairs of integers (a,b)(a, b) with 1abn1 \le a \le b \le n such that wa,bw_{a,b} is a palindrome.

You are given the sample ww. You may leave it unchanged, or you may pick exactly one position and change the letter at that position to any letter. Find the largest weight you can obtain this way.

Input

The first line contains the sample ww. It consists of lower case letters of the English alphabet only, and its length is between 1 and 1000.

Output

Print the largest weight you can obtain.

Hint

For the input aaaa, every substring is already a palindrome, so it is best left unchanged.

For the input baccb, changing the second letter to c gives bcccb, whose weight is 9.