Claudio works hard and enjoys helping others. Over the years, he has learned many skills: he can work as a farmhand, carpenter, engineer, mechanic, gravedigger, businessman, or neighborhood bar owner. Whatever the job, he does it exceptionally well, even without formal training.
Today he has jobs to do, in a fixed order, and each job requires a specific skill. Claudio needs to change tools whenever two consecutive jobs in his schedule require different skills. Notice that preparing the tools for his first job does not count as a tool change.
Claudio’s son is following in his footsteps and wants to practice one of the skills. The son can choose any skill and perform all jobs requiring that skill. These jobs are removed from Claudio’s schedule, while the order of all remaining jobs stays the same.
When choosing a skill to practice for the day, Claudio’s son wants to help his father as much as possible, minimizing the number of tool changes that Claudio will need for the remaining jobs. What is this minimum number?
The first line contains an integer () indicating the number of jobs.
The second line contains integers (), where is the skill required for the -th job.
Output a single line with an integer representing the minimum possible number of tool changes.
8 1 2 1 2 2 3 2 1
2
If Claudio’s son performs all jobs requiring skill 1, the remaining jobs require the skills 2 2 2 3 2, and then Claudio needs to change tools twice. Choosing another skill does not reduce the number of tool changes.
2 1 2
0
Choosing either skill 1 or skill 2 leaves a single job, so Claudio makes no tool changes.
5 3 3 3 3 3
0
Claudio’s son can choose skill 3 and perform all five jobs, leaving Claudio with no jobs and hence no tool changes.