Approach 2 for sum of all submatrices

the second part of my code i attached in this post kindly look into this and make the corrections and explains me where i am wrong

  1. first find the prefix matrix then use it in the top right and bottom left loop