import java.util.*;
class Main
{
static int[][] answers;
static int calculate(int l, int r){
if(l > r) return 0; //Если индекс левой границы отрезка больше индекса правой.
if(answers[l][r] == -1){ //Если ответ для данного отрезка ещё не известен, находим его.
answers[l][r] = s.length();
if(s.
charAt(l
) == s.
charAt(r
)) answers
[l
][r
] = Math.
min(answers
[l
][r
], calculate
(l
+1, r
-1)); for(int i = l; i < r; ++i){
answers
[l
][r
] = Math.
min(answers
[l
][r
], calculate
(l, i
) + calculate
(i
+1, r
)); }
}
return answers[l][r];
}
{
Scanner in
= new Scanner
(System.
in); s = in.nextLine(); //Ввод строки.
answers = new int[s.length()][s.length()];
//Заполнение массива начальными значениями.
for(int i = 0; i < s.length(); ++i){
for(int j = 0; j < s.length(); ++j){
if(i == j) answers[i][j] = 1;
else answers[i][j] = -1;
}
}
//Вывод ответа.
System.
out.
print(calculate
(0, s.
length()-1)); }
}
aW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgTWFpbgp7CglzdGF0aWMgaW50W11bXSBhbnN3ZXJzOwoJc3RhdGljIFN0cmluZyBzOwoKCXN0YXRpYyBpbnQgY2FsY3VsYXRlKGludCBsLCBpbnQgcil7CgkJaWYobCA+IHIpIHJldHVybiAwOyAgLy/QldGB0LvQuCDQuNC90LTQtdC60YEg0LvQtdCy0L7QuSDQs9GA0LDQvdC40YbRiyDQvtGC0YDQtdC30LrQsCDQsdC+0LvRjNGI0LUg0LjQvdC00LXQutGB0LAg0L/RgNCw0LLQvtC5LgoJCWlmKGFuc3dlcnNbbF1bcl0gPT0gLTEpeyAvL9CV0YHQu9C4INC+0YLQstC10YIg0LTQu9GPINC00LDQvdC90L7Qs9C+INC+0YLRgNC10LfQutCwINC10YnRkSDQvdC1INC40LfQstC10YHRgtC10L0sINC90LDRhdC+0LTQuNC8INC10LPQvi4KCQkJYW5zd2Vyc1tsXVtyXSA9IHMubGVuZ3RoKCk7CgkJCWlmKHMuY2hhckF0KGwpID09IHMuY2hhckF0KHIpKSBhbnN3ZXJ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