#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> os;
typedef unsigned long long ull;
typedef long long ll;
class Cvor{
public:
    Cvor* kec = nullptr;
    Cvor* nula = nullptr;
};
class Trie{
public:
    Cvor* koren;
    Trie() {
        koren = new Cvor();
    }
    void dodaj(int br){
        Cvor* tr = koren;
        for(int bit = 30;bit>=0;bit--){
            if((br>>bit)&1){
                if(tr->kec==nullptr)tr->kec = new Cvor();
                tr = tr->kec;
            }
            else{
                if(tr->nula==nullptr)tr->nula = new Cvor();
                tr = tr->nula;
            }
        }
    }
};
int resi(int start, int kraj, vector<int> a){
    Trie trie;
    trie.dodaj(0);
    int mx = 0;
    int tr = 0;
    for(int i = start;i<=kraj;i++){
        tr^=a[i];
        int xr = 0;
        Cvor* trcvor = trie.koren;
        for(int bit = 30;bit>=0;bit--){
            if((tr>>bit)&1){
                if(trcvor->nula!=nullptr)trcvor=trcvor->nula;
                else{
                    xr|=(1<<bit);
                    trcvor = trcvor->kec;
                }
            }
            else{
                if(trcvor->kec!=nullptr){
                    xr|=(1<<bit);
                    trcvor = trcvor->kec;
                }
                else trcvor = trcvor->nula;
            }
        }
        mx = max(mx, xr ^ tr);
        trie.dodaj(tr);
    }
    return mx;
}
int main(){
    ios;
    int n;
    cin>>n;
    vector<int> a(n), b(n);
    bool podzadatak2 = true;
    bool podzadatak4 = true;
    bool podzadatak5 = true;
    for(int i = 0;i<n;i++){
        cin>>a[i];
        if(a[i]!=1)podzadatak2=false;
    }
    for(int i = 0;i<n;i++){
        cin>>b[i];
        if(b[i]!=1)podzadatak4 = false;
        if(b[i]>3)podzadatak5 = false;
    }
    if(n<=2000){
        ll mx = 0;
        for(int i = 0;i<n;i++){
            int xr = 0;
            int nd = b[i];
            for(int j = i;j<n;j++){
                xr^=a[j];
                nd&=b[j];
                ll res = (ll)xr * (ll)nd;
                mx = max(mx, res);
            }
        }
        cout<<mx<<endl;
        return 0;
    }
    if(podzadatak2){
        int mx = 0;
        for(int i = 0;i<n;i++)mx = max(mx, b[i]);
        cout<<mx<<endl;
        return 0;
    }
    if(podzadatak4){
        int res = resi(0, n-1, a);
        cout<<res<<endl;
        return 0;
    }
    if(podzadatak5){
        vector<pair<int,int>> dvojke;
        vector<pair<int,int>> trojke;
        vector<pair<int,int>> kecevi;
        int l = 0;
        while(l<n){
            if(b[l]==2||b[l]==3){
                int r = l;
                while(r<n&&b[r]==2||b[r]==3)r++;
                r--;
                dvojke.pb({l, r});
                l = r + 1;
            }
            else l++;
        }
        l = 0;
        while(l<n){
            if(b[l]==1||b[l]==3){
                int r = l;
                while(r<n&&b[r]==1||b[r]==3)r++;
                r--;
                kecevi.pb({l, r});
                l = r + 1;
            }
            else l++;
        }
        l = 0;
        while(l<n){
            if(b[l]==3){
                int r = l;
                while(r<n&&b[r]==3)r++;
                r--;
                trojke.pb({l, r});
                l = r + 1;
            }
            else l++;
        }
        ll res = 0;
        for(pair<int,int> p : kecevi){
            ll r1 = (ll)resi(p.first, p.second, a);
            res = max(res, r1);
        }
        for(pair<int,int> p : dvojke){
            ll r1 = 2ll * (ll)resi(p.first, p.second, a);
            res = max(res, r1);
        }
        for(pair<int,int> p : trojke){
            ll r1 = 3ll * (ll)resi(p.first, p.second, a);
            res = max(res, r1);
        }
    }

}