#include<bits/stdc++.h>
#define ll long long
#define MAXN 200007
#define logn 21
using namespace std;
int n;
ll a[MAXN], b[MAXN];

ll xorpref[MAXN];
ll preand[2007][2007];
void sb1()
{
    ll ans=0;
    xorpref[0]=0;
    for(int i=1;i<=n;i++) xorpref[i]=xorpref[i-1]^a[i];
    for(int i=1;i<=n;i++)
    {
        preand[i][i]=b[i];
        for(int j=i+1;j<=n;j++)
        {
            preand[i][j]=preand[i][j-1]&b[j];
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            ans=max(ans,(xorpref[j]^xorpref[i-1])*preand[i][j]);
        }
    }
    cout<<ans<<endl;
}

void sb2()
{
    cout<<*max_element(b+1,b+n+1)<<endl;
}

ll sand[logn][MAXN];
ll getand(int l, int r)
{
    int lg = log2(r-l+1);
    return sand[lg][l]&sand[lg][r-(1<<(lg))+1];
}
ll najblizi[MAXN][512];
void sb3()
{
    for(int i=1;i<=n;i++) sand[0][i]=b[i];
    for(int i=1;i<logn;i++)
    {
        for(int j=1;j+(1<<i)<=n+1;j++)
        {
            sand[i][j]=sand[i-1][j]&sand[i-1][j+(1<<(i-1))];
        }
    }
    xorpref[0]=0;
    for(int i=1;i<=n;i++) xorpref[i]=xorpref[i-1]^a[i];
    for(int i=0;i<512;i++) najblizi[n][i]=-1;
    najblizi[n][a[n]]=n;
    for(int i=n-1;i>0;i--)
    {
        for(int j=0;j<512;j++)
        {
            najblizi[i][j]=najblizi[i+1][j^a[i]];
        }
        najblizi[i][a[i]]=i;
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<512;j++)
        {
            if(najblizi[i][j]!=-1)
            {
                ans=max(ans,j*getand(i,najblizi[i][j]));
            }
        }
    }
    cout<<ans<<endl;
}

struct Trie{
    ll cnt;
    Trie *children[2]={};
};
void add(Trie *root, ll x)
{
    Trie *cur = root;
    cur->cnt++;
    for(int i=30;i>=0;i--)
    {
        bool has_bit = x&(1<<i);
        if (cur->children[has_bit] == NULL) 
        {
			cur->children[has_bit] = new Trie;
		}
		cur->children[has_bit]->cnt++;
		cur = cur->children[has_bit];
    }
}
void remove(Trie *root, int x) 
{
	Trie *cur = root;
	for (int i = 30; i >= 0; i--) 
    {
		bool has_bit = x&(1<<i);
		cur->children[has_bit]->cnt--;
		cur = cur->children[has_bit];
	}
}
ll query(Trie *root, ll x)
{
    Trie *cur = root;
    ll y=0;
    for(int i=30;i>=0;i--)
    {
        bool has_bit = x&(1<<i);
        if(cur->children[!has_bit]!=NULL && cur->children[!has_bit]->cnt>0)
        {
            cur = cur->children[!has_bit];
            y+=(!has_bit)*(1<<i);
        }
        else
        {
            cur = cur->children[has_bit];
            y+=(has_bit)*(1<<i);
        }
    }
    return y;
}
void sb4()
{
    xorpref[0]=0;
    for(int i=1;i<=n;i++) xorpref[i]=xorpref[i-1]^a[i];
    Trie t;
    for(int i=0;i<=n;i++) add(&t,xorpref[i]);
    ll ans=0;
    for(int i=0;i<=n;i++) ans=max(ans, xorpref[i]^query(&t,xorpref[i]));
}



int nextzero[MAXN][32];
ll ansq[32*MAXN];
ll block_size;
bool cmpp(pair<int,int>p, pair<int,int>q)
{
    return make_pair(p.first/block_size, p.second) < make_pair(q.first/block_size, q.second);
}
void sb5()
{

    xorpref[0]=0;
    for(int i=1;i<=n;i++) xorpref[i]=xorpref[i-1]^a[i];
    for(int i=1;i<=n;i++) sand[0][i]=b[i];
    for(int i=1;i<logn;i++)
    {
        for(int j=1;j+(1<<i)<=n+1;j++)
        {
            sand[i][j]=sand[i-1][j]&sand[i-1][j+(1<<(i-1))];
        }
    }

    ll logg = log2(*max_element(b+1,b+n+1))+1;
    for(int i=n+1;i>0;i--)
    {
        for(int j=0;j<logg;j++)
        {
            if((b[i]&(1<<j))==0) nextzero[i][j]=i;
            else nextzero[i][j] = nextzero[i+1][j];
        }
    }

    vector<pair<int,int>>queries;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<32;j++)
        {
            if((b[i]&(1<<j))!=0) queries.emplace_back(i, nextzero[i][j]-1);
        }
    }
    sort(queries.begin(),queries.end(),cmpp);
    Trie tr;
    int cur_l=0, cur_r=-1;
    ll ans=0;
    for(auto q:queries)
    {
        while(cur_l > q.first)
        {
            cur_l--;
            add(&tr, xorpref[cur_l]);
        }
        while(cur_r < q.second)
        {
            cur_r++;
            add(&tr, xorpref[cur_r]);
        }
        while (cur_l < q.first) 
        {
            remove(&tr, xorpref[cur_l]);
            cur_l++;
        }
        while (cur_r > q.second) 
        {
            remove(&tr, xorpref[cur_r]);
            cur_r--;
        }
        ans=max(ans,getand(q.first,q.second)*(xorpref[q.first-1]^query(&tr,xorpref[q.first-1])));
    }
    cout<<ans<<endl;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    if(n<=2000)
    {
        sb1();
        return 0;
    }
    if(*max_element(a+1,a+n+1)==1 && *min_element(a+1,a+n+1)==1)
    {
        sb2();
        return 0;
    }
    if(*max_element(a+1,a+n+1)<=512)
    {
        sb3();
        return 0;
    }
    if(*max_element(b+1,b+n+1)==1 && *min_element(b+1,b+n+1)==1)
    {
        sb4();
        return 0;
    }
    sb5();
}