Under construction

Still being built. Things may change

Sum of Subrectangle Areas

Time limit2sMemory limit512 MB

Summary
For each N, compute the total area of all axis-aligned integer subrectangles in an N by N grid.
Level

Easy3 of 10

Topics
Math, Combinatorics
Solved
No attempts yet

Problem

Consider the grid from (0,0)(0, 0) to (N,N)(N, N).

Consider every subrectangle whose four corners have integer coordinates, that is, every [r1,r2]×[c1,c2][r_1, r_2] \times [c_1, c_2] with 0≤r1<r2≤N0 \le r_1 < r_2 \le N and 0≤c1<c2≤N0 \le c_1 < c_2 \le N. The area of such a rectangle is (r2−r1)×(c2−c1)(r_2 - r_1) \times (c_2 - c_1). 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 NN, compute this sum efficiently. The input contains several test cases.

Input

The first line contains the number of test cases TT. Each of the following TT lines contains a single integer NN for that test case. NN fits in a 64-bit integer with 0≤N≤92233720368547758070 \le N \le 9223372036854775807.

Output

For each test case, print the sum defined above on its own line. The sum may exceed the range of a 64-bit integer, so print it as an arbitrary precision integer.

Examples1

  1. Example 1

    Input
    5
    1
    2
    3
    4
    1000
    
    Expected output
    1
    16
    100
    400
    27944805889000000