#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
// 动态规划求最长回文子串的长度
int longestPalindrome(const string& s) {
int n = s.size();
if (n == 0) return 0;
vector<vector<bool>> dp(n, vector<bool>(n, false));
int max_length = 1;
// 单个字符总是回文
for (int i = 0; i < n; ++i) {
dp[i][i] = true;
}
// 检查长度为2的子串
for (int i = 0; i < n - 1; ++i) {
if (s[i] == s[i + 1]) {
dp[i][i + 1] = true;
max_length = 2;
}
}
// 检查长度大于2的子串
for (int length = 3; length <= n; ++length) {
for (int i = 0; i <= n - length; ++i) {
int j = i + length - 1;
if (s[i] == s[j] && dp[i + 1][j - 1]) {
dp[i][j] = true;
max_length = length;
}
}
}
return max_length;
}
// 预处理字符串,移除只出现一次的字符
string preprocessString(const string& s) {
unordered_map<char, int> charCount;
for (char c : s) {
charCount[c]++;
}
string result;
for (char c : s) {
if (charCount[c] > 1) {
result += c;
}
}
return result;
}
int main() {
string input;
getline(cin, input);
// 预处理字符串
string processedString = preprocessString(input);
// 计算最长对称子串的长度
int maxLength = longestPalindrome(processedString);
// 输出结果
cout << maxLength << endl;
return 0;
}