from typing import List


def _merge(nums: List[int], left: int, mid: int, right: int,
           aux: List[int]) -> int:
    """
    Helper function to merge the given sub-list.
    :param nums: list[int]
    :param left: int
    :param mid: int
    :param right: int
    :param aux: list[int]
    :return: int
    """
    left_ptr, right_ptr = left, mid + 1
    merged_ptr = left
    inversion_count = 0
    while left_ptr <= mid and right_ptr <= right:
        if nums[left_ptr] <= nums[right_ptr]:
            aux[merged_ptr] = nums[left_ptr]
            left_ptr += 1
            inversion_count += right_ptr - (mid + 1)
        else:
            aux[merged_ptr] = nums[right_ptr]
            right_ptr += 1
        merged_ptr += 1
    while left_ptr <= mid:
        aux[merged_ptr] = nums[left_ptr]
        left_ptr += 1
        merged_ptr += 1
        inversion_count += right_ptr + 1 - (mid + 1)
    while right_ptr <= right:
        aux[merged_ptr] = nums[right_ptr]
        right_ptr += 1
        merged_ptr += 1
    nums[left:right + 1] = aux[left:right + 1]
    return inversion_count
    # Running time complexity: O(n)