Count Inversions in an array, O(nlgn) solution
fix sort and counting error