#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

const int N = 2e5 + 3;
const int logn = 19;
const int bits = 31;
int n;
int lg[N];
ll a[N], b[N], pref[N], andd[N], up[N][logn];

struct triestruct {
    int m[2], mx;
    void clearr() {
        m[0] = -1; m[1] = -1; mx = -1;
    }
    int& operator [] (const int& i) {
        return m[i];
    }
};
int sz = 1;
triestruct tr[bits * N];

void insertt(int x, int ind, int t = 0) {
    for (int bit = bits - 1; bit >= 0; bit--) {
        bool b = (x & (1 << bit)) > 0;
        if (tr[t][b] == -1) {
            tr[t][b] = sz;
            tr[sz].clearr(); tr[sz].mx = ind;
            sz++;
        }
        t = tr[t][b];
        tr[t].mx = max(tr[t].mx, ind);
    }
}

ll maxx(int x, int l, int r, int t = 0) {
    ll ans = 0;
    for (int bit = bits - 1; bit >= 0; bit--) {
        bool b = (x & (1 << bit)) > 0;
        if (tr[t][!b] == -1) {
            t = tr[t][b];
            if (tr[t].mx < l)
                return 0ll;
        } else if (tr[t][b] == -1) {
            t = tr[t][!b];
            ans += (1 << bit);
            if (tr[t].mx < l)
                return 0ll;
        } else if (tr[tr[t][!b]].mx >= l) {
            ans += (1 << bit);
            t = tr[t][!b];
        } else {
            t = tr[t][b];
            if (tr[t].mx < l)
                return 0ll;
        }
    }

    return ans;
}

void solve() {
    tr[0].clearr();
    cin >> n;
    lg[1] = 0;
    for (int i = 2; i <= n; i++)
        lg[i] = lg[i/2]+1;
    for (int i = 1; i <= n; i++) cin >> a[i], pref[i] = pref[i-1] ^ a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) {
        up[i][0] = b[i-1];
        for (int j = 1; j < logn; j++) {
            up[i][j] = up[i][j-1] & up[max(0, i-(1<<(j-1)))][j-1];
        }
    }

    insertt(0, 0, 0);
    vector<pair<int, int>> vec;
    ll ans = 0;

    for (int r = 1; r <= n; r++) {
        vec.clear();
        int rig = r; andd[r] = b[r];
        while (rig > 0) {
            int lef = rig;
            ll poc = andd[rig];
            for (int j = lg[lef]; j >= 0; j--) {
                if (rig-(1<<j) <= 0) continue;
                if ((poc&up[rig][j]) == poc) {
                    rig -= (1<<j);
                }
            }
            swap(lef, rig);
            vec.push_back({lef, rig});
            andd[lef-1] = poc & b[lef-1];
            rig = lef-1;
        }
        for (auto [lef, rig] : vec) {
            ans = max(ans, andd[rig] * maxx(pref[r], lef-1, rig-1, 0));
        }
        insertt(pref[r], r, 0);
    }

    cout << ans << "\n";
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
	int t=1; //cin >> t;
	while (t--) {
        solve();
	}
}