#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define mp make_pair
#define parll pair<ll,ll>
#define parii pair<int,int>
#define frs first
#define sec second
#define neparno(x) (x&1)
#define parno(x) (!neparno(x))
#define lowbit(x) (x&-x)
#define nzd __gcd
#define nzs(e1,e2) ((e1*e2)/nzd(e1,e2))
#define yesno(x) cout << ((x)?"Yes\n":"No\n")
#define condcout(x,y,z) cout << ((x)?y:z) << "\n"
#define all(V) V.begin(),V.end()
#define fill(V,v) fill(all(V),v)
#define l_b(BRL,brl) lower_bound( BRL.begin(), BRL.end(), brl )-BRL.begin()-1
#define u_b(BRU,bru) upper_bound( BRU.begin(), BRU.end(), bru )-BRU.begin()
#define mod 1000000007
#define mxn 200005
#define maxk 32

struct TrieNode
{
    ll vr;
    TrieNode *p[2];
};

TrieNode *NewNode()
{
    TrieNode *t = new TrieNode;
    t->vr = 0;
    t->p[0] = t->p[1] = NULL;
    return t;
}

void Insert( TrieNode *root, ll pxor )
{
    TrieNode *t = root;
    for ( ll i = maxk-1; i >= 0; i-- )
    {
        bool val = pxor&(1ll<<i);
        if ( t->p[val] == NULL )
        {
            t->p[val] = NewNode();
        }
        t = t->p[val];
    }
    t->vr = pxor;
}

ll Query( TrieNode *root, ll pxor )
{
    TrieNode *t = root;
    for ( ll i = maxk-1; i >= 0; i-- )
    {
        bool val = pxor&(1ll<<i);
        if ( t->p[1-val] != NULL )
        {
            t = t->p[1-val];
        }
        else if ( t->p[val] != NULL )
        {
            t = t->p[val];
        }
    }
    return pxor^(t->vr);
}

ll MaxSubXOR( ll A[], ll l, ll r )
{
    TrieNode *root = NewNode();
    Insert(root,0ll);
    ll rez=INT_MIN,pxor=0;
    for ( ll i = l; i <= r; i++ )
    {
        pxor = pxor^A[i];
        Insert(root,pxor);
        rez = max( rez, Query(root,pxor) );
    }
    return rez;
}

ll n,A[mxn],B[mxn];

void Podzadatak1()
{
    ll rez = 0;
    for ( ll i = 1; i <= n; i++ )
    {
        ll txor=0,tand=B[i];
        for ( ll j = i; j <= n; j++ )
        {
            txor ^= A[j];
            tand &= B[j];
            ll trez = txor*tand;
            rez = max( rez, trez );
        }
    }
    cout << rez << "\n";
}

void Podzadatak2()
{
    ll rez = 0;
    for ( ll i = 1; i <= n; i++ )
    {
        rez = max( rez, B[i] );
    }
    cout << rez << "\n";
}

void Podzadatak4()
{
    ll rez = MaxSubXOR(A,1,n);
    cout << rez << "\n";
}

void Podzadatak5()
{
    ll rez=0,l=1,r=1;
    for ( ll k = 1; k <= 3; k++ )
    {
        for ( ll i = 1; i <= n; i++ )
        {
            if ( (B[i]&k) == k )
            {
                l = r = i;
                while ( r <= n && (B[r]&k) == k )
                {
                    r++;
                }
                if ( (r > n) || ((B[r]&k) != k) )
                {
                    r--;
                }
                rez = max( rez, k*MaxSubXOR(A,l,r) );
                i = r;
            }
        }
    }
    cout << rez << "\n";
}

int main()
{
    ios;

    cin >> n;
    bool a1=true,b1=true,b3=true;
    for ( ll i = 1; i <= n; i++ )
    {
        cin >> A[i];
        if ( A[i] != 1 )
        {
            a1 = false;
        }
    }
    for ( ll i = 1; i <= n; i++ )
    {
        cin >> B[i];
        if ( B[i] != 1 )
        {
            b1 = false;
        }
        if ( B[i] > 3 )
        {
            b3 = false;
        }
    }

    if ( n <= 2000 )
    {
        Podzadatak1();
        return 0;
    }
    if ( a1 )
    {
        Podzadatak2();
        return 0;
    }
    if ( b1 )
    {
        Podzadatak4();
        return 0;
    }
    if ( b3 )
    {
        Podzadatak5();
        return 0;
    }
    Podzadatak1();

    return 0;
}