Colored Balls
Easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
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.
Input
The input consists of the number of balls in the line (up to 100) and the colors of these balls, represented by integers from 0 to 9, where each integer corresponds to a specific color.
Output
Output the total number of balls that will be removed.
Examples
Input #1
Answer #1
Submissions 586
Acceptance rate 30%