Singularity Cup P2 - Reverse Substring Partitioning
View as PDFYou are given a string  of length 
, only consisting of the lowercase letters 
a-z.
Let us define an RSP (Reverse Substring Partition) as an operation where you partition  into two non-empty contiguous substrings, reverse both substrings, and merge the two letters that touch in the middle of the partitions into one.
In order to perform an RSP, it is required that during the final step, the last letter of the leftmost partition is the same as the first letter of the rightmost partition so they can be merged. Otherwise, this operation cannot be performed. More formally, you may perform an RSP by partitioning  into two non-empty substrings 
 and 
 where 
 if and only if the last letter of 
 when reversed is equal to the first letter of 
 when reversed.
After performing any number of RSPs, what is the minimum possible length of ?
Constraints
 only contains lowercase letters from the English alphabet.
Input Specification
The first line of input contains an integer .
The next line of input contains  lowercase letters representing 
.
Output Specification
Output a single integer, the smallest possible resulting length of .
Sample Input
4
noon
Sample Output
2
Comments