#include<bits/stdc++.h> using namespace std; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch&15); ch=getchar(); } return x*f; } inline void write(int x) { if(x<0)x=-x,putchar('-'); if(x>9)write(x/10); putchar(x%10+48); return; } const int M=30,N=2e7+7,INF=0x3f3f3f3f; struct node{int v,w;}; vector<node>mp[M]; int n,ans,kk[M][M],st[N],f[N]; inline void dfs(int u,int res) { if(u>n) { ans=max(res,ans); return; } for(auto t:mp[u]) { int v=t.v,w=t.w; if(st[v])continue; st[u]=v; st[v]=u; int k=u; while(st[k])++k; dfs(k,res+w); st[u]=0; st[v]=0; } } mt19937 dg(time(0)); int main() { n=read(); for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) { kk[i][j]=read(); if(~kk[i][j])mp[i].emplace_back((node){j,kk[i][j]}); } if(n<=16)dfs(1,0); else { for(int S=3;S<(1<<n);++S) { if(__builtin_popcount(S)&1)continue; int cnt=0; for(int j=0;j<n;++j)if((1<<j)&S)st[++cnt]=j; for(int j=2;j<=cnt;++j) f[S]=max(f[S],f[S-(1<<st[1])-(1<<st[j])]+kk[st[1]+1][st[j]+1]); } ans=f[(1<<n)-1]; } write(ans); return 0; }