USACO Silver: Painting the Barn

So I read the editorial and while I understand how the first code works, I don’t understand how they immediately go to the 2-D prefix sums in the second code. Could somebody please explain?

Not sure what the confusion is, 2D prefix sums are described here.