Problems
Farmer John wants to take a picture of his cows grazing in their pasture to hang on his wall. The pasture is represented by an
No two cows may be placed in the same cell.
Every sub-grid of
For example, this placement is valid:
CCC
...
CCCwhile this placement is not, because the
square region that contains the bottom-right corner cell contains only 1 cow:
C.C
.C.
C..There are no other restrictions. You may assume that Farmer John has an infinite number of cows available (based on previous experience, this assumption certainly seems to be true...).
Farmer John wants some cells to contain cows more than other cells. In particular, he believes that when a cow is placed in cell
Determine the maximum possible total beauty of a valid placement of cows.
Input
The first line contains
The next
Output
Print one integer giving the maximum possible beauty of the resulting photo.
Example
4
3 3 1 1
1 1 3 1
3 3 1 1
1 1 3 3
22
In this sample, the maximum beauty can be achieved with the following placement:
CC..
..CC
CC..
..CCThe beauty of this placement is