#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1000 + 10;
char str[maxn];
int dp[maxn][maxn];
int main()
{
while (cin >> str) {
memset(dp, 0, sizeof(dp));
int len = strlen(str);
for (int i = len - 1; i >= 0; i--) {
dp[i][i] = 1;
for (int j = i + 1; j < len; j++) {
if (str[i] == str[j]) dp[i][j] = dp[i + 1][j - 1] + 2;
else dp[i][j] = max(dp[i][j - 1], dp[i + 1][j]);
}
}
printf("%d\n", dp[0][len - 1]);
}
return 0;
}
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1000 + 10;
char str[maxn];
int dp[maxn][maxn];
int main()
{
while (cin >> str) {
memset(dp, 0, sizeof(dp));
int len = strlen(str);
for (int i = len - 1; i >= 0; i--) {
dp[i][i] = 1;
for (int j = i + 1; j < len; j++) {
if (str[i] == str[j]) dp[i][j] = dp[i + 1][j - 1] + 2;
else dp[i][j] = max(dp[i][j - 1], dp[i + 1][j]);
}
}
printf("%d\n", dp[0][len - 1]);
}
return 0;
}