#P1114D. Flood Fill
Flood Fill
No submission language available for this problem.
Description
You are given a line of colored squares in a row, numbered from to from left to right. The -th square initially has the color .
Let's say, that two squares and belong to the same connected component if , and for all satisfying . In other words, all squares on the segment from to should have the same color.
For example, the line has connected component, while the line has connected components.
The game "flood fill" is played on the given line as follows:
- At the start of the game you pick any starting square (this is not counted as a turn).
- Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
The first line contains a single integer () — the number of squares.
The second line contains integers () — the initial colors of the squares.
Print a single integer — the minimum number of the turns needed.
Input
The first line contains a single integer () — the number of squares.
The second line contains integers () — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Samples
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index as the starting square and then play as follows:
In the second example, a possible way to achieve an optimal answer is to pick square with index as the starting square and then perform recoloring into colors in that order.
In the third example, the line already consists of one color only.