CF2170A.Maximum Neighborhood

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Maximum Neighborhood

Consider an n×nn \times n grid filled with numbers as follows:

  • the first row contains integers from 11 to nn from left to right;
  • the second row contains integers from (n+1)(n+1) to 2n2n from left to right;
  • this pattern continues until the nn-th row, which contains integers from (n2n+1)(n^2-n+1) to n2n^2 from left to right.

Let's define the cost of a cell as its value plus the sum of its neighboring cells' values. Two cells are considered neighboring if they share a side.

Your task is to calculate the maximum cost among all cells in the grid.

The grid for n=4n = 4 and the optimal answer for it. The yellow cell has the maximum possible cost; the green cells are its neighbors. The cost of the cell is 15+11+14+16=5615+11+14+16=56.

Input

The first line contains a single integer tt (1t1001 \le t \le 100) — the number of test cases.

The only line of each test case contains a single integer nn (1n1001 \le n \le 100).

Output

For each test case, print a single integer — the maximum cost among all cells in the grid.

Note

In the first example, there is only 11 cell with the cost 11.

In the second example, the cell with value 44 has the maximum cost: 4+2+3=94 + 2 + 3 = 9.

In the third example, the cell with value 88 has the maximum cost: 8+5+7+9=298 + 5 + 7 + 9 = 29.

In the fourth example, the cell with value 1515 has the maximum cost: 15+11+14+16=5615 + 11 + 14 + 16 = 56.

In the fifth example, the cell with value 1919 has the maximum cost: 19+14+18+20+24=9519 + 14 + 18 + 20 + 24 = 95.

Samples

5
1
2
3
4
5
1
9
29
56
95

在线编程 IDE

建议全屏模式获得最佳体验