#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define debug(x) std::cout << #x << ": " << x << "\n"
#define all(v) v.begin(), v.end()
#define li(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define endl '\n'
#define mem(name,val) memset(name,val,sizeof(name))
#define min(a,b) (a<=b ? a : b)
#define max(a,b) (a>=b ? a : b)
//using u64 = uint64_t;
//using u128 = __uint128_t;

class TrieNode {
public:
    TrieNode* child[2]; // 0 1
    int maxI[2]; // 0 1 max index that has 0 or 1 on this depth

    TrieNode() {
        child[0] = nullptr;
        child[1] = nullptr;
        maxI[0] = -1;
        maxI[1] = -1;
    }
};

void insert(TrieNode* root, int a, int index) {
    TrieNode* node = root;

    for (int i = 31; i >= 0; --i) {
        int bit = (a >> i) & 1; 
        if (!node->child[bit]) {
            node->child[bit] = new TrieNode();
        }
        node->maxI[bit] = max(node->maxI[bit], index);
        node = node->child[bit];
    }
}

int query(TrieNode* root, int a, int l) {
    TrieNode* node = root;
    int maxv = 0;

    for (int i = 31; i >= 0; --i) {
        int bit = (a >> i) & 1;

        if (node->child[1 - bit] && node->maxI[1-bit] >= l) {
            maxv |= (1 << i);           
            node = node->child[1 - bit];
        } else {
            node = node->child[bit];
        }
    }
    return maxv;
}


int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);    

    int n;
    cin>>n;
    int a[n], b[n];
    li(i,0,n) cin>>a[i];
    li(i,0,n) cin>>b[i];

    int prefixxor[n]; prefixxor[0] = a[0];
    li(i,1,n) prefixxor[i] = prefixxor[i-1] ^ a[i];

    TrieNode* root = new TrieNode();
    ll maxv = a[0] * b[0];
    int pref = a[0];

    insert(root, 0, 0);
    insert(root, a[0], 0);

    vector<int> suffb(n,0); suffb[0] = b[0];
    int l = 0;
    int st = -1; // start 3

    li(i,1,n) {
        pref ^= a[i]; 

        if(b[i]!=3) st=-1;
        if(b[i] == 0){
            suffb[i] = 0;
            insert(root, pref, i);
            continue;
        }
        else if(b[i] == 3){
            if(st == -1){
                st = i;
                maxv=max(maxv, 3 * a[i]);
            }
            else{
                if(st == 0){
                    int comp = query(root, pref, st);
                    maxv=max(maxv,comp*3);
                }
                else{
                    int comp = query(root, pref, st-1);
                    maxv=max(maxv,comp*3);
                }
                
            }
        }

        if((suffb[i-1] & b[i])==0){
            suffb[i] = b[i];
            l = i;
        }
        else{
            suffb[i] = suffb[i-1] & b[i];
        }

        if(l == i){
            maxv = max(maxv, b[i]*a[i]);
        }
        else{
            if(l == 0){
                int comp = query(root, pref, l);
                maxv = max(maxv, comp * suffb[i]);
            }
            else{
                int comp = query(root, pref, l-1);
                maxv = max(maxv, comp * suffb[i]);
            }
        }
        insert(root, pref, i);
    }

    cout<<maxv;

    return 0;
}