import math


def compute_colors(n, cols):
    """Interpolate a list of colors cols to a list of n colors."""
    m = len(cols)
    lst = []
    for i in range(n):
        j = math.floor (i * (m - 1.0) / (n - 1.0))
        k = math.ceil (i * (m - 1.0) / (n - 1.0))
        t = (i * (m - 1.0) / (n - 1.0)) - j
        (r0, g0, b0) = cols[int(j)]
        (r1, g1, b1) = cols[int(k)]
        r = min(255, max(0, int (0.5 + (1.0 - t) * r0 + t * r1)))
        g = min(255, max(0, int (0.5 + (1.0 - t) * g0 + t * g1)))
        b = min(255, max(0, int (0.5 + (1.0 - t) * b0 + t * b1)))
        lst.append((r,g,b))
    return lst