Given a polynomial represented as poly[] of size n and a value x, compute value of the polynomial for given x.  The result should be computed under modulo 10^{9}+7. 
Example 1:
Input: n = 4, x = 3
poly = {2, -6, 2, -1}
Output: 5
Explaination: Output is value of 2x^{3} - 6x^{2} + 
2x - 1 for x = 3.
Example 2:
Input: n = 4, x = 2
poly = {1, 2, 0, 4}
Output: 20
Explaination: Output is value of x^{3} + 2x^{2} + 4 
for x = 2.
Your Task:
You do not need to read input or print anything. Your task is to complete the function value() which takes n, poly and x as input parameters and returns the value of the polynomial modulo 10^{9} + 7.
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ n ≤ 2000
-1000 ≤ poly[i] ≤ 1000
1 ≤ x ≤ 1000

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def value(self, n, poly, x):
        # code here

Solutions:
class Solution:

	def value(self, n, poly, x):
		(ans, m) = (0, int(1000000000.0) + 7)
		for i in range(n):
			ans += poly[i] * x ** (n - i - 1)
		return ans % m


class Solution:

	def value(self, n, poly, x):
		sum = 0
		p = n - 1
		for i in range(n):
			sum += poly[i] * x ** p
			p -= 1
		return sum % 1000000007


MOD = 1000000000.0 + 7

class Solution:

	def value(self, n, poly, x):
		acc = 1
		ans = 0
		for i in range(len(poly) - 1, -1, -1):
			ans = (ans % MOD + poly[i] * acc % MOD) % MOD
			acc = acc % MOD * x % MOD % MOD
		return int(ans)


class Solution:

	def value(self, n: int, poly: list, x: int) -> int:
		result = 0
		for i in range(n):
			result += poly[i] * x ** (n - 1 - i)
		return result % 1000000007


class Solution:

	def value(self, n, poly, x):
		mod = 10 ** 9 + 7
		poly = poly[::-1]
		Sum = 0
		for i in range(n - 1, -1, -1):
			Sum += poly[i] * x ** i % mod
		return int(Sum % mod)


class Solution:

	def value(self, n, poly, x):
		res = 0
		temp = 0
		for i in range(n):
			res += poly[i]
			if i == n - 1:
				res %= 1000000007
				return int(res)
			res *= x


class Solution:

	def value(self, n, poly, x):
		s = poly[0]
		for i in range(1, n):
			s = s * x + poly[i]
		return s % (10 ** 9 + 7)


class Solution:

	def value(self, n, poly, x):
		ans = 0
		for i in range(len(poly)):
			pow_val = x ** (n - 1)
			ans += poly[i] * pow_val
			n -= 1
		return ans % (10 ** 9 + 7)


class Solution:

	def value(self, n, poly, x):
		mod = 10 ** 9 + 7
		res = 0
		pow_x = 1
		for i in range(n - 1, -1, -1):
			res += pow_x * poly[i]
			pow_x = pow_x * x % mod
		return res % mod