def polyval(f, x, m=None):
    """
    Evalutates a polynomial at a particular point, optionally modulo something.
    Input:
        f -- List.  These are the polynomial's coefficients in order of
             increasing degree.
        x -- Integer.  Evaluate here.
        m -- Integer or None (default).  If not None, evaluate modulo m.
    Output: An integer.
    Examples:
    >>> polyval([1,2,3], 2)
    17
    >>> polyval([1,2,3], 2, 3)
    2
    """
    out = 0
    if m is None:
        for a in reversed(f):
            out = a + out * x
    else:
        for a in reversed(f):
            out = (a + out * x) % m
    return out
