
Let me explain the sample input...
Sample Input
1 2 3 4 5 6 7 8 9
then the bins are in this form:
Brown Green Clear
Bin #1: 1 2 3
Bin #2: 4 5 6
Bin #3: 7 8 9
We want to put all the brown bottles in one bin, all the green bottles in other and all the clear bottles in other. i.e we want to separe the bins by color.
if we try the following order:
BCG
then we have to move 4 brown bottles of bin#2 and 7 brown bottles of bin#3 to bin#1, because bin#1 is of brown bottles, of de same form we have to move 3 clear bottles from bin#1 and 9 clear bottles from bin#3 to bin#2 and 2 green bottles from bin#1 and 5 green bottles from bin#2 to bin#3, then the total of moved bottles is:
4 + 7 + 3 + 9 + 2 + 5 = 30.
I hope this help

P.D. There are only 6 possible combinations:
BCG
BGC
CBG
CGB
GBC
GCB
you can only figure out those 6 (yes, only 6) possible combinations, and then choose the smallest.