#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define endl "\n"
#define INT_SIZE 32
struct Node{
    int vred;
    Node *niz[2];
};
Node *newNode(){
    Node *tr=new Node;
    tr->vred=0;
    tr->niz[0]=tr->niz[1]=NULL;
    return tr;
}
void insert(Node *koren,int pre_xor){
    Node *tr=koren;
    for(int i=INT_SIZE-1;i>=0;i--){
        bool vr=pre_xor&(1<<i);
        if(tr->niz[vr]==NULL)tr->niz[vr]=newNode();
        tr = tr->niz[vr];
    }tr->vred=pre_xor;
}
int query(Node *koren,int pre_xor){
    Node *tr=koren;
    for(int i=INT_SIZE-1;i>=0;i--){
        bool vr=pre_xor&(1<<i);
        if(tr->niz[1-vr]!=NULL)tr=tr->niz[1-vr];
        else if(tr->niz[vr]!=NULL)tr=tr->niz[vr];
    }return pre_xor^(tr->vred);
}
int pre_xorseg(vector<int>niz, int n){
    n=niz.size();
    Node *koren = newNode();
    insert(koren,0);
    int result=INT_MIN,pre_xor=0;
    for (int i=0;i<n;i++){
        pre_xor=pre_xor^niz[i];
        insert(koren, pre_xor);
        ll res=query(koren, pre_xor);
        if(res>result)result=res;
    }
    return result;
}
ll seg_find(vector<int> a,int l,int r){
    vector<int>niz(r-l+1);
    for(int i=l,j=0;i<=r;i++,j++){niz[j]=a[i];}
    return pre_xorseg(niz,r);
}
void solve(){
    int n,mx=0;cin>>n;ll ans=0LL;
    vector<int>a(n);
    for(int i=0;i<n;i++){cin>>a[i];}
    vector<int>b(n);
    for(int i=0;i<n;i++){cin>>b[i];mx=max(mx,b[i]);}
    for(int i=mx;i>0;i--){
        int l=-1,r=0;ll res=0LL;
        for(int j=0;j<n;j++){
            if((b[j]&i)==i){
                r++;
                if(l==-1){l=j;r=l;}
            }
            else if(l!=-1){
                ll res=seg_find(a,l,r);
                ans=max(ans,(res*i));
                l=-1;r=0;
            }
        }
        if(l!=-1){
            ll res=seg_find(a,l,r);
            ans=max(ans,(res*i));
            l=-1;r=0;
        }
    }cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t=1;//cin>>t;
    while(t--)solve();
    return 0;
}