def merge_and_count(a, b):
    """

    :param a: a list of integers
    :param b: a list of integers
    :return: c: the merged list
            count: the number of inversions
    """
    n = len(a) + len(b)
    i_a = 0
    i_b = 0
    c = []
    count = 0

    for i in range(0, n):
        if i_a >= len(a):
            c.append(b[i_b])
            i_b += 1

        elif i_b >= len(b):
            c.append(a[i_a])
            i_a += 1

        elif a[i_a] < b[i_b]:
            c.append(a[i_a])
            i_a += 1

        else:
            c.append(b[i_b])
            i_b += 1
            count += len(a) - i_a
    return c, count