inversion count algorithM