模板
# include <bits/stdc++.h>
const int MAXN = 300005 ;
const int N = 26*2 ;
int f(char c) {
if ('a' <= c && c <= 'z') return c - 'a';
else return c - 'A' + 26;
}
struct Palindromic_Tree {
int next[MAXN][N] ;
int fail[MAXN] ;
int cnt[MAXN] ;
int num[MAXN] ;
int len[MAXN] ;
int S[MAXN] ;
int last ;
int n ;
int p ;
int newnode ( int l ) {
for ( int i = 0 ; i < N ; ++ i ) next[p][i] = 0 ;
cnt[p] = 0 ;
num[p] = 0 ;
len[p] = l ;
return p ++ ;
}
void init () {
p = 0 ;
newnode ( 0 ) ;
newnode ( -1 ) ;
last = 0 ;
n = 0 ;
S[n] = -1 ;
fail[0] = 1 ;
}
int get_fail ( int x ) {
while ( S[n - len[x] - 1] != S[n] ) x = fail[x] ;
return x ;
}
void add ( int c ) {
S[++ n] = c ;
int cur = get_fail ( last ) ;
if ( !next[cur][c] ) {
int now = newnode ( len[cur] + 2 ) ;
fail[now] = next[get_fail ( fail[cur] )][c] ;
next[cur][c] = now ;
num[now] = num[fail[now]] + 1 ;
}
last = next[cur][c] ;
cnt[last] ++ ;
}
void count () {
for ( int i = p - 1 ; i >= 0 ; -- i ) cnt[fail[i]] += cnt[i] ;
}
} p;
char s[N];
int i,j,k;
int main(){
scanf("%s",s);
j=strlen(s);
p.init();
for(i=0;i<j;++i) p.add(f(s[i]));
p.count();
return 0;
}