Consider having a cow that gives a child every year from her fourth year of life on and all her subsequent children do the same.
After n years how many cows will you have?
Return null if n is not an integer.
Note: Assume all the cows are alive after n years.
from collections import deque
def count_cows(n):
    if not isinstance(n, int):
        return None
    calves = deque([1, 0, 0])
    cows = 0
    for i in range(n):
        cows += calves.pop()
        calves.appendleft(cows)
    return cows + sum(calves)
from collections import deque
def count_cows(n):
    if not isinstance(n, int):
        return None
    calves = deque([1, 0, 0])
    cows = 0
    for i in range(n):
        cows += calves.pop()
        calves.appendleft(cows)
    return cows + sum(calves)