Implementation of Counting Inversions algorithm