Every Palindrome, Counted — Solution & Editorial
Manacher's algorithm computes the palindrome radius at every odd and even center in O(n); the total count is the sum of all radii (each radius r contributes r palindromes centered there).
Complexity: O(|S|)
Watch out: Count reaches ~1012 for 'aaaa...'; 64-bit.