#K7311. Minimum Blocks Removal

    ID: 33903 Type: Default 1000ms 256MiB

Minimum Blocks Removal

Minimum Blocks Removal

You are given a sequence of building blocks, each with a specified height. Your task is to determine the minimum number of blocks that need to be removed so that no two adjacent blocks have the same height.

More formally, given an integer n representing the number of blocks and a list of n integers where each integer denotes the height of a block, you need to compute the minimum removals required such that for every adjacent pair of blocks, their heights are different.

Example:

Input: n = 8, heights = [3, 3, 2, 1, 3, 3, 2, 1]
Output: 2

Explanation: Removing one of the first two blocks with height 3, and one of the two blocks with height 3 later in the list, ensures that no two adjacent blocks have the same height.

</p>

inputFormat

The input consists of two lines:

  • The first line contains a single integer n (1 ≤ n ≤ 105), representing the number of blocks.
  • The second line contains n space-separated integers, each representing the height of a block.

outputFormat

Output a single integer, which is the minimum number of blocks that must be removed so that no two adjacent blocks have the same height.

## sample
8
3 3 2 1 3 3 2 1
2