Submatrices sum code

i have tried implementing the code of this approach but could not build it because i am understanding what to do with nested loops of li lj and bi bj in the starting for top left and bottom right or first four loops . can someone tell me how can implement those four loops ?
below given my code:


Check now.You code is correct. It is similar to the pseudo code taught in the lecture videos.I have just changed loop in line 20 and 22.