Beads
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
The necklace is made up of beads in 4 different colors. The owner wants to keep beads of only 3 colors. Determine the minimum number of beads that must be removed from the necklace if the cut can be made only once, and the beads must be removed consecutively. Once removed, the beads cannot be returned, and the remaining string is tied together.
Input
The program reads from the keyboard the number of beads N (4 ≤ N ≤ 5000), followed by N integers in the same row separated by spaces, each representing the color of a bead (1 for yellow, 2 for blue, 3 for red, 4 for green).
Output
The program outputs a single integer — the minimum number of beads that need to be removed.
Examples
Input #1
Answer #1
Submissions 204
Acceptance rate 25%