#include <iostream>
#include <string>
using namespace std;
int **answers;
string s;
int calculate(int l, int r){
if(l > r) return 0; //Если индекс левой границы отрезка больше индекса правой.
if(answers[l][r] == -1){ //Если ответ для данного отрезка ещё не известен, находим его.
answers[l][r] = s.size();
if(s[l] == s[r]) answers[l][r] = min(answers[l][r], calculate(l+1, r-1));
for(int i = l; i < r; ++i){
answers[l][r] = min(answers[l][r], calculate(l, i) + calculate(i+1, r));
}
}
return answers[l][r];
}
int main() {
getline(cin, s); //Ввод строки.
answers = new int*[s.size()];
for(int i = 0; i < s.size(); ++i){
answers[i] = new int[s.size()];
}
//Заполнение массива начальными значениями.
for(int i = 0; i < s.size(); ++i){
for(int j = 0; j <= s.size(); ++j){
if(i == j) answers[i][j] = 1;
else answers[i][j] = -1;
}
}
//Вывод ответа.
cout<<calculate(0, s.size()-1);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50ICoqYW5zd2VyczsKc3RyaW5nIHM7CgppbnQgY2FsY3VsYXRlKGludCBsLCBpbnQgcil7CglpZihsID4gcikgcmV0dXJuIDA7CS8v0JXRgdC70Lgg0LjQvdC00LXQutGBINC70LXQstC+0Lkg0LPRgNCw0L3QuNGG0Ysg0L7RgtGA0LXQt9C60LAg0LHQvtC70YzRiNC1INC40L3QtNC10LrRgdCwINC/0YDQsNCy0L7QuS4KCWlmKGFuc3dlcnNbbF1bcl0gPT0gLTEpeyAvL9CV0YHQu9C4INC+0YLQstC10YIg0LTQu9GPINC00LDQvdC90L7Qs9C+INC+0YLRgNC10LfQutCwINC10YnRkSDQvdC1INC40LfQstC10YHRgtC10L0sINC90LDRhdC+0LTQuNC8INC10LPQvi4KCQlhbnN3ZXJzW2xdW3JdID0gcy5zaXplKCk7CgkJaWYoc1tsXSA9PSBzW3JdKSBhbnN3ZXJzW2xdW3JdID0gbWluKGFuc3dlcnNbbF1bcl0sIGNhbGN1bGF0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