Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/dp-palindromlarga-bolish

Palindrome partitioning

Medium 1000 ms 128 MB 62%
Share

A string $s$ of lowercase Latin letters is given. It must be split into consecutive pieces so that every piece is a palindrome (reads the same from left to right and from right to left). What is the smallest number of pieces needed? For example, abaccd can be split into three pieces: aba, cc, d.

The letters of the string split into palindrome pieces, each piece marked with a bracket

Input

One line with the string $s$.

Output

One integer — the smallest number of pieces.

Note

$1 \le |s| \le 1000$
$s$ consists only of lowercase Latin letters

Examples

Input #1
abaccd
Output #1
3
Input #2
aab
Output #2
2

Sign in to submit a solution

Signing up is free and takes a minute.