from operator import add


def population(generation, fis):
    """
    Get the accumulated fish population at the given generation.

    This is accomplished by rotating the number of fish in each state left (à la a
    bitwise rotate, with the leftmost number representing the fish in the process of
    spawning coming back around to the 7-steps-to-next-spawn index) and then adding in
    the newly spawned fish (in this case, via zipping the result together with a
    additive mask).

    Achieves space = O(1) and time = O(generation) by operating over aggregated number
    of fish in each state rather than managing each fish's individual state.

    This implementation attempts to transliterate the functional solution, rather
    than translate the aforementioned steps into an imperative "Pythonic" solution.
    """
    for _ in range(generation):
        fis = list(map(add, [0, 0, 0, 0, 0, 0, fis[0], 0, 0], fis[1:] + [fis[0]]))
    return sum(fis)