#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 2e5+5;
const int inf = (1ll<<31)-1;



struct Node{
	int value = 0;
	Node *l = nullptr, *r = nullptr;
};
Node trie{1<<30};

void insert(int x){
	int m = 1<<30;
	Node *s;
	while(m > 0){
		if(x&m){
			if(s->r==nullptr){
				s->r = new Node{m>>1};
			}
			s = s->r;
		}
		else{
			if(s->l==nullptr){
				s->l = new Node{m>>1};
			}
			s = s->l;
		}
		m >>= 1;
	}
}

int parse(int x){
	int r = 0;
	int m = 1<<30;
	Node *s;
	while(m > 0){
		if(x&m){
			if(s->l==nullptr){
				s = s->r;
			}
			else{
				s = s->l;
				r += m;
			}
		}
		else{
			if(s->r==nullptr){
				s = s->r;
			}
			else{
				s = s->l;
				r += m;
			}
		}
		m >>= 1;
	}
	return r;
}



int n;
int a[MAXN], b[MAXN];

void solve(){
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	for(int i = 0; i < n; ++i){
		cin >> b[i];
	}
	if(n <= 2005){
		int r = 0;
		for(int i = 0; i < n; ++i){
			int x = 0, y = inf;
			for(int j = i; j < n; ++j){
				x ^= a[j];
				y &= b[j];
				r = max(r, x*y);
			}
		}
		cout << r << '\n';
		return;
	}
	bool da = 1;
	for(int i = 0; i < n; ++i){
		if(a[i]!=1){
			da = 0;
			break;
		}
	}
	if(da){
		int r = 0;
		for(int i = 0; i < n; ++i){
			r = max(r, b[i]);
		}
		cout << r << '\n';
		return;
	}

	da = 1;
	for(int i = 0; i < n; ++i){
		if(b[i]!=1){
			da = 0;
			break;
		}
	}
	if(da){
		int r = 0;
		int p = 0;
		insert(0);
		for(int i = 0; i < n; ++i){
			p ^= a[i];
			r = max(r, parse(p));
			insert(p);
		}
		cout << r << '\n';
		return;
	}
	cout << 5;
}

int32_t main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int qqq=1;
	//cin>>qqq;
	while(qqq--)solve();
	return 0;
}