#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define pb push_back

const int N = 7e6 + 2, B = 30;
int ch[N][2], sz[N], ro[N], C = 0;
void add(int ol, int nw, int x) {
    bool ex = 1;
    for (int i = B; i >= 0; --i) {
        if (ex) {
            ch[nw][(x >> i) & 1] = ++C;
            ch[nw][((x >> i) & 1) ^ 1] = ch[ol][((x >> i) & 1) ^ 1];
            sz[C] = sz[ch[ol][(x >> i) & 1]] + 1;
            nw = C, ol = ch[ol][(x >> i) & 1];
        }
        else {
            ch[nw][(x >> i) & 1] = ++C;
            sz[C] = 1;
            nw = C;
        }
        if (!ch[ol][(x >> i) & 1])  ex = 0;
    }
}
ll qry(int L, int R, int x = 0) {
    int n1 = ro[L-1], n2 = ro[R];
    int S = 0;
    for (int i = B; i >= 0; --i) {
        int b = (x >> i) & 1;
        if (sz[ch[n2][b ^ 1]] - sz[ch[n1][b ^ 1]]) {
            n2 = ch[n2][b ^ 1], n1 = ch[n1][b ^ 1];
            S += (1 << i);
        }
        else {
            n2 = ch[n2][b], n1 = ch[n1][b];
        }
    }
    return S;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n+1], px[n+1]; ro[0] = ++C; px[0] = 0;
    for (int i = B; i >= 0; --i) {
        ch[C][0] = C+1; ++C;
        sz[C] = 1;
    }
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        ro[i] = ++C, px[i] = px[i-1] ^ a[i];
        add(ro[i-1], ro[i], px[i]);
    }
    vector<array<ll, 2>> d;
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        ll b;
        cin >> b;
        for (auto &[x, y] : d)  x &= b;
        d.insert(d.begin(), {b, i});
        vector<array<ll, 2>> d2;
        for (int j = 0; j < d.size(); ++j) {
            while (j != d.size() - 1 && d[j][0] == d[j+1][0])    ++j;
            d2.pb(d[j]);
        }
        d = d2;
        int R = i;
        for (auto [x, y] : d) {
            ans = max(ans, x * qry(y-1, R-1, px[i]));
            R = y-1;
        }
    }
    cout << ans << '\n';
}