CountInversions
O(n^2) and O(n logn) implementation