Sum of all submatrix from a given matrix approach 2

In the very first iteration all the four variables have values =0.
In the sum expression the value of index at some place is coming out to be negative due to which answer is coming wrong.

@J20APPPP0005
hello Nitish,
u should replace all negative indices term with zero.

but sir if i make them zero then

suppose i consider 2X2 matrix with all elements 1.

consider sub matrix of elements at (0,0) and (0,1) the sum must be 2 but we will get 0

@J20APPPP0005
pls check this->