#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x).size()
using namespace std;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int N = 1e3 + 5, M = 1e2 + 2, K = 5e2 + 5;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
void fast()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
}
int id = 0;
string s;
int dp[N][N], vis[N][N];
int lcs(int i, int j)
{
if (i > j)
return 0;
if (i == j)
return 1;
int &ret = dp[i][j];
if (vis[i][j] == id)
return ret;
if (s[i] == s[j])
return ret = 2 + lcs(i + 1, j - 1);
ret = 0, vis[i][j] = id;
ret = max(ret, lcs(i, j - 1));
ret = max(ret, lcs(i + 1, j));
return ret;
}
int32_t main()
{
fast();
while (cin >> s)
{
id++;
int x = lcs(0, s.size() - 1);
cout << x << "\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZwojZGVmaW5lIGFsbCh4KSB4LmJlZ2luKCksIHguZW5kKCkKI2RlZmluZSByYWxsKHgpIHgucmJlZ2luKCksIHgucmVuZCgpCiNkZWZpbmUgc3ooeCkgKGludCkoeCkuc2l6ZSgpCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBkb3VibGUgcGkgPSBhY29zKC0xKTsKY29uc3QgaW50IG1vZCA9IDFlOSArIDc7CmNvbnN0IGludCBOID0gMWUzICsgNSwgTSA9IDFlMiArIDIsIEsgPSA1ZTIgKyA1OwoKaW50IGR4W10gPSB7MCwgMCwgMSwgLTEsIDEsIDEsIC0xLCAtMX07CmludCBkeVtdID0gezEsIC0xLCAwLCAwLCAxLCAtMSwgMSwgLTF9OwoKdm9pZCBmYXN0KCkKewojaWZuZGVmIE9OTElORV9KVURHRQogICAgZnJlb3BlbigiaW5wdXQudHh0IiwgInIiLCBzdGRpbik7CiAgICBmcmVvcGVuKCJvdXRwdXQudHh0IiwgInciLCBzdGRvdXQpOwojZW5kaWYKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUobnVsbHB0ciksIGNvdXQudGllKG51bGxwdHIpOwp9CgppbnQgaWQgPSAwOwpzdHJpbmcgczsKaW50IGRwW05dW05dLCB2aXNbTl1bTl07CgppbnQgbGNzKGludCBpLCBpbnQgaikKewogICAgaWYgKGkgPiBqKQogICAgICAgIHJldHVybiAwOwoKICAgIGlmIChpID09IGopCiAgICAgICAgcmV0dXJuIDE7CgogICAgaW50ICZyZXQgPSBkcFtpXVtqXTsKCiAgICBpZiAodmlzW2ldW2pdID09IGlkKQogICAgICAgIHJldHVybiByZXQ7CgogICAgaWYgKHNbaV0gPT0gc1tqXSkKICAgICAgICByZXR1cm4gcmV0ID0gMiArIGxjcyhpICsgMSwgaiAtIDEpOwoKICAgIHJldCA9IDAsIHZpc1tpXVtqXSA9IGlkOwogICAgcmV0ID0gbWF4KHJldCwgbGNzKGksIGogLSAxKSk7CiAgICByZXQgPSBtYXgocmV0LCBsY3MoaSArIDEsIGopKTsKICAgIHJldHVybiByZXQ7Cn0KCmludDMyX3QgbWFpbigpCnsKICAgIGZhc3QoKTsKCiAgICB3aGlsZSAoY2luID4+IHMpCiAgICB7CiAgICAgICAgaWQrKzsKICAgICAgICBpbnQgeCA9IGxjcygwLCBzLnNpemUoKSAtIDEpOwogICAgICAgIGNvdXQgPDwgeCA8PCAiXG4iOwogICAgfQoKICAgIHJldHVybiAwOwp9