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

using namespace std;

unsigned int akcija(int l, int r, vector<unsigned int> aa, vector<unsigned int> bb) {

    unsigned int pom_xor, pom_and;

    pom_xor = aa[l-1];
    pom_and = bb[l-1];

    for (int i=l; i<r; i++){
        pom_xor = pom_xor^aa[i];
        pom_and = pom_and&bb[i];
    };

    return pom_xor*pom_and;
}

int main()
{


    int n;

    vector <unsigned int> a;
    vector <unsigned int> b;

    cin >> n;

    unsigned int pom;

    for (int i=0; i<n; i++){
        cin >> pom;
        a.push_back(pom);
    };

    for (int i=0; i<n; i++){
        cin >> pom;
        b.push_back(pom);
    };

    unsigned int maks;

    //maks = akcija(1, 1, a, b);
    maks = 0;

    for (int l=1; l<n+1; l++){
        for (int r=l; r<n+1; r++){
            if (akcija(l, r, a, b) > maks){
                maks = akcija(l, r, a, b);
            };
        };
    };


    cout << maks;


    return 0;
}