#C7455. Minimum Operations in a Garden Row

    ID: 51328 Type: Default 1000ms 256MiB

Minimum Operations in a Garden Row

Minimum Operations in a Garden Row

You are given a row of plants represented by integers. The first integer n in each test case indicates the number of plants, followed by n integers representing the type of each plant. Two adjacent plants should not be of the same type. To achieve this, you are allowed to change the type of a plant arbitrarily. Your task is to compute the minimum number of operations needed to ensure that no two adjacent plants are identical.

For example, consider the test case:

3 1 2 2

The first integer 3 indicates there are three plants: [1, 2, 2]. By modifying the last plant (or the middle one in an alternative valid strategy), you can obtain a configuration such as [1, 2, 3]. Thus, the answer is 1.

Note: When processing multiple test cases, the input ends with a line where the first integer is 0.

inputFormat

The input consists of several test cases, each on a separate line. Each test case is a space‐separated sequence of integers. The first integer n (n ≥ 0) indicates the number of plants in the row, followed by n integers representing the plant types. Input terminates when a test case with 0 as the first number is encountered (this test case should not be processed).

outputFormat

For each test case (except for the terminating test case), output a single integer representing the minimum number of operations required to ensure that no two adjacent plants are of the same type. Each result should be printed on its own line.

## sample
3 1 2 2
5 1 1 1 2 2
0
1

2

</p>