To query the sum of a rectangle from to : Why four terms?
You start with the big rectangle, subtract two overlapping pieces, but that removes the top-left corner twice. Add it back once. You're using inclusion-exclusion.
Draw it on paper if it's not clear. The picture makes the formula obvious.