from typing import Sequence


def polynomial(x: int, coefficients: Sequence[int], n: int) -> int:
    """value at x of polynomial with given coefficients in modulo field n"""
    y = 0
    for i, a in enumerate(coefficients):
        y = (y + (a * (x ** i) % n) % n) % n
    return y