#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    long long suma,sumb,max=0;
    cin >> n;
    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];
    for(int i = 0; i < n; i++){
        suma=a[i],sumb=b[i];
        if(b[i] == 0) continue;
        for(int j = i+1; j < n; j++){
            if((a[i] == 0 && a[j] == 0) || a[i]==a[j] || b[j] == 0) continue;
            suma^= a[j];
            sumb&= b[j];
            long long val = suma*sumb;
            if(val > max ) max = val;
        }
    }
    cout << max;
    return 0;
}