using System;

class Program
{
    static void Main()
    {
        int N = Convert.ToInt32(Console.ReadLine());
        int[] A = new int[N + 1];
        int[] B = new int[N + 1];

        string[] inputA = Console.ReadLine().Split(' ');
        for (int i = 1; i <= N; i++)
        {
            A[i] = Convert.ToInt32(inputA[i - 1]);
        }

        string[] inputB = Console.ReadLine().Split(' ');
        for (int i = 1; i <= N; i++)
        {
            B[i] = Convert.ToInt32(inputB[i - 1]);
        }

        int maxValue = CalculateMaxValue(A, B, N);
        Console.WriteLine(maxValue);
    }

    static int CalculateMaxValue(int[] A, int[] B, int N)
    {
        int maxValue = int.MinValue;

        for (int L = 1; L <= N; L++)
        {
            int xorValue = 0;
            int andValue = -1;

            for (int R = L; R <= N; R++)
            {
                xorValue ^= A[R];
                andValue &= B[R];
                int currentValue = xorValue * andValue;

                if (currentValue > maxValue)
                {
                    maxValue = currentValue;
                }
            }
        }

        return maxValue;
    }
}