#include <stdio.h>
#include <string.h>
#include <iostream>
#include<functional>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
const int maxn = 35;
const int inf = 1<<30;
int n;
int map[maxn][maxn],dp[maxn][maxn][maxn][maxn];
int Max( int a,int b,int c,int d )
{
if( a < b ) a = b;
if( a < c ) a = c;
if( a < d ) a = d;
return a;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt","r",stdin);
#endif
while( scanf("%d",&n) != EOF ){
memset( dp,0,sizeof(dp) );
for( int i = 1; i <= n; i ++ )
for( int j = 1; j <= n; j ++ )
scanf("%d",&map[i][j]);
for( int i = 1; i <= n; i ++ ){
for( int j = 1; j <= n; j ++ ){
for( int x = 1; x < i; x ++ ){
int y = i + j - x;
dp[i][j][x][y] = Max( dp[i-1][j][x-1][y],dp[i-1][j][x][y-1],dp[i][j-1][x-1][y],dp[i][j-1][x][y-1] ) + map[i][j] + map[x][y];
}
}
}
printf("%d\n",dp[n][n-1][n-1][n] + map[1][1] + map[n][n]);
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <iostream>
#include<functional>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
const int maxn = 35;
const int inf = 1<<30;
int n;
int map[maxn][maxn],dp[maxn][maxn][maxn][maxn];
bool vis[maxn][maxn][maxn][maxn];
int Max( int a,int b,int c,int d )
{
if( a < b ) a = b;
if( a < c ) a = c;
if( a < d ) a = d;
return a;
}
int dfs( int a,int b,int c,int d )
{
if( a<1 || a>n || b<1 || b>n || c<1 || c>n || d<1 || d>n ) //判断是否越界
{
return 0;
}
if( vis[a][b][c][d] == 1 )
return dp[a][b][c][d];
vis[a][b][c][d] = 1;
dp[a][b][c][d] = Max( dfs( a-1,b,c-1,d ),dfs( a-1,b,c,d-1 ),dfs( a,b-1,c-1,d ),dfs( a,b-1,c,d-1 ) ) + map[a][b] + map[c][d];
return dp[a][b][c][d];
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt","r",stdin);
#endif
while( scanf("%d",&n) != EOF )
{
memset(dp,0,sizeof(dp));
memset(vis,0,sizeof(vis));
for( int i = 1; i <= n; i ++ )
{
for( int j = 1; j <= n; j ++ )
{
scanf("%d",&map[i][j]);
vis[i][j][i][j] = 1; //把两条路走到相同点的情况标记成1
}
}
printf("%d\n",dfs(n,n-1,n-1,n)+map[1][1]+map[n][n]);
}
return 0;
}