#include #include #include #include #include using namespace std; bool p(string s) { for(int i = 0; i < s.size(); i++) { if(s[i] != s[s.size() - 1 - i]) return false; } return true; } bool b[101][101]; int dp[101]; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int n = s.size(); if(count(s.begin(), s.end(), s[0]) == n) { cout << n - 1 << endl; return 0; } for(int i = 0; i < n; i++) { for(int j = 1; i + j - 1 < n; j++) { if(i == 0 && j == n) continue; b[i][j] = p(s.substr(i, j)); } } memset(dp, -1, sizeof dp); dp[0] = 0; for(int i = 0; i < n; i++) { if(dp[i] == -1) continue; for(int j = 1; i + j - 1 < n; j++) { if(b[i][j]) { dp[i + j] = max(dp[i + j], dp[i]); dp[i + j] = max(dp[i + j], j); } } } cout << dp[n] << endl; }