#include <cstring> #include <cstdio> #include <algorithm> using namespace std; char s[100]; int rd[100]; int manecher(char* s) { int len = strlen(s); for (int i = len - 1; i >= 0; i--) { s[i * 2 + 3] = ‘#‘; s[i * 2 + 2] = s[i]; } s[len * 2 + 2] = ‘\0‘; s[1] = ‘#‘; s[0] = ‘$‘; memset(rd, 0, sizeof(rd)); int right = 0;//右边界 int cn = 0;//回文串中心 for (int i = 1; i < 2 * len + 2; i++) { if (right > i) { rd[i] = min(rd[2 * cn - i], rd[cn] + cn - i); } else { rd[i] = 1; } while (s[i + rd[i]] == s[i - rd[i]]) rd[i]++; if (right > cn + rd[i]) { right = cn + rd[i]; cn = i; } } int ans = 0; for (int i = 1; i < 2 * len + 2; i++) { ans = max(ans, rd[i] - 1); } return ans; } int main() { scanf("%s", s); printf("%d\n", manecher(s)); return 0; }