#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define PI acos(-1)
#define LSB(i) ((i) & -(i))
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define sc second
#define th third
#define fo fourth
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
#define INF 1e15
#define MOD 1000000007
#define endl "\n"

#define all(data)       data.begin(),data.end()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()
#define MAXN 200007
ll a[MAXN],b[MAXN],lst[507],prefxor[MAXN],tr[MAXN*30][2],nxt;
bool checka1=true,checka500=true,checkb1=true,checkb3=true;
void Add(ll x)
{
    string s=bitset<30>(x).to_string();
    ll y=0;
    for(int i=0;i<30;i++)
    {
        if(!tr[y][s[i]-'0']) y=tr[y][s[i]-'0']=nxt++;
        else y=tr[y][s[i]-'0'];
    }
}
ll Query(ll x)
{
    string s=bitset<30>(x).to_string();
    ll y=0,rez=0;
    for(int i=0;i<30;i++)
    {
        if(tr[y][s[i]-'0']) {y=tr[y][s[i]-'0']; rez+=(s[i]-'0')*(1<<(29-i));}
        else {y=tr[y][1-(s[i]-'0')]; rez+=(1-(s[i]-'0'))*(1<<(29-i));}
    }
    return rez;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    ll n; cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]!=1) checka1=false;
        if(a[i]>500) checka500=false;
    }
    for(int i=1;i<=n;i++)
    {
        cin>>b[i];
        if(b[i]!=1) checkb1=false;
        if(b[i]>3) checkb3=false;
    }
    if(n<=2007)
    {
        ll rez=0;
        for(int l=1;l<=n;l++)
        {
            ll aa=0,bb=1;
            for(int r=l;r<=n;r++) {aa^=a[r]; bb&=b[r]; rez=max(rez,aa*bb);}
        }
        cout<<rez<<endl;
    }
    else if(checka1)
    {
        ll rez=0;
        for(int i=1;i<=n;i++) rez=max(rez,b[i]);
        cout<<rez<<endl;
    }
    else if(checka500)
    {
        ll rez=0;
        for(int l=1;l<=n;l++)
        {
            ll aa=0,bb=1;
            for(int r=l;r<=min(n,(ll)(l+512));r++) {aa^=a[r]; bb&=b[r]; rez=max(rez,aa*bb);}
        }
        cout<<rez<<endl;
    }
    else if(checkb1)
    {
        ll rez=0; prefxor[0]=0; Add(0);
        for(int i=1;i<=n;i++)
        {
            prefxor[i]=prefxor[i-1]^a[i];
            ll c=((1<<30)-1)^prefxor[i];
            rez=max(rez,prefxor[i]^Query(c));
            Add(prefxor[i]);
        }
        cout<<rez<<endl;
    }
    else
    {
        ll rez=0;
        for(int l=1;l<=n;l++)
        {
            ll aa=0,bb=1;
            for(int r=l;r<=min(n,(ll)(l+1000));r++) {aa^=a[r]; bb&=b[r]; rez=max(rez,aa*bb);}
        }
        cout<<rez<<endl;
    }
    return 0;
}