#include <bits/stdc++.h>
using namespace std;
string s;
vector<vector<int>> DP;
int solve(int l, int r)
{
if (l >= r) {
return 1;
}
if (DP[l][r] > -1) {
return DP[l][r];
}
DP[l][r] = r - l + 1;
for (int m = l; m < r; ++m) {
DP[l][r] = min(DP[l][r], solve(l, m) + solve(m + 1, r));
}
if (s[l] == s[r]) {
DP[l][r] = min(DP[l][r], solve(l + 1, r - 1));
}
return DP[l][r];
}
int main()
{
cin >> s;
DP.assign(s.size(), vector<int>(s.size(), -1));
cout << solve(0, s.size() - 1) << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJpbmcgczsKdmVjdG9yPHZlY3RvcjxpbnQ+PiBEUDsKCmludCBzb2x2ZShpbnQgbCwgaW50IHIpCnsKICAgIGlmIChsID49IHIpIHsKICAgICAgICByZXR1cm4gMTsKICAgIH0KICAgIGlmIChEUFtsXVtyXSA+IC0xKSB7CiAgICAgICAgcmV0dXJuIERQW2xdW3JdOwogICAgfQogICAgRFBbbF1bcl0gPSByIC0gbCArIDE7CiAgICBmb3IgKGludCBtID0gbDsgbSA8IHI7ICsrbSkgewogICAgICAgIERQW2xdW3JdID0gbWluKERQW2xdW3JdLCBzb2x2ZShsLCBtKSArIHNvbHZlKG0gKyAxLCByKSk7CiAgICB9CiAgICBpZiAoc1tsXSA9PSBzW3JdKSB7CiAgICAgICAgRFBbbF1bcl0gPSBtaW4oRFBbbF1bcl0sIHNvbHZlKGwgKyAxLCByIC0gMSkpOwogICAgfQogICAgcmV0dXJuIERQW2xdW3JdOwp9CgppbnQgbWFpbigpCnsKICAgIGNpbiA+PiBzOwogICAgRFAuYXNzaWduKHMuc2l6ZSgpLCB2ZWN0b3I8aW50PihzLnNpemUoKSwgLTEpKTsKICAgIGNvdXQgPDwgc29sdmUoMCwgcy5zaXplKCkgLSAxKSA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0=