Mabel has a line of marbles, each of which is one of colours.
She can swap the position of two adjacent marbles, with the goal of creating a "complete colour grouping". A complete colour grouping for a colour occurs when all marbles of colour are arranged contiguously in a block of consecutive marbles.
Help Mabel find the minimum number of swaps to reach a complete colour grouping for each colour.
Input Specification
The first line will contain two space-separated integers, and , the number of marbles and the number of colours.
The second line will contain space-separated integers, , representing the colour of the of marble.
Output Specification
Output one line containing space-separated integers, representing the minimum number of swaps required to reach a complete colour grouping for each of the colours.
Sample Input
8 3
3 1 3 2 2 1 3 2
Sample Output
3 2 4
Sample Explanation
For colour 1, a complete colour grouping can be achieved in the following state: 3 1 1 3 2 2 3 2
. This takes 3 swaps to reach.
For colour 2, a complete colour grouping can be achieved in the following state: 3 1 3 2 2 2 1 3
. This takes 2 swaps to reach.
For colour 3, a complete colour grouping can be achieved in the following state: 1 3 3 3 2 2 1 2
. This takes 4 swaps to reach.
Comments