#include using namespace std; #define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define rrep(i, r, l) for (int i = (int)(r); i > (int)(l); i--) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() void solve() { const int MAX = 5005; string s; cin >> s; const int n = s.size(); vector dp(n + 1, 0); vector> kaibun(n + 1, vector(n + 1, false)); rep(i, 0, n) { kaibun[i][i + 1] = true; kaibun[i][i] = true; } rep(len, 2, n + 1) { rep(l, 0, n - len + 1) { int r = l + len; if (kaibun[l + 1][r - 1] && s[l] == s[r - 1]) { kaibun[l][r] = true; } } } dp[0] = MAX; rep(i, 0, n) { rep(j, i + 1, n + 1) { if (kaibun[i][j]) { dp[j] = max(dp[j], min(j - i, dp[i])); } } } cout << dp[n] << '\n'; } int main() { int q = 1; // cin >> q; while (q--) { solve(); } }