Consider the grid from (0,0) to (N,N).
Consider every subrectangle whose four corners have integer coordinates, that is, every [r1,r2]×[c1,c2] with 0≤r1<r2≤N and 0≤c1<c2≤N. The area of such a rectangle is (r2−r1)×(c2−c1). The following pseudocode computes the sum of the areas of all subrectangles.
sum = 0
for r1 = 0 to N-1
for c1 = 0 to N-1
for r2 = r1+1 to N
for c2 = c1+1 to N
sum = sum + (r2-r1)*(c2-c1)
print(sum)
Given N, compute this sum efficiently. The input contains several test cases.