#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll op_Xor(ll bit[])
{
    ll odg = 0;
    for (ll i = 0; i < 32; i++)
        if (bit[i])
            odg += (1 << i);
    return odg;
}
 
ll op_And(ll bit[], ll k)
{
    ll odg = 0;
    for (ll i = 0; i < 32; i++)
        if (bit[i] == k)
            odg += (1 << i);
    return odg;
}
 
ll maxAndXor(ll nizA[], ll nizB[], ll N, ll K)
{
    ll bitA[32] = { 0 };
    ll bitB[32] = { 0 };
 
    for (ll i = 0; i < K; i++) {
        for (ll j = 0; j < 32; j++) {
            if (nizA[i] & (1 << j))
                bitA[j] ^= nizA[i];
            if (nizB[i] & (1 << j))
                bitB[j]++;
        }
    }
 
    ll odg = op_And(bitB, K) * op_Xor(bitA);
 
    for (ll i = K; i < N; i++) {
 
        for (ll j = 0; j < 32; j++) {
            if (nizA[i - K] & (1 << j))
                bitA[j] ^= nizA[i-K];
            if (nizB[i - K] & (1 << j))
                bitB[j]--;
        }
 
        for (int j = 0; j < 32; j++) {
            if (nizA[i] & (1 << j))
                bitA[j] ^= nizA[i];
            if (nizB[i] & (1 << j))
                bitB[j]++;
        }
 
        odg = max(odg, op_And(bitB, K) 
                  * op_Xor(bitA));
    }
 
    return odg;
}
 
int main()
{
    ll n; cin>>n;
    ll A[n];
    ll B[n];
    
    for(ll i=0; i<n; i++){
        cin>>A[i];
    }
     
    for(ll i=0; i<n; i++){
        cin>>B[i];
    }
    
    ll maxv=0;
    for (ll k = 0; k < n; k++) {
        maxv=max(maxv,maxAndXor(A, B, n, k));
    }
    cout<<maxv;
}