#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>
#include <unordered_map>

using namespace std;

long long cA(const int& start, const int& end, vector<int>& b) {
    long long fcA = b[start];
    for (int i = start + 1;i <= end;i++) {
        fcA &= b[i];
    }
    return fcA;
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,a1=0,b1=0;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0;i < n;i++) {
        cin >> a[i];
        if (a[i] == 1)a1++;
    }
    for (int i = 0;i < n;i++) {
        cin >> b[i];
        if (b[i] == 1)b1++;
    }
    if (a1 == n) {
        int maxb = INT_MIN;
        for (const int& num : b) {
            maxb = max(maxb, num);
        }
        cout << maxb;
    }
    else if (b1 == n) {
        unordered_set<int> prevX;
        prevX.insert(0);
        int cX = 0, mX = 0;
        for (int i = 0;i < n;i++) {
            cX ^= a[i];
            for (const int& val : prevX) {
                mX = max(mX, cX ^ val);
            }
            prevX.insert(cX);
        }
        cout << mX;
    }
    else {
        unordered_map<int,int> prevX;
        prevX[0]=-1;
        long long cX = 0, maxVal = 0;
        for (int i = 0;i < n;i++) {
            cX ^= a[i];
            for (const auto& val : prevX) {
                maxVal = max(maxVal, (cX ^ val.first) * cA(val.second+1, i,b));
            }
            prevX[cX]=i;
        }
        cout << maxVal;
    }
}