#abc375d. D - ABA

D - ABA

Score : 400400 points

问题陈述

给定一个由大写英文字母组成的字符串 SS

找出满足以下两个条件的整数三元组 (i,j,k)(i, j, k) 的数量:

  • 1i<j<kS1 \leq i < j < k \leq |S|
  • 按照 SiS_iSjS_jSkS_k 的顺序连接形成的三字符长度字符串是一个回文。

这里,S|S| 表示 SS 的长度,SxS_x 表示 SS 的第 xx 个字符。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given a string SS consisting of uppercase English letters.

Find the number of integer triples (i,j,k)(i, j, k) satisfying both of the following conditions:

  • 1i<j<kS1 \leq i < j < k \leq |S|
  • The length-33 string formed by concatenating SiS_i, SjS_j, and SkS_k in this order is a palindrome.

Here, S|S| denotes the length of SS, and SxS_x denotes the xx-th character of SS.

Constraints

  • SS is a string of length between 11 and 2×1052 \times 10^5, inclusive, consisting of uppercase English letters.

Input

The input is given from Standard Input in the following format:

SS

Output

Print the answer.

Sample Input 1

ABCACC

Sample Output 1

5

The triples satisfying the conditions are $(i, j, k) = (1, 2, 4), (1, 3, 4), (3, 4, 5), (3, 4, 6), (3, 5, 6)$.

Sample Input 2

OOOOOOOO

Sample Output 2

56

Sample Input 3

XYYXYYXYXXX

Sample Output 3

75