Sorts an array using merge_sort algorithm, also counts total inversions.