So at this point, we know that in the resulting array, the first two elements

will be occupied by the number 1, the next seven elements will be occupied by

the number 2, and the next three elements will be occupied by the number 3.

Now we would like, instead of having just the lengths of these three intervals,

we would like to compute the starting point of each interval.

So we do this in a new loop.

And for this we introduce a new array Pos.

So Pos[1] is equal to 1,

meaning that number 1 will occupy a range starting from the first index.

And the starting point for each subsequent range is computed as a starting

point of each previous range, plus the length of this previous range.

So Pos[j] is computed as Pos[j -1] + Count[j- 1].

So at this point we know the starting point for each range.

Namely, k in the resulting array, number k will occupy a range starting from Pos[k].

Then we just count our initial array and whenever we see an element,

we always know where to put it in the initial array.

So then let me remind you that we do not just fill in the array with numbers from 1

to M, but we copy elements from our initial array.

This is because what we are looking for

in this certain problem is a permutation of our initial n given objects.

Because what we have is probably not just number, not just integers from 1 to M,

but these numbers are keys of some probably complex object.