Implementing one of the solutions of matrix region sum problem