#include #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) #define pii pair #define vi vector #define fi first #define se second #define pb push_back #define ALL(x) x.begin(),x.end() #define sz(x) int(x.size()) #define ll long long using namespace std; const int N = 5e3 + 5; int n,ok[N][N],dp[N]; char s[N]; int main(){ cin.tie(0)->sync_with_stdio(0); cin >> (s + 1); while(s[n + 1])n++; dp[0] = n; rep(i,1,n)ok[i][i] = 1; rep(len,2,n)rep(i,1,n){ int j = i + len - 1; if(len == 2 && s[i] == s[j])ok[i][j] = 1; if(len > 2 && s[i] == s[j])ok[i][j] = ok[i + 1][j - 1]; } rep(i,1,n)rep(j,1,i){ if(ok[j][i])dp[i] = max(dp[i],min(dp[j - 1],i - j + 1)); } cout << dp[n] << endl; return 0; }