Implementation of the counting inversions algorithm in O(n log n) running time