CF1132F.Clear the String

传统题 时间 2000 ms 内存 256 MiB 10 尝试 2 已通过 2 标签

Clear the String

You are given a string ss of length nn consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. For example, after deleting substring bbbb from string abbbbaccdd we get the string aaccdd.

Calculate the minimum number of operations to delete the whole string ss.

Input

The first line contains one integer nn (1n5001 \le n \le 500) — the length of string ss.

The second line contains the string ss (s=n|s| = n) consisting of lowercase Latin letters.

Output

Output a single integer — the minimal number of operation to delete string ss.

Samples

5
abaca
3
8
abcddcba
4

在线编程 IDE

建议全屏模式获得最佳体验