#include using namespace std; bool isPalindrome(const string &s, int l, int r) { for (int i = 0; i < r - l; i++) { if (s[l + i] != s[r - 1 - i]) { return false; } } return true; } bool isPalTwo(const string &s, int k, const vector &zF) { assert(k >= 2); // evil solution for (int i = 1; i < min(100, k); i++) { if (zF[s.size() * 2 + 1 - i] >= i && isPalindrome(s, i, k)) { return true; } } /* for (int i = 1; i < r - l; i++) { if (isPalindrome(s, l, l + i) && isPalindrome(s, l + i, r)) { return true; } } */ return false; } vector zAlgorithm(string s) { vector z(s.size()); z[0] = s.size(); int i = 1; int j = 0; while (i < s.size()) { while (i + j < s.size() && s[i + j] == s[j]) { j++; } z[i++] = j; if (j == 0) { continue; } j--; int k = 1; while (i < s.size() && z[k] < j) { z[i++] = z[k++]; j--; } } return z; } int main() { string s; cin >> s; string t = s; reverse(t.begin(), t.end()); int n = s.size(); vector bad(n); vector cnt(n + 2); vector z = zAlgorithm(s); vector zF = zAlgorithm(s + "$" + t); vector zB = zAlgorithm(t + "$" + s); for (int i = 1; i < n; i++) { if (bad[i]) { continue; } if (zF[n * 2 + 1 - i] >= i) { for (int j = 2; i * j < n; j++) { if (z[i * (j - 1)] < i) { break; } cnt[i * j + 1] += j - 1; bad[i * j] = true; } } } for (int i = 2; i <= n - 2; i++) { if (bad[i]) { continue; } // TODO: more faster if (isPalTwo(s, i, zF)) { for (int j = 1; i * j < n; j++) { if (z[i * (j - 1)] < i) { break; } cnt[i * j + 1] += j; bad[i * j] = true; } } } for (int i = 0; i < n - 1; i++) { cnt[i + 1] += cnt[i]; } int64_t ans = 0; for (int i = 1; i < n; i++) { if (zB[n * 2 + 1 - i] >= i) { ans += cnt[n - i]; } } cout << ans << endl; }