#K69577. Minimum Additional Hills Construction

    ID: 33117 Type: Default 1000ms 256MiB

Minimum Additional Hills Construction

Minimum Additional Hills Construction

You are given an integer n representing the number of hills and an array heights of length n, where heights[i] denotes the height of the i-th hill.

Your task is to determine the minimum number of additional hills that must be constructed (by modifying the height of a hill) so that no two adjacent hills have the same height. In other words, after performing the modifications, the following condition must hold for every valid index i:

\( heights_{i} \neq heights_{i+1} \)

If the sequence already meets the criteria, no additional hill is required. The answer is defined as the number of modifications you need to perform. Note that it is always possible to modify a hill (by assigning it a sufficiently large value) so that the condition holds.

Example:

  • For n = 5 and heights = [1, 2, 2, 3, 4], a single modification is enough to ensure that no two consecutive hills have the same height. Hence, the answer is 1.

inputFormat

The first line of input contains a single integer n (1 ≤ n ≤ 105), representing the number of hills.

The second line contains n space-separated integers representing the heights of the hills.

outputFormat

Output a single integer which is the minimum number of modifications required to ensure that no two adjacent hills have the same height.

## sample
5
1 2 2 3 4
1

</p>