A necklace contains
beads, each of which may be of any one of seven different
colors. The beads are arranged arbitrarily in circular order with a thread
passing through the center of each bead. The thread is tied up at its ends
and the necklace is closed. Unfortunately, the colors of the beads are all
mixed-up and may appear in any order. It is your task to rearrange the beads
so that all beads of the same color occur together. To do this, you are
allowed to cut the thread at any point, remove some beads from either end,
put them back in a different order, and tie up the ends again. The cost of
this operation is the number of beads that were removed. You may perform any
number of such cut operations. The total cost is the sum of the costs of the
individual operations. You have to write a program to find the minimum total
cost required for rearranging a given initial necklace so that all beads of
the same color occur together.
Input
The input will consist of several test cases. The first line of each test
case will specify
, the number of beads in the necklace. If
is zero, it
indicates end of input. Assume that
is at most 100. The next line will
contain a character string with
characters, specifying the colors of the
beads in circular order. The color may be any one of the characters
in the string "vibgyor". There will no line separating individual test cases.
Output
The output should be a sequence of integers, one per line, giving the answer for each test case in the same order as the input. There should be no lines separating answers for successive test cases.
Sample Input
5 vbyrv 8 vbvvvbbv 0
Sample Output
0 3