#include <bits/stdc++.h>
#define ll long long
using namespace std;
int N, glob;
int A[200006];
int B[200006];
int I[200006][36];
struct NODE
{
  int next, i;
}TRIE[2][6000006];
inline void Pre()
{
  for(int j = 0; j <= 30; j++) I[N + 1][j] = INT_MAX;
  for(int i = N; i >= 1; i--)
  {
    for(int j = 0; j <= 30; j++)
    {
      if(B[i] & (1 << j)) I[i][j] = I[i + 1][j];
      else I[i][j] = i;
    }
  }
  for(int i = 1; i <= N; i++) sort(I[i], I[i] + 31);
  return;
}
inline void Insert(int X, int i)
{
  int temp = 0, b;
  for(int j = 30; j >= 0; j--)
  {
    b = bool(X & (1 << j));
    if(!TRIE[b][temp].next)
    {
      TRIE[b][temp].next = ++glob;
      TRIE[b][temp].i = i;
      temp = glob;
    }
    else {TRIE[b][temp].i = min(i, TRIE[b][temp].i); temp = TRIE[b][temp].next;}
  }
  return;
}
inline int Find(int X, int border)
{
  int RET = 0, temp = 0, b;
  for(int j = 30; j >= 0; j--)
  {
    b = bool(X & (1 << j));
    if(TRIE[b ^ 1][temp].next && (TRIE[b ^ 1][temp].i <= border))
    {
      RET += ((b ^ 1) << j);
      temp = TRIE[b ^ 1][temp].next;
    }
    else
    {
      RET += (b << j);
      temp = TRIE[b][temp].next;
    }
  }
  return RET;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> N;
  for(int i = 1; i <= N; i++) cin >> A[i];
  for(int i = 1; i <= N; i++) cin >> B[i];
  Pre();
  Insert(0, N + 1);
  int suffix = 0;
  ll XOR, AND, sol = 0;
  for(int i = N; i >= 1; i--)
  {
    suffix ^= A[i];
    XOR = A[i];
    AND = B[i];
    sol = max(XOR * AND, sol);
    for(int j = 0; j <= 30; j++)
    {
      if((I[i][j] != i) && (I[i][j] != INT_MAX))
      {
        XOR = suffix ^ Find(suffix, I[i][j]);
        sol = max(XOR * AND, sol);
        AND &= B[I[i][j]];
      }
      else if(I[i][j] == INT_MAX) break;
    }
    if(AND)
    {
      XOR = suffix ^ Find(suffix, N + 1);
      sol = max(XOR * AND, sol);
    }
    Insert(suffix, i);
  }
  cout << sol << '\n';

  return 0;
}