R=range X=R(4001) D=[[i==j<1for j in X]for i in X] for i in X: for j in X:D[i][j]=((D[i][j-1]if j else 0)+(0if i