Magical floor
Difficulty: Hard

Rajarshee has few friends. As you see, not all of them are beneficial. Some are selfish while some of them are too proud. However, he is leading his own life, not much problem to worry about yet. One thing you should know about him : he is very fond of adventure!

However, as you all now, a peaceful life is enviable. 
Rajarshee is much weak in solving problems and doesn't care much about challenges and avoids them. However a jealous friend tries to disrupt his peace and throws an unsolved challenge to him and says, "Solve your love for adventure!"

Rajarshee gets angry and takes this threat seriously!

His friend gives him information about a strange house with a magical floor on which a __n x n__ grid is drawn with square cells and a number written on each cell. The magical part lies in the fact that whenever any two people stands on two cells each, all the numbers in either diagonal of a cell gets added (including the cell on which you stand) and you get a total reward in gold with value of the sum. The same thing happens for both the cell.

"Easy!", Rajarshee lies!


"Let me add more to your pain. If there is a cell which lies in a diagonal common to both the cell, you wont get any gold. Instead, you will visit hell straight down!"

Rajarshee gets afraid yet he is ashamed to show his fear to the jealous friend. Instead, he comes to you, his best friend and a remarkable programmer.

You visit the house with your laptop along with him. After seeing the grid and all the numbered cells, you start writing a program that will solve the problem and make the gold inevitable for you two!

Input Format:
 The first line contains a integer n (2 ≤ n ≤ 2000). The __ith__ line of the next n lines contains n integers where __jth__ integer denotes __a[i][j]__ (0 ≤ a[i][j] ≤ 10^9) where __a__ is the matrix representation of the grid.

Output Format:
 Print the maximum total reward that you can achieve.

Sample Input:
	4
	1 1 1 1
	2 1 1 0
	1 1 1 0
	1 0 0 1


Sample Output:
 	12

Python 3 starter code:


Reference solution (Python):
	import java.io.BufferedReader;
	import java.io.IOException;
	import java.io.InputStreamReader;
    
	public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int i,j,n = Integer.parseInt(br.readLine());
        long a[][] = new long[n][n];
        int x1=0,y1=0,x2=0,y2=1;
        long max1=0,max2=0;
        cell c[][] = new cell[n][n];
        
        for(i=0;i<n;i++)
        {
           j=0;           
           String t[] = br.readLine().split(" ");
           while(j<n)           
           {
               a[i][j] = Integer.parseInt(t[j]);
               int x = i, y = j;
               if(x<y)
               {
                   y -= (x-0);
                   x = 0;
               }
               else
               {
                   x -= (y-0);
                   y = 0;
               }
               if(c[x][y]==null)               
                   c[x][y] = new cell();       
               c[x][y].dia1+= a[i][j];
               x= i; y = j;
               if(x-0>n-1-y)
               {
                   x -= (n-1-y);
                   y = n-1;
               }
               else
               {
                   y += (x-0);
                   x = 0;
               }
               if(c[x][y]==null)               
                   c[x][y] = new cell();  
               c[x][y].dia2+= a[i][j];
               
               j++;
               
           }                      
        }
        
        for(i = 0;i<n; i++)
        {           
            for(j=0;j<n; j++)
            {              
                if(c[i][j]==null)                
                    c[i][j] = new cell();    
                
                int x = i, y = j;
               if(x<y)
               {
                   y -= (x-0);
                   x = 0;
               }
               else
               {
                   x -= (y-0);
                   y = 0;
               }
               c[i][j].dia1 = c[x][y].dia1;   
               
               x= i; y = j;
               if(x-0>n-1-y)
               {
                   x -= (n-1-y);
                   y = n-1;
               }
               else
               {
                   y += (x-0);
                   x = 0;
               }
               c[i][j].dia2 = c[x][y].dia2;     
               long t = c[i][j].dia1 + c[i][j].dia2 - a[i][j];
             if((i+j)%2==0 && t>max1)
             {
                 max1 = t; x1 = i; y1 = j ;
             }
             else if((i+j)%2==1 && t>max2)
             {
                 max2 = t; x2 = i; y2 = j;
             }
               
            }
            
        }     
        System.out.println(max1+max2);        
        
    }    
    
	}

	class cell
	{
    	long dia1,dia2;
	}