#include using namespace std; using P = pair; const int M = 1000000007; const long long LM = 1LL << 60; int solve(const string& s_) { string s = "^" + s_; int n = s.length(); vector> pl(n, vector(3, 0)), gpl(n, vector(3, 0)); pl[0][0] = 1; vector> g; for (int j = 1; j < n; ++j) { vector> g1, g2; for (auto [i, d, k] : g) { if (i > 0 && s[i - 1] == s[j]) { g1.emplace_back(i - 1, d, k); } } int r = -j; for (auto [i, d, k] : g1) { if (i - r != d) { g2.emplace_back(i, i - r, 1); if (k > 1) { g2.emplace_back(i + d, d, k - 1); } } else { g2.emplace_back(i, d, k); } r = i + (k - 1) * d; } if (j > 1 && s[j - 1] == s[j]) { g2.emplace_back(j - 1, j - 1 - r, 1); r = j - 1; } g2.emplace_back(j, j - r, 1); g.clear(); for (auto [i, d, k] : g2) { if (g.empty() || get<1>(g[(int)g.size() - 1]) != d) { g.emplace_back(i, d, k); } else { get<2>(g[(int)g.size() - 1]) += k; } } for (auto [i, d, k] : g) { r = i + (k - 1) * d; vector m = { 0LL, pl[r - 1][0], pl[r - 1][1] }; if (k > 1) { m[1] += gpl[i - d][1]; m[2] += gpl[i - d][2]; } if (d <= i) { gpl[i - d] = m; } pl[j][1] += m[1]; pl[j][2] += m[2]; } } long long ans = 0; vector a(n); a[0] = pl[0][2]; for (int i = 1; i < n; ++i) { a[i] = a[i - 1] + pl[i][2]; } for (auto [i, d, k] : g) { for (int j = 0; j < k; ++j) { if (i + d * j > 1) { ans += a[i + d * j - 2]; } } } return ans; } int main() { cin.tie(0); ios::sync_with_stdio(0); string s; cin >> s; cout << solve(s) << '\n'; return 0; }