#K91697. Minimum Trees to Cut

    ID: 38033 Type: Default 1000ms 256MiB

Minimum Trees to Cut

Minimum Trees to Cut

You are given a sequence of n trees, where each tree has a specified height. Your task is to determine the minimum number of trees that must be cut down so that no two adjacent trees have the same height.

Formally, given an array \(a_0, a_1, \dots, a_{n-1}\), you must ensure that after cutting some trees (removing them from the sequence), the remaining sequence (which preserves the original order) satisfies \(a_i \neq a_{i+1}\) for every valid index i. However, in this problem you are not allowed to rearrange the trees or remove trees from anywhere except by cutting; instead, you are to directly compute and output the minimum number of trees to cut in the original sequence to achieve the goal.

Note: Cutting a tree means that its height is completely removed from consideration and the gap is closed by the remaining trees shifting together.

inputFormat

The input is provided via standard input (stdin) with the following format:

  1. The first line contains an integer \(n\), the number of trees.
  2. The second line contains \(n\) space-separated integers, representing the heights of the trees in order.

outputFormat

Output a single integer to standard output (stdout) — the minimum number of trees that need to be cut so that no two adjacent trees have the same height.

## sample
6
4 4 4 5 6 6
3