Working merge sort with inversion count