#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 200000 * 30;

int n;

int trie[N][2];
int sum[N];
int cnt = 1;

void add(int x, int t) {
    int p = 1;
    sum[p] += t;
    for (int i = 29; i >= 0; i--) {
        int d = x >> i & 1;
        if (!trie[p][d]) {
            trie[p][d] = ++cnt;
        }
        p = trie[p][d];
        sum[p] += t;
    }
}

int query(int x) {
    int ans = 0;
    int p = 1;
    for (int i = 29; i >= 0; i--) {
        int d = x >> i & 1;
        if (sum[trie[p][!d]]) {
            p = trie[p][!d];
            ans |= 1 << i;
        } else {
            p = trie[p][d];
        }
    }
    return ans;
}

int mx = 200005;

vector<int> a(mx);

vector<int> b(mx);

struct sparse{
    int spars[200005][20];
    void build() {
        for(int i = 1; i <= n; i++) {
            spars[i][0] = b[i];
        }
        for(int j = 1; (1LL << j) <= n; j++) {
            for(int i = 1; i <= n; i++) {
                spars[i][j] = (spars[i][j - 1] & spars[i + (1LL << (j - 1))][j - 1]);
            }
        }
    }
    int query(int l, int r) {
        int logaritam = log2(r - l + 1);
        return (spars[l][logaritam] & spars[r - (1LL << logaritam) + 1][logaritam]);
    }
}sp;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    //add(0, 1);
    for(int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    sp.build();
    if(n <= 2000) {
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            int endic = b[i];
            int kxor = 0;
            for(int j = i; j <= n; j++) {
                endic &= b[j];
                kxor ^= a[j];
                ans = max(ans, endic * kxor);
            }
        }
        cout << ans;
        return 0;
    }
    int subtask2 = 1;
    for(int i = 1; i <= n; i++) {
        if(a[i] != - 1) {
            subtask2 = 0;
        }
    }
    if(subtask2) {
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            ans = max(ans, b[i]);
        }
        cout << ans;
        return 0;
    }
    int subtask3 = 1;
    for(int i = 1; i <= n; i++) {
        if(a[i] > 500) {
            subtask3 = 0;
        }
    }
    if(subtask3) {
        // fiksiram xor koji je maximalno 512
        vector<int> pref(n + 1, 0);
        for(int i = 1; i <= n; i++) {
            pref[i] = (pref[i - 1] ^ a[i]);
        }
        int ans = 0;
        for(int ksor = 1; ksor <= 569; ksor++) {
            vector<int> last(2002, - 1);
            int poui = 0;
            for(int i = 1; i <= n; i++) {
                last[pref[i - 1]] = i;
                // prefj ^ prefi-1 = ksor
                // ksor ^ prefj = prefi-1
                int broj = (pref[i] ^ ksor);
                int index = last[broj];
                //cout << broj << " " << index << "\n";
                if(index == - 1) {
                    continue;
                }
                poui = max(poui, sp.query(index, i));
            }
            ans = max(ans, poui * ksor);
        }
        cout << ans;
        return 0;
    }
    int subtask4 = 1;
    for(int i = 1; i <= n; i++) {
        if(b[i] != - 1) {
            subtask4 = 0;
        }
    }
    if(subtask4) {
        int ans = 0;
        vector<int> pref(n + 1, 0);
        for(int i = 1; i <= n; i++) {
            pref[i] = (pref[i - 1] ^ a[i]);
        }
        for(int i = 1; i <= n; i++) {
            add(pref[i - 1], 1);
            ans = max(ans, query(pref[i]));
        }
        cout << ans;
        return 0;
    }
    // bi <= 3
    // fiksiram and
    int ans = 0;
    // and 1 -
    int i = 1;
    vector<int> pref(n + 1, 0);
    for(int i = 1; i <= n; i++) {
        pref[i] = (pref[i - 1] ^ a[i]);
    }
    while(i <= n) {
        if(b[i] != 3) {
            i += 1;
            continue;
        }
        int l = i;
        int r = i;
        while(r <= n && b[r] == 3) {
            r += 1;
        }
        r -= 1;
        int mx = 0;
        for(int j = l; j <= r; j++) {
            add(pref[j - 1], 1);
            mx = max(mx, query(pref[j]));
        }
        for(int j = l; j <= r; j++) {
            add(pref[j - 1], -1);
        }
        //cout << l << " " << r << " " << mx << "\n";
        ans = max(ans, mx * 3);
        r += 1;
        i = r;
    }
    // sad and 2
    i = 1;
    while(i <= n) {
        if(b[i] != 2 && b[i] != 3) {
            i += 1;
            continue;
        }
        int ok = 0;
        int l = i;
        int r = i;
        while(r <= n && (b[r] == 2 || b[r] == 3)) {
            if(b[r] == 2) {
                ok = 1;
            }
            r += 1;
        }
        r -= 1;
        if(ok) {
            int u = 0;
            for(int j = l; j <= r; j++) {
                add(pref[j - 1], 1);
                u = max(u, query(pref[j]));
            }
            for(int j = l; j <= r; j++) {
                add(pref[j - 1], -1);
            }
            //cout << l << " " << r << " " << u << "\n";
            ans = max(ans, u * 2);
        }
        r += 1;
        i = r;
    }
    i = 1;
    while(i <= n) {
        if(b[i] != 1 && b[i] != 3) {
            i += 1;
            continue;
        }
        int l = i;
        int r = i;
        int ok = 0;
        while(r <= n && (b[r] == 1 || b[r] == 3)) {
            if(b[r] == 1) {
                ok = 1;
            }
            r += 1;
        }
        r -= 1;
        //cout << l << " " << r << "\n";
        if(ok) {
            //cout << l << " " << r << "\n";
            int u = 0;
            for(int j = l; j <= r; j++) {
                add(pref[j - 1], 1);
                u = max(u, query(pref[j]));
            }
            for(int j = l; j <= r; j++) {
                add(pref[j - 1], - 1);
            }
            //cout << l << " " << r << " " << u << "\n";
            ans = max(ans, u);
        }
        r += 1;
        i = r;
    }
    cout << ans;
}