#include <iostream>
#include <algorithm>
using namespace std;
const int L = 20000;
int n;
int mp[25][25]; //地图
int dp[L], temp[L];
int pre[L], now[L]; //上一行的所有状态,当前行的所有状态
int preNum, nowNum; //上一行的状态数,当前行的状态数
int ans[L]; //各状态选择的数之和
//深搜,搜索当前行的所有状态
//r:行数,c:列数,s:当前行选择状态,sum:当前行选择的数之和
void DFS(int r, int c, int s, int sum)
{
if (c >= n) //当前行搜索完成
{
now[++nowNum] = s;
ans[nowNum] = sum;
return;
}
DFS(r, c + 2, s | (1 << c), sum + mp[r][c]); //选择当前格子
DFS(r, c + 1, s, sum); //不选择当前格子
}
//动态规划
void DP()
{
for (int row = 1; row <= n; row++)
{
nowNum = 0;
DFS(row, 0, 0, 0); //搜索当前行的所有状态
for (int i = 1; i <= nowNum; i++)
dp[i] = 0;
for (int i = 1; i <= nowNum; i++)
{
for (int j = 1; j <= preNum; j++)
{
if (now[i] & pre[j]) //按位与不为0,即存在相邻格
continue;
dp[i] = max(dp[i], temp[j] + ans[i]);
}
}
for (int i = 1; i <= nowNum; i++) //当前行存为上一行
{
temp[i] = dp[i];
pre[i] = now[i];
}
preNum = nowNum;
}
}
int main()
{
while (cin >> n)
{
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < n; j++)
cin >> mp[i][j];
}
temp[1] = pre[1] = 0;
preNum = 1;
DP();
int ans = 0;
for (int i = 1; i <= preNum; i++)
{
ans = max(ans, temp[i]);
}
cout << ans << endl;
}
return 0;
}