NOI Contest Archive

Archive / 2023 / Selection Test

Magical Eraser

Medium · National Olympiad in Informatics Sri Lanka - Screening Test 2023

You are given a magic eraser and tasked with erasing a word. When you use the magic eraser on a character on a word, if the characters on the left or right are the same character as the charcter you are using the eraser on, all those adjacent same characters are erased at once.
ex: abaaaaaca becomes abca when the magic eraser is used on any of the a characters in the middle.
Find out the minimum number of uses of the magic eraser that you need to erase the given word completely.

Input Format

one line containing \(n\): the length of the word
one line containing the word

Output Format

one line containing the minimum number of magic eraser uses to erase the word.

Constraints

all characters in the word are lowercase english letters
\(10 \le n \le 1000\)

Sample Input 0

10
bbbabaabaa

Sample Output 0

4