cho.sh
Notes
Loading...

Ball Replacement

Time limit

2s

Memory limit

128 MB

Problem

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.

  1. If that ball is already in a box, do nothing.
  2. If there is an empty box, put the ball into an empty box. This is an insertion operation.
  3. If there is no empty box, remove one ball currently in a box and put the new ball in its place. This is a replacement operation.

Given the card sequence, find the minimum possible total number of insertion and replacement operations needed to process all cards in order.

Input

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.

Output

Print the minimum number of operations required.