def _extract_coefficients(polynomial, monomials, variables):
    """
    Return the coefficients of ``monomials``.

    INPUT:

    - ``polynomial`` -- the input polynomial

    - ``monomials`` -- a list of monomials in the polynomial ring

    - ``variables`` -- a list of variables in the polynomial ring

    OUTPUT:

    A tuple containing the coefficients of the monomials in the given
    polynomial.

    EXAMPLES::

        sage: from sage.schemes.toric.weierstrass import _extract_coefficients
        sage: R.<x,y,z,a30,a21,a12,a03,a20,a11,a02,a10,a01,a00> = QQ[]
        sage: p = (a30*x^3 + a21*x^2*y + a12*x*y^2 + a03*y^3 + a20*x^2*z +
        ....:      a11*x*y*z + a02*y^2*z + a10*x*z^2 + a01*y*z^2 + a00*z^3)
        sage: m = [x^3, y^3, z^3, x^2*y, x^2*z, x*y^2, y^2*z, x*z^2, y*z^2, x*y*z]
        sage: _extract_coefficients(p, m, [x,y,z])
        (a30, a03, a00, a21, a20, a12, a02, a10, a01, a11)

        sage: m = [x^3, y^3, 1, x^2*y, x^2, x*y^2, y^2, x, y, x*y]
        sage: _extract_coefficients(p.subs(z=1), m, [x,y])
        (a30, a03, a00, a21, a20, a12, a02, a10, a01, a11)
    """
    R = polynomial.parent()
    indices = [R.gens().index(x) for x in variables]

    def index(monomial):
        if monomial in R.base_ring():
            return tuple(0 for i in indices)
        e = monomial.exponents()[0]
        return tuple(e[i] for i in indices)
    coeffs = dict()
    for c, m in polynomial:
        i = index(m)
        coeffs[i] = c*m + coeffs.pop(i, R.zero())
    result = tuple(coeffs.pop(index(m), R.zero()) // m for m in monomials)
    if len(coeffs) != 0:
        raise ValueError('The polynomial contains more monomials than '
                         'given: '+str(coeffs))
    return result