#include <iostream>
#include <algorithm>

using namespace std;

#define MAX 20000
typedef long long ll;

ll niz1[MAX],niz2[MAX];
int n;

ll solve(int l, int r, ll numl, ll numr, bool increasedL, bool increasedR){
  if (l > r || r >= n) return 0;

  if (l == r){

  }

  if (numl == -1){
    numl = niz1[l];
    numr = niz2[l];
  }else{
    if (increasedL){
      numl ^= niz1[l-1];
      int newNum = niz2[l];
      for (int i = l+1; i<=r; ++i){
        newNum &= niz2[i];
      }
      numr = newNum;
    }

    if (increasedR){
      numl ^= niz1[r];

      if (!increasedL){
        numr &= niz2[r];
      }
    }
  }
  ll num = numl*numr;
  return max(num,max(solve(l+1,r,numl,numr,true,false),max(solve(l,r+1,numl,numr,false,true),solve(l+1,r+1,numl,numr,true,true))));
}

int main(){
  ios_base::sync_with_stdio(false),cin.tie(0);

  cin>>n;

  for (int i = 0;i<n;++i){
    cin>>niz1[i];
  }

  for (int j = 0;j<n;++j){
    cin>>niz2[j];
  }

  cout<<solve(0,0,-1,-1,false,false);

  return 0;
}