#include <iostream>
using namespace std;

int main() {
	int N;
    cin>>N;
    int *A = new int[N]; 
    int *B = new int[N];  

    for(int i=0;i<N;++i) 
	cin>>A[i]; 
    for(int i=0;i<N;++i) 
	cin>>B[i]; 

    long long maksVred=0;  
    int trenXOR=0;
    int trenAND=-1;

    int leviPok = 0;
    for(int desniPok=0;desniPok<N;++desniPok)
	{
        trenXOR^=A[desniPok];
        if(trenAND==-1)  
            trenAND=B[desniPok];
        else
            trenAND&=B[desniPok];

        while (trenAND == 0 && leviPok <= desniPok) {
            trenXOR^=A[leviPok];
            trenAND=-1;
            
            for (int i=leviPok+1;i<=desniPok;++i) 
			{
                if (trenAND==-1)
                    trenAND=B[i];
                else
                    trenAND&=B[i];
            }
            ++leviPok;
        }

        long long vredPodniz = trenXOR * trenAND;
        maksVred = max(maksVred, vredPodniz);  
    }

    cout<<maksVred<<endl;  

    delete[] A;
    delete[] B;
    
    return 0;
}