implement inversions problem