\begin{tutorial}{Painting stones}

\begin{center}
\begin{tabular}{rl}
\textbf{Problem Author}: & \textbf{Oleksandr Tymkovich} \\
\textbf{Prepared by}: & \textbf{Oleksandr Tymkovich} \\
\textbf{Editorial by}: & \textbf{Oleksandr Tymkovich} 
\end{tabular} 
\end{center}
\textbf{Solution for} $n\le 1\,000$:

Let's iterate over the color in which all the stones will be painted in the end. To find the minimum number of paintings for a certain color, you can follow the following greedy algorithm:
\begin{itemize}
\item if the color of the stone is the one we are iterating over, then move on;
\item otherwise, paint the current stone and the next one in the color we are iterating over.
\end{itemize}

\textbf{Full solution}:

Let's assume we are iterating over the color $C$. For which minimum number of operations can we paint the segment $[l,r]$ where the end stones are of color $C$, and there are no other stones of color $C$ except the end ones? From the algorithm for the solution $n\le 1000$, the answer is $\lfloor \frac{r-l}{2} \rfloor$.

We can divide the array into such segments, and the overall answer for the color $C$ is the sum of the answers for each segment. (Also, don't forget that you may need to paint the prefix and suffix).

So the solution is to calculate each color separately. For the color $C$, we have provided an algorithm with a complexity of $O(occ(C))$ where $occ(C)$ is the number of occurrences of the number $C$ in the array. In total, for all colors, the solution has a complexity of $O(n)$.

\end{tutorial}
