#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll md=2038077799,mul=1400312813;
int n;
ll ai[200010],bi[200010],a[200010],b[200010];
vector<int> v;
ll hasha,hashb,etc;
ll ksm(int x)
{
	if (!x) return 1ll;
	return (((ksm(x/2)*ksm(x/2))%md)*(x%2 ? mul : 1))%md; 
}
int main()
{
	cin >>n;
	for (int i=0;i<n;i++) cin >>ai[i];
	for (int i=0;i<n;i++) cin >>bi[i];
	for (int i=0;i<n;i++) a[i]=ai[i]^ai[(i+1)%n],b[i]=bi[i]^bi[(i+1)%n];
	etc=ksm(n-1);
	for (int i=0;i<n;i++)
	{
		hasha=(((hasha*mul)%md)+a[i])%md;
		hashb=(((hashb*mul)%md)+b[i])%md;
	}
	for (int i=0;i<n;i++)
	{
		if (hasha==hashb) v.push_back(i);
		hasha=(hasha+md-((a[i]*etc)%md))%md;
		hasha=(((hasha*mul)%md)+a[i])%md;
	}
	for (int i=0;i<v.size();i++) cout <<v[i]<<" "<<(ai[v[i]]^bi[0])<<"\n";
	return 0;
} 
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
const ll MOD = 998244353;
const ll INF = 1e18;
using namespace std;

ll dp[1 << 20], pre[1 << 20];

main(){    
    #ifdef XOX
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\Input.txt", "r", stdin);
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\OPT.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(!cin.tie(NULL));
    
    int n;
    cin >> n;
    memset(dp, 0, sizeof(dp));
    memset(pre, 0, sizeof(pre));

    ll tmp, mask;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> tmp;
            mask = (1 << i)|(1 << j);
            dp[mask] += tmp;
        }
    }

    for(int i = 0; i < n; i++){
        for(int mask = 0; mask < (1 << n); mask++){
            if(mask&(1 << i))   dp[mask] += dp[mask^(1 << i)];
        }
    }

    for(int mask = 0; mask < (1 << n); mask++){
        pre[mask] = dp[mask];
        for(int sub = mask; sub; sub = (sub - 1)&mask){
            pre[mask] = max(pre[mask], pre[sub] + dp[mask^sub]);
        }
    }

    cout << pre[(1 << n) - 1] / 2;  

}