#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define MAXN 200010

using namespace std;

vector <vector <ll> > TRIE(MAXN*32, vector <ll> (2));
ll n = 1;

void ins(ll X)
{
    ll node = 0;
    for(int i = 31; i >= 0; i--)
    {
        ll v = X>>i&1;
        if(!TRIE[node][v]) TRIE[node][v] = n++;
        node = TRIE[node][v];
    }
}

ll src(ll X)
{
    ll res = 0, node = 0;
    for(int i = 31; i >= 0; i--)
    {
        ll v = X>>i&1;
        if(TRIE[node][v^1]) {node = TRIE[node][v^1]; res += (1LL << i);}
        else node = TRIE[node][v];
    }
    return res;
}


int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll N, cntA = 0, cntB = 0, m = 0;
    cin >> N;
    vector <ll> A(N), B(N);
    for(int i = 0; i < N; i++) {cin >> A[i]; if(A[i] == 1) cntA++; m = max(m, A[i]);}
    for(int i = 0; i < N; i++) {cin >> B[i]; if(B[i] == 1) cntB++;}
    if(cntA == N)
    {
        ll maks = 0;
        for(int i = 0; i < N; i++) maks = max(maks, B[i]);
        cout << maks << endl;
    }
    else if(cntB == N)
    {
        ins(0);
        ll maks = 0, val = 0;
        for(int i = 0; i < N; i++)
        {
            val ^= A[i];
            ins(val);
            maks = max(maks, src(val));
        }
        cout << maks << endl;
    }
    else if(N <= 10000)
    {
        ll res = 0;
        for(int L = 0; L < N; L++)
        {
            ll a = B[L];
            ll x = 0;
            for(int R = L; R < N; R++)
            {
                a &= B[R];
                x ^= A[R];
                res = max(res, a*x);
            }
        }
        cout << res << endl;
    }
    else cout << 1 << endl;
    return 0;
}