Time limit
2s
Memory limit
128 MB
There are ten balls labeled with the digits from 0 to 9, one ball for each digit. There are also several cards, each labeled with one digit from 0 to 9, and four boxes that can each hold one ball. Multiple cards may have the same digit, but each digit has only one matching ball.
Process the cards one by one in the given order. For each card, the ball with the same digit must be placed in one of the boxes according to these rules.
Given the card sequence, find the minimum possible total number of insertion and replacement operations needed to process all cards in order.
The first line contains the number of drawn cards, n. (0 <= n <= 100)
If n is greater than 0, the second line contains n space-separated digits. These digits describe the cards in the order they were drawn, and each digit is between 0 and 9.
Print the minimum number of operations required.