#include <bits/stdc++.h>

#define int long long 

#define pb push_back
 
#define F first
 
#define S second
 
using namespace std;
 
const int N = 2e5 + 10;

const int mod = 1e9 + 7;

const int inf = 1e9;

const int LOG = 30;

const int K = 515;

int a[N],b[N],niz[K],logs[N],pref[N],index = 0,trie[N * LOG][2],cnt[N * LOG],st[N][LOG];

int get(int l,int r) {
	int j = logs[r - l + 1];
	return (st[l][j] & st[r - (1 << j) + 1][j]);
}

void add(int x) {
	int node = 0;
	for(int j = LOG - 1; j >= 0; j--) {
		int bit = x >> j & 1;
		if(!trie[node][bit]) trie[node][bit] = ++index;
		node = trie[node][bit];
		cnt[node]++;
	}
}

void rem(int x) {
	int node = 0;
	for(int j = LOG - 1; j >= 0; j--) {
		int bit = x >> j & 1;
		if(!trie[node][bit]) trie[node][bit] = ++index;
		node = trie[node][bit];
		cnt[node]--;
	}
}

int get(int x) {
	int res = 0,node = 0;
	for(int j = LOG - 1; j >= 0; j--) {
		int bit = x >> j & 1;
		if(cnt[trie[node][bit ^ 1]] > 0) {
			res += 1 << j;
			node = trie[node][bit ^ 1];
		}else {
			node = trie[node][bit];
		}
	}
	return res;
}
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 	int n,MX = 0;
 	cin >> n;
 	for(int i = 1; i <= n; i++) {
 		if(i > 1) logs[i] = logs[i / 2] + 1;
 		cin >> a[i];
 		MX = max(MX,a[i]);
 		pref[i] = pref[i - 1] ^ a[i];
 	}
 	for(int i = 1; i <= n; i++) {
 		cin >> b[i];
 		st[i][0] = b[i];
 	}
 	for(int j = 1; j < LOG; j++) {
 		for(int i = 1; i + (1 << (j - 1)) <= n; i++) {
 			st[i][j] = st[i][j - 1] & st[i + (1 << (j - 1))][j - 1];
 		}
 	}
 	int res = 0;
 	if(n <= 2000) {
 		for(int i = 1; i <= n; i++) {
	        int And = b[i],Xor = a[i];
	        for(int j = i; j <= n; j++) {
	            And &= b[j];
	            if(i != j) Xor ^= a[j];
	            res = max(res,And * Xor);
	        }
	    }
	    cout << res;
	    return 0;
 	}
 	if(MX <= 100) {
 		for(int i = 0; i < K; i++) niz[i] = inf;
	 	for(int i = 1; i <= n; i++) {
	 		niz[pref[i - 1]] = i;
	 		for(int j = 0; j < K; j++) {
	 			if(niz[j] != inf) {
	 				res = max(res,(j ^ pref[i]) * get(niz[j],i));
	 			}
	 		}
	 	}
	 	cout << res;
	 	return 0;
 	}
 	for(int val = 1; val <= 3; val++) {
 		int i = 1;
 		while(i <= n) {
 			while(i <= n && (b[i] & val) != val) i++;
 			if(i > n) break;
  			int l = i,r = n,ans = -1;
 			while(l <= r) {
 				int mid = (l + r) / 2;
 				if((get(i,mid) & val) == val) {
 					ans = mid;
 					l = mid + 1;
 				}else {
 					r = mid - 1;
 				}
 			}
 			for(int j = i; j <= ans; j++) {
 				add(pref[j - 1]);
 				//cout << val << " " << get(pref[j]) << " " << i << " " << j << endl;
 				res = max(res,val * get(pref[j]));
 			}
 			for(int j = i; j <= ans; j++) rem(pref[j - 1]);
 			i = ans + 1;
 		}
  	}
  	cout << res;
    return 0;
}