#include <iostream>
#include <algorithm>

using namespace std;

#define MAX 20000
typedef unsigned long long ull;

ull nums1[MAX],nums2[MAX];

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

  int n; cin>>n;

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

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

  ull result = 0;

  for (int l = 0;l<n;++l){
    ull xornum = nums1[l];
    ull andnum = nums2[l];
    for (int r = l;r<n;++r){
      if (r != l){
        xornum ^= nums1[r];
        andnum &= nums2[r];
      }

      result = max(result,xornum*andnum);
    }
  }

  cout<<result;

  return 0;
}