Count smaller items to the right

Write smaller_to_right(nums) that returns a list where entry i is how many items to the right of position i are smaller than nums[i].

smaller_to_right([5, 2, 6, 1])  ->  [2, 1, 1, 0]
smaller_to_right([-1, -1])      ->  [0, 0]

The pairwise loop is quadratic and passes the small checks. The fast version is merge sort on (value, original index) pairs, counting how many right-half items jump past each left-half item during the merge. One check has forty thousand items.

def smaller_to_right(nums):
    ...