#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = s.size(); vector> p(n, vector(n + 1, false)); for (int i = 0; i < n; i++) { p[i][i + 1] = true; if (i < n - 1) { p[i][i + 2] = (s[i] == s[i + 1]); } } for (int len = 3; len <= n; len++) { for (int i = 0; i + len <= n; i++) { if (p[i + 1][i + len - 1] && s[i] == s[i + len - 1]) { p[i][i + len] = true; } } } vector dp(n + 1, 0); for (int i = 1; i <= n; i++) { for (int j = 0; j < i; j++) { if (p[j][i]) { if (j == 0) { dp[i] = max(dp[i], i); } else { dp[i] = max(dp[i], min(dp[j], i - j)); } } } } cout << dp[n] << '\n'; }