#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>

using namespace std;

const int MAXN = 2e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;

vector<int> segand(MAXN<<2);
vector<int> segxor(MAXN<<2);
vector<int> a(MAXN);
vector<int> b(MAXN);

void andbuild(int nod, int tl, int tr)
{
    if(tl == tr)
    {
        segand[nod] = b[tl];
        return;
    }
    int mid = tl+tr>>1;
    andbuild(nod<<1, tl, mid);
    andbuild(nod<<1|1, mid+1, tr);
    segand[nod] = segand[nod<<1] & segand[nod<<1|1];
}

void xorbuild(int nod, int tl, int tr)
{
    if(tl == tr)
    {
        segxor[nod] = a[tl];
        return;
    }
    int mid = tl+tr>>1;
    xorbuild(nod<<1, tl, mid);
    xorbuild(nod<<1|1, mid+1, tr);
    segxor[nod] = segxor[nod<<1] ^ segxor[nod<<1|1];
}

int xorquery(int nod, int tl, int tr, int l, int r)
{
    if(tl > r || tr < l)return 0;
    if(tl >= l && tr <=r)return segxor[nod];
    int mid = tl+ tr>>1;
    return xorquery(nod<<1, tl, mid, l, r) ^ xorquery(nod<<1|1, mid+1, tr, l,r);
}

int andquery(int nod, int tl, int tr, int l, int r)
{
    if(tl > r || tr < l)return (1<<62)-1;
    if(tl >= l && tr <=r)return segand[nod];
    int mid = tl+ tr>>1;
    return andquery(nod<<1, tl, mid, l, r) & andquery(nod<<1|1, mid+1, tr, l,r);
}

signed main()
{
    ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
    int tt=1;
    ///cin >> tt;
    while(tt--)
    {
        int n;
        cin >> n;

        bool testcase1 = true;
        bool testcase2 = true;
        for(int i=0; i<n; i++)
        {
            cin >> a[i];
            if(a[i] !=1)testcase1 = 0;
        }
         for(int i=0; i<n; i++)
        {
            cin >> b[i];
            if(b[i] !=1)testcase2 = 0;
        }
        xorbuild(1,0,n-1);
        andbuild(1,0,n-1);
        if(n<=2000)
        {
            long long rez = 0;
            for(int i=0; i<n; i++)
            {
                for(int j=i+1; j<n;j++)
                {
                    rez = max(rez,xorquery(1,0,n-1,i,j) * andquery(1,0,n-1,i,j));
                }
            }
            cout << rez << endl;
        }
        else if(testcase1)
        {
            long long rez = 0;
            for(int i=0; i<n; i++)
            {
                rez = max(rez, b[i]);
            }
            cout << rez << endl;
        }
        else if(testcase2)
        {

        }

    }
}