#include <iostream>
#include <vector>
using namespace std;


bool f(vector < int > & v)
{
    for(auto it : v)
    {
        if(it != 1) return false;
    }
    return true;
}

int g(vector < int > & v)
{
    int maxi = 0;
    for(auto it : v) maxi = max(maxi, it);
    return maxi;
}

int main()
{
    int n; cin >> n;
    vector < int > a(n);
    vector < int > b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];

    if(f(a)) return cout << g(b) << "\n", 0;

    long long ans = 0;

    for(int i = 0; i < n; i++)
    {
        long long val1 = a[i];
        long long val2 = b[i];
        ans = max(ans, val1 * val2);
        for(int j = i - 1; j >= 0; j--)
        {
            val1 ^= a[j];
            val2 &= b[j];
            ans = max(ans, val1 * val2);
        }
    }

    cout << ans << "\n";

    return 0;
}