#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];
    }
    
   
    vector<int> prefixXor(N + 1, 0), prefixAnd(N + 1, ~0);  // ~0 ?? ??? ?????? ?? 1
    
    
    for (int i = 0; i < N; i++) {
        prefixXor[i + 1] = prefixXor[i] ^ A[i];
        prefixAnd[i + 1] = prefixAnd[i] & B[i];
    }
    
    long long maxVal = 0;
    for (int L = 0; L < N; L++) {
        int currentXor = 0;
        int currentAnd = ~0;
        
        for (int R = L; R < N; R++) {
           
            currentXor ^= A[R];  
            currentAnd &= B[R]; 
            
            
            long long value = (long long) currentXor * currentAnd;
            maxVal = max(maxVal, value);
        }
    }
    
    
    cout << maxVal << endl;
    
    return 0;
}