C. Palindrome Automata——回文自动机

    传统题 2000ms 512MiB

Palindrome Automata——回文自动机

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Statement

For a string SS, Timothy defines it as a palindrome if and only if every character index ii in the string SS of length xx satisfies S[i]=S[x1i]S[i]=S[x-1-i]. For example, abcba\tt abcba is a palindrome because S[0]=S[4],S[1]=S[3],S[2]=S[2]S[0]=S[4], S[1]=S[3], S[2]=S[2], while abcca\tt abcca is not.

Timothy now has a string SS and wants to divide it into several segments of length 1,2,3,and1, 2, 3, and \dots. Specifically, he will first take the first character and make it S1S_1, then take the 2nd,3rd2nd, 3rd characters and make it S2S_2, then take the 4th,5th,6th4th, 5th, 6th characters and make it S3S_3, and so on... Finally, if there are any extra characters, they will be treated as separate segments.

For example, the string aaababcaacd\tt aaababcaacd will be divided into the following five strings:

  • S1=aS_1=\tt a;
  • S2=aaS_2=\tt aa;
  • S3=babS_3=\tt bab;
  • S4=caacS_4=\tt caac;
  • S5=dS_5=\tt d;

The 55 strings split from the string aaababcaacd\tt aaababcaacd are all palindromes.

Timothy wants to know, for the input string SS, how many of the split strings are palindromes?

Input

Input a line, a string SS. Its length xx satisfies 1x1061 \leq x \leq 10^6, and the string contains only English lowercase letters

Output

Output an integer representing the answer.

Samples

aaababcaacd
5
abacdcaaba
2

Notes

For the first group of examples, they have been described in the question;

For the 22-nd group of examples, S1=aS_1=\tt a, S2=baS_2=\tt ba, S3=cdcS_3=\tt cdc, S4=aabaS_4=\tt aaba, where S1S_1 and S3S_3 are palindrome strings.

2025 JSUT Collegiate Programming Contest 江苏理工学院新生赛-同步赛

未参加
状态
已结束
规则
ACM/ICPC
题目
15
开始于
2025-11-8 12:00
结束于
2025-11-8 17:00
持续时间
5 小时
主持人
参赛人数
15