If all numbers A

*were different, then the solution is obvious: 1) count the number of inversions, or 2) go through the first element to the last, and if the current element differs from needed - then swap current element with the needed and answer++.*

But when there may be several instances of the same number, then difficulties appear: we don't know which of the copies to swap. For example, "2 1 1" - here we should swap 2 and the second 1.

Maybe (I speak about algorithm 2) ), if there are several choices, then we should always swap with the last one?..

But when there may be several instances of the same number, then difficulties appear: we don't know which of the copies to swap. For example, "2 1 1" - here we should swap 2 and the second 1.

Maybe (I speak about algorithm 2) ), if there are several choices, then we should always swap with the last one?..