#include <iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    int A[N + 5], B[N + 5];
    for(int i = 1; i <= N; i++)
        cin >> A[i];
    for(int i = 1; i <= N; i++)
        cin >> B[i];
    long long prefiksxor[N + 5][N + 5] = {0}, prefiksand[N + 5][N + 5] = {0};
    long long maks = 0;
    for(int i = 1; i <= N; i++){
        prefiksxor[i][i] = A[i];
        prefiksand[i][i] = B[i];
    }
    for(int i = 1; i <= N; i++){
        for(int j = i + 1; j <= N; j++){
            prefiksxor[i][j] = prefiksxor[i][j - 1] ^ A[j];
            prefiksand[i][j] = prefiksand[i][j - 1] & B[j];
        }
    }
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            maks = max(maks, prefiksxor[i][j] * prefiksand[i][j]);
        }
    }
    cout << maks << endl;
    return 0;
}