def f (cache, posX, posY, sizeX, sizeY):

    p=(posX, posY, sizeX, sizeY)
    if p in cache:
        return cache[p]

    rt=0

    # right
    if posX+1 != sizeX:
        rt=rt+f(cache, posX+1, posY, sizeX, sizeY)
    
    # bottom
    if posY+1 != sizeY:
        rt=rt+f(cache, posX, posY+1, sizeX, sizeY)
    
    # goal
    if posX+1 == sizeX and posY+1 == sizeY:
        rt=rt+1
    
    cache[p]=rt

    return rt

print (f({},0,0,21,21))
