#K60647. Minimum Operations to Ensure Unique Adjacent Elements

    ID: 31133 Type: Default 1000ms 256MiB

Minimum Operations to Ensure Unique Adjacent Elements

Minimum Operations to Ensure Unique Adjacent Elements

You are given an array of integers. Your task is to determine the minimum number of operations required to modify the array so that no two adjacent elements are the same.

In one operation, you can change the value of any one element to any other integer. The goal is to achieve an array where for every index i (with 1 ≤ i < n), the condition \(a_i \neq a_{i+1}\) holds. A simple greedy strategy can be used: iterate through the array and whenever two consecutive elements are equal, count an operation and consider that change as done.

Note: If the array is empty or has only one element, no operation is required.

Mathematically, if the array is \(a_1, a_2, \dots, a_n\), then the minimum number of operations is given by:

[ \text{operations} = \sum_{i=1}^{n-1} \mathbf{1}{{a_i = a{i+1}}}, ]

where \(\mathbf{1}_{\{condition\}}\) is 1 if the condition is true, and 0 otherwise.

inputFormat

The first line contains an integer n (\(0 \leq n \leq 10^5\)), representing the number of elements in the array.

If n > 0, the second line contains n space-separated integers representing the array elements. If n = 0, there will be no second line.

outputFormat

Output a single integer which is the minimum number of operations required to ensure that no two adjacent elements in the array are the same.

## sample
5
1 2 2 3 3
2

</p>