也可以用Manacher算法做 但是我觉得有点麻烦..而且没搞出来= =
#include <cstdio>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
#include <functional>
#include <vector>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <sstream>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
const int MAX = 2005;
int F[MAX], G[MAX];
string Str;
int main()
{
while (cin >> Str)
{
size_t len = Str.length();
memset(F, 0, sizeof(F));
memset(G, 0, sizeof(G));
for (int i = 0; i < len; i++)
{
for (int l = i, r = i; l >= 0 && r < len && Str[l] == Str[r]; l--, r++)
F[l]++, G[r]++;
for (int l = i, r = i + 1; l >= 0 && r < len && Str[l] == Str[r]; l--, r++)
F[l]++, G[r]++;
}
for (int i = 1; i < len; i++)
G[i] += G[i - 1];
long long Ans = 0;
for (int i = 1; i < len; i++)
Ans += G[i - 1] * F[i];
cout << Ans << endl;
}
return 0;
}