#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n, vr, i, kraj, pocetak, xorvr, andvr, maxvr = 0;
    cin >> n;

    vector<int> a(n), b(n);

    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    for (i = 0; i < n; i++)
    {
        cin >> b[i];
    }

    for (pocetak = 0; pocetak < n; pocetak++)
    {
        xorvr = 0;
        andvr = b[pocetak];

        for (kraj = pocetak; kraj < n; kraj++)
        {
            xorvr ^= a[kraj];
            andvr &= b[kraj];

            vr = xorvr * andvr;

            maxvr = max(maxvr, vr);
        }
    }

    cout << maxvr << endl;

    return 0;
}