#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define eb emplace_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define si(a) (ll)(a.size())
using namespace std;
using ld = double;
using ll = int;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pld = pair<ld,ld>;

#define mod 1
ll add(ll x,ll y){
	x+=y;
	if(x<0){
		x%=mod;
		x+=mod;
	}else{
		if(x>=mod) x%=mod;
	}
	return x;
}
ll mul(ll a,ll b){
	a = add(a,0);
	b = add(b,0);
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}


const ll maxn = 200005;
const ll maxx = 10000005;
const ll lg = 30;
ll n;
ll a[maxn];
ll b[maxn];
ll t[2][maxx],val[maxx];
ll ps[maxn];
ll root[maxn];
ll tsz = 0;
void upd(ll &v,ll vc,ll x,ll k) {
	if(!v) v = ++tsz;
	val[v] = val[vc] + 1;
	if(k==-1) return;
	bool e = (1<<k)&x;
	t[1-e][v] = t[1-e][vc];
	upd(t[e][v],t[e][vc],x,k-1);
}
ll get(ll l,ll r,ll x,ll k = 29) {
	if(k==-1) return 0;
	bool e = (1<<k)&x;
	e^=1;
	if(val[t[e][r]]-val[t[e][l]]>=1){
		return (1<<k) + get(t[e][l],t[e][r],x,k-1);
	}
	return get(t[1-e][l],t[1-e][r],x,k-1);
}
/**
3
4 5 2
0 1 3
**/

void tc(){
	cin >> n;
	upd(root[0],0,0,lg-1);
	for(ll i = 1;i<=n;i++) {
		cin >> a[i];
		ps[i] = ps[i-1]^a[i];
		upd(root[i],root[i-1],ps[i],lg-1);
	}
	for(ll i = 1;i<=n;i++) cin >> b[i];
	vector<pll> v;
	v.pb({0,0});
	long long ans = 0;
	for(ll i = 1;i<=n;i++) {
		vector<pll> w;
		ll cur = b[i];
		ll last = i;
		while(cur!=v.back().fi) {
			w.pb({cur,last});
			pll p = v.back();
			if((p.fi&cur)==p.fi) break;
			v.popb();
			last = p.sc;
			cur&=p.fi;
		}
		while(si(w)) {
			v.pb(w.back());
			w.popb();
		}
		v.pb({i+1,i+1});
		for(ll j = 1;j<si(v);j++) {
			pll p = v[j];
			pll q = v[j-1];
			long long bi = q.fi;
			ll vl,vr;
			if(q.sc>=0) vl = root[q.sc-2];
			else vl = 0;
			if(p.sc>=0) vr = root[p.sc-2];
			else vr = 0;
			long long ai = get(vl,vr,ps[i]);
			ans = max(ans,ai*bi);
		}
		v.popb();
	}
	cout<<ans<<endl;

}

int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
	int t; t = 1;
	while(t--){
		tc();
	}
	return (0-0);
}