Implement inversions counting