(p1: Polynomial, p2: Polynomial, q: Union[float, int, Fraction])
return ans
Compute the product of
    given cycle indices p1,
    and p2 and evaluate it at q.
Compute the product of
    given cycle indices p1,
    and p2 and evaluate it at q.
Compute the product of given cycle indices p1 and p2 and evaluate it at q .
def cycle_product_for_two_polynomials(p1: Polynomial, p2: Polynomial, q: Union[float, int, Fraction]) -> Union[float, int, Fraction]:
    """
    Compute the product of
    given cycle indices p1,
    and p2 and evaluate it at q.
    """
    ans = Fraction(0, 1)
    for m1 in p1.monomials:
        for m2 in p2.monomials:
            ans += cycle_product(m1, m2).substitute(q)

    return ans
def cycle_product_for_two_polynomials ( p1 : Polynomial , p2 : Polynomial , q : Union [ float , int , Fraction ] ) -> Union [ float , int , Fraction ] : ans = Fraction ( 0 , 1 ) for m1 in p1 . monomials : for m2 in p2 . monomials : ans += cycle_product ( m1 , m2 ) . substitute ( q ) return ans