def polyeval(a, x):
	"""
	p(x) = polyeval(a, x)
	     = a[0] + a[1]x + a[2]x^2 +...+ a[n-1]x^{n-1} + a[n]x^n
	     = a[0] + x(a[1] + x(a[2] +...+ x(a[n-1] + a[n]x)...)
	"""
	p = 0
	a.reverse()
	for coef in a:
		p = p*x + coef
	a.reverse()
	return p