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

using namespace std;

int main() {
    int n;
    cin >> n;

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

    int maxVrednost = 0;

    for (int start = 0; start < n; ++start) {
        int xorA = 0;
        int andB = b[start];
        
        for (int end = start; end < n; ++end) {
            xorA ^= a[end];
            andB &= b[end]; 
            
            if (andB == 0) break;

            int vrednost = xorA * andB;
            maxVrednost = max(maxValue, value);
        }
    }

    cout << maxVrednost << endl;

    return 0;
}