def mag_intersect(A, B):
    """
    Returns magnitude of multiset-intersection of A and B
    """
    val = 0
    for term in A:
        if term in B:
            val += min(A[term], B[term])
    return val
