In a computer game, players arrange balls of various colors in a line. When a sequence of three or more consecutive balls of the same color appears, that sequence is removed. The remaining balls then shift to fill the gap, potentially creating new sequences that can also be removed.
Write a program to calculate how many balls will be removed in total, given an initial arrangement. Initially, there will be at most one sequence of three or more identical balls.
The input consists of the number of balls in the line (up to ) and the colors of these balls, represented by integers from to , where each integer corresponds to a specific color.
Output the total number of balls that will be removed.
Example 1