//
// Created by Admin on 16/11/2024.
#include <sstream>

#include <iostream>
#include <vector>
#include <algorithm>
//popravi za &
//popraviti pisanje koda

std::vector<std::vector<int>> SPLIT(std::vector<int> B,int n) {
        std::vector<std::vector<int>> res;
    std::vector<int> curr;
    for (int i = 0; i < B.size(); i++) {
        if (B[i] == n) {
            if (!curr.empty()) {
                res.push_back(curr);
                curr.clear();
            }
        } else {
            curr.push_back(i); 
        }
    }
    if (!curr.empty()) {
        res.push_back(curr); 
    }
    return res;
}
long dvaniza(std::vector<int> A,std::vector<int> B) {
    std::vector<std::vector<int>> Bsplit = SPLIT(B,0);
    
    std::vector<int> B1(Bsplit.size());
    for (int i = 0; i < Bsplit.size(); i++) {
        B1[i] = B[Bsplit[i][0]];
        for (int j = 1; j < Bsplit[i].size(); j++) {
            B1[i] &= B[Bsplit[i][j]]; 
        }
    }
    
    std::vector<int> A1(Bsplit.size());
    for (int i = 0; i < Bsplit.size(); i++) {
        A1[i] = A[Bsplit[i][0]]; 
        for (int j = 1; j < Bsplit[i].size(); j++) {
            A1[i] ^= A[Bsplit[i][j]]; 
        }
    }
    
    long largest = 0;
    for (int l = 0; l < Bsplit.size(); ++l) {
        for (int r = l; r < Bsplit.size(); ++r) {
            long sumA = A1[l];
            long sumB = B1[l];
            for (int i = l + 1; i <= r; ++i) {
                sumA ^= A1[i];  
                sumB &= B1[i];  
            }
            long sum = sumA * sumB;
            if (sum > largest) {
                largest = sum;
            }
        }
    }
    
    return largest;
}
//  sumA = A1[left-1] ^ A1[right];
//sumB=B1[right] & ~B1[left - 1];
//

int main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
int n;
    std::cin>>n;
    std::vector<int> A(n);
    std::vector<int> B(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> A[i];
    }

    for (int i = 0; i < n; ++i) {
        std::cin >> B[i];
    }
    std::cout<<dvaniza(A, B);
    return 0;
}