def merge_countsplit(b,c):
    """
    Given two sorted arrays b and c, output a merged sorted array and the number of inversions.
    
    Output:
    d, num_split: Merged array d and number of inversions.
    """
    i=0
    j=0
    k=0
    
    n1 = len(b)
    n2 = len(c)
    d = [None]*(n1+n2)
    num_split = 0
    
    # traverse over b and c
    while i<n1 and j<n2:
        if(b[i] <= c[j]):
            d[k] = b[i]
            i+=1
            k+=1
        else:
            d[k] = c[j]
            num_split += n1 - i
            j+=1
            k+=1
    
    while i<n1:
        d[k] = b[i]
        i+=1
        k+=1
        
    while j<n2:
        d[k] = c[j]
        j+=1
        k+=1
    return d, num_split