ZOJ Problem Set - 3751
Alice is very interested in the algorithm. He finds a interesting book called "Algorithmic puzzles" which contains more than 100 puzzles. The puzzles included many typical algorithmic thinking in the programming. He likes the grid puzzles most. The grid puzzle is which the puzzle is based on the grids.
On the page 173, Alice is attracted by a grid puzzle. There is a N * N grids. Each grid should be filled with a number from 1, 2, .., N * N. No two girds share the same number. For any two adjacent numbers X and X + 1, the grids they filled in should also be adjacent. The problem is to find the maximum sum of the numbers in the main diagonal (the ith grid in the ith row). Alice wants you to help him solve the problem.
There are multiple test cases. For each test case:
There is an integer N (1 <= N <= 1000) which described above.
For each test case, output the maximum sum of the numbers in the main diagonal.
Author: GAN, Tiansheng
Source: ZOJ Monthly, January 2014