1830.Palindrome Degree

Time Limit: 1s Memory Limit: 256MB

String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length 1830_1.png are (k-1)-palindromes. By definition, any string (even empty) is 0-palindrome.

Let's call the palindrome degree of string s such a maximum number k, for which s is k-palindrome. For example, "abaaba" has degree equals to 3.

You are given a string. Your task is to find the sum of the palindrome degrees of all its prefixes.

Input Format(From the terminal/stdin)

The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5 \cdot 106. The string is case-sensitive.

Output Format(To the terminal/stdout)

Output the only number - the sum of the polindrome degrees of all the string's prefixes.

Sample Input 1

Copy
a2A
   \n

Sample Output 1

Copy
1
 \n

Sample Input 2

Copy
abacaba
       \n

Sample Output 2

Copy
6
 \n

Submit

请先 登录

© 2025 FAQs