def polynomial_multiply_mod(m1, m2, polymod, p):
 prod = (((len(m1) + len(m2)) - 1) * [0])
 for i in range(len(m1)):
  for j in range(len(m2)):
   prod[(i + j)] = ((prod[(i + j)] + (m1[i] * m2[j])) % p)
 return polynomial_reduce_mod(prod, polymod, p)

def polynomial_multiply_mod ( m1 , m2 , polymod , p ) : prod = ( ( ( len ( m1 ) + len ( m2 ) ) - 1 ) * [ 0 ] ) for i in range ( len ( m1 ) ) : for j in range ( len ( m2 ) ) : prod [ ( i + j ) ] = ( ( prod [ ( i + j ) ] + ( m1 [ i ] * m2 [ j ] ) ) % p ) return polynomial_reduce_mod ( prod , polymod , p )
polynomial multiplication modulo a polynomial over ints mod p .