#C4090. Minimum Energy to Make Array Interesting
Minimum Energy to Make Array Interesting
Minimum Energy to Make Array Interesting
You are given an array (a) consisting of (n) integers and an integer (k). An array is considered interesting if it does not contain three consecutive identical elements. In other words, for all indices (i \geq 2), it must hold that (a[i] \neq a[i-1] \text{ or } a[i-1] \neq a[i-2]).
Whenever the array contains three consecutive identical elements (i.e. (a[i]=a[i-1]=a[i-2]) for some (i \geq 2)), you are allowed to change (a[i]) to ((a[i] \bmod k) + 1). Each such modification incurs an energy cost of 1. Your task is to compute the minimum total energy required to make the array interesting.
For example, consider (n=6), (k=2) and (a=[1, 2, 2, 2, 1, 2]). Modifying the third occurrence of (2) in the consecutive sequence transforms it and the energy cost becomes 1.
inputFormat
The input is given via standard input (stdin). The first line contains two space-separated integers (n) and (k). The second line contains (n) space-separated integers representing the array (a).
outputFormat
Output a single integer on standard output (stdout) representing the minimum energy required to make the array interesting.## sample
6 2
1 2 2 2 1 2
1