#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>

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;

  ull maxNum = 0;

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

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

  int to = log2(maxNum);

  ull weights1[n] = {0};
  ull weights2[n] = {0};

  for (int i = 0; i<=to;++i){
    ull actualI = pow(2,i);
    int total = 0;

    for (int j = 0;j<n;++j){
      ull num = nums2[j];
      bool isSetBit = (num & actualI) != 0;
      
      if (isSetBit){
        ++total;
      }else{
        total=0;
      }

      weights2[j]+= (ull) total*actualI;
    }

    total = 0;
    bool isLastSet;

    for (int j = 0;j<n;++j){
      ull num = nums2[j];
      bool isSetBit = (num & actualI) != 0;

      if (j == 0 || isSetBit != isLastSet){
        ++total;
      }else{
        total=1;
      }
      weights1[j]+=(ull) total*actualI;
      isLastSet = isSetBit;
    }
  }

  /*for (int num: weights1){
    cout<<num<<' ';
  }
  cout<<'\n';

  for (int num: weights2){
    cout<<num<<' ';
  }

  cout<<'\n';*/

  ull maxNumber = 0;
  ull maxIndex = 0;

  for (int i = 0; i<n; ++i){
    ull weight1 = weights1[i];
    ull weight2 = weights2[i];

    ull add = weight1+weight2;

    if (add > maxNumber){
      maxIndex = i;
      maxNumber = add;
    }
  }

  ull xornum = nums1[maxIndex];
  ull andnum = nums2[maxIndex];
  ull result = xornum*andnum;

  for (int i = maxIndex-1; i>=0; i--){
    xornum ^= nums1[i];
    andnum &= nums2[i];

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

  cout<<result;

  return 0;
}