#K11851. No Adjacent Equal Heights

    ID: 23560 Type: Default 1000ms 256MiB

No Adjacent Equal Heights

No Adjacent Equal Heights

Given a sequence of n integers representing the heights of students standing in a row, determine the minimum number of students that need to be moved so that no two adjacent students have the same height.

A move is simply the rearrangement of a student to a position where the adjacent conflict is resolved. The main observation is that whenever two adjacent students have the same height, at least one of them must be moved. Your task is to calculate the minimum number of moves needed to achieve the desired configuration.

The formula to compute the answer is:

\( \text{moves} = \sum_{i=1}^{n-1} \mathbf{1}\{h_i = h_{i+1}\} \)

where \(h_i\) represents the height of the \(i^{th}\) student and \(\mathbf{1}\{\cdot\}\) is the indicator function which is 1 if the condition holds and 0 otherwise.

inputFormat

The first line contains an integer n denoting the number of students. The second line contains n space-separated integers representing the heights of the students. If n = 0, no further input is provided.

outputFormat

Output a single integer, the minimum number of students that need to be moved, such that no two adjacent students have the same height.## sample

6
1 1 2 3 3 1
2

</p>