Manacher's algorithm, O(n)