solving inversion using merge sort