#include <bits/stdc++.h>

using namespace std;

int main() {
    //ios_base::sync_with_stdio(false);
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int N;
    cin >> N;
    vector<long long> A(N), B(N);
    bool Ai = true;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        if(A[i] != 1) {
            Ai = false;
        }
    }
    for (int i = 0; i < N; ++i) {
        cin >> B[i];
    }
    long long maksimum = 0;
    if(Ai == true) {
        for(int i = 0; i < N-1; i++) {
            maksimum = max(maksimum, B[i]&B[i+1]);
        }
        cout << maksimum;
    }
    else {
        vector<vector<long long>> A_S(N);
        vector<vector<long long>> B_S(N);
        for(int i = 0; i < N-1; i++) {
            A_S[i].push_back(A[i]^A[i+1]);
            B_S[i].push_back(B[i]&B[i+1]);
            for(int j = 1; j + i < N-1; j++) {
                A_S[i][j] = A_S[i][j-1]^A[i+j+1];
                B_S[i][j] = B_S[i][j-1]&B[i+j+1];
            }
        }
        for(int l = 0; l < N-1; l++) {
            for(int r = 0; r + l < N-1; r++){
                maksimum = max(maksimum, A_S[l][r]*B_S[l][r]);
            }
        }
        cout << maksimum;
    }
}