题号:NC24430
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 64 M,其他语言128 M
64bit IO Format: %lld
题目描述
Ramen likes palindrome.
A palindrome is a word, number, phrase, or other sequences of characters which reads the same backward as forward, such as madam or racecar or the number 10801.
An all palindrome is such a string that each substring of it is a palindrome. For example, the string aaa is an all palindrome while aba is not.
There is a string, and Ramen wants to make it an all palindrome string. He has a magic skill that he can remove any character of the string as much as he wants. But cast such a spell will cost him a lot of energy. As a lazy boy, he wants to save energy to play games, so can you tell him the minimum number of the necessary characters that he needs to remove?
输入描述:
The input contains precisely two lines.
The first line is an integer n(1 <= n <= 100000), which indicates the length of the given string.
The second line is the given string S. It's guaranteed that S contains only lower case Lattin letters, i.e., a-z.
输出描述:
For each test case, output the minimum number of necessary removals.
示例1
输入
复制
22
welcometotheupcofhitwh
示例3
输入
复制
25
goandgrabyoursignupreward