IOI '00 - Beijing, China

Palindrome

A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted into the string in order to obtain a palindrome.

As an example, by inserting 2 characters, the string "Ab3bd" can be transformed into a palindrome ("dAb3bAd" or "Adb3bdA"). However, inserting fewer than 2 characters does not produce a palindrome.

Input

The first line contains an integer N (3 ≤ N ≤ 5000), the length of the input string. The string follows on the next line. The string will be composed of uppercase letters, lowercase letters, and digits. Uppercase and lowercase letters are to be considered distinct.

Output

A single integer, the desired minimal number.

Sample Input

5
Ab3bd

Sample Output

2

All Submissions
Best Solutions


Point Value: 10
Time Limit: 2.00s
Memory Limit: 16M
Added: Aug 22, 2009

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

I checked with various test cases and they all worked

Your submission doesn't respect the given limits.

Oh I forgot about optimizing memory! Thanks.

MLEs are now shown for Java. (As with everything else when it comes to grading Java, this may or may not work.)