#include <bits/stdc++.h>

using namespace std;

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(n<=2000){
        int ans = 0;
        for(int i = 0; i < n; i++){
            int curra = a[i];
            int currb = b[i];
            ans = max(ans, curra*currb);
            for(int j = i-1; j >= 0; j--){
                curra^=a[j];
                currb&=b[j];
                ans = max(ans, curra*currb);
            }
        }
        cout << ans;
        return 0;
    }
    bool allone = true;

    int mx = 0;
    for(int i = 0; i < n; i++){
        mx = max(mx, b[i]);
        if(a[i]!=1) allone = false;
    }
    if(allone){
        cout << mx;
        return 0;
    }

    return 0;
}