using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Perica___Nizovi___takmicenje
{
    class Program
    {
        static int uDekadno(string s)
        {
            string[] s1 = s.Split();
            int n = 0;
            for (int i = 0; i < s1.Length - 1; i++)
            {
                n = n + (int)Math.Pow(2, i) * int.Parse(s1[i]);
            }
            return n;
        }
        static string uBinaran(int n)
        {
            string b = "";
            for (int i = n; i > 0;)
            {
                if (i % 2 == 0) b = b + "0 ";
                if (i % 2 == 1) b = b + "1 ";
                i = i / 2;
            }
            return b;
        }

        static string XOR(string s1, string s2)
        {
            string[] S1 = s1.Split();
            string[] S2 = s2.Split();

            int min = Math.Min(S1.Length, S2.Length);
            int max = Math.Max(S1.Length, S2.Length);
            max--;
            min--;
            string s = "";
            string x = "";
            for (int i = 0; i < min; i++)
            {
                if (S1[i] == S2[i]) s += "0 ";
                else s += "1 ";
            }
            for (int i = min; i < max; i++)
            {
                if (max == S1.Length) x = S1[i];
                else x = S2[i];
                if (x == "0") s += "0 ";
                else s += "1 ";
            }
            return s;
        }

        static string AND(string s1, string s2)
        {
            string[] S1 = s1.Split();
            string[] S2 = s2.Split();

            int min = Math.Min(S1.Length, S2.Length);
            int max = Math.Max(S1.Length, S2.Length);
            max--;
            min--;
            string s = "";
            string x = "";
            for (int i = 0; i < min; i++)
            {
                if (S1[i] == S2[i] && S1[i] == "1") s += "1 ";
                else s += "0 ";
            }
            for (int i = min; i < max; i++)
            {
                s += "0 ";
            }
            return s;
        }

        static string operacija1(int[] A, int l, int d)
        {
            string s = uBinaran(A[l]);
            while (l<d)
            {
                s = XOR(s, uBinaran(A[d]));
                d--;
            }
            return s;
        }

        static string op1(int[] A, int l, int d)
        {
            string s = uBinaran(A[l]);
            while (l < d)
            {
                s = XOR(s, uBinaran(A[d]));
                d--;
            }
            return s;
        }

        static string op2(int[] B, int l, int d)
        {
            string s = uBinaran(B[l]);
            while (l < d)
            {
                s = AND(s, uBinaran(B[d]));
                d--;
            }
            return s;
        }
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            
            string[] s1 = Console.ReadLine().Split();
            string[] s2 = Console.ReadLine().Split();
            
            int[] A = new int[N];
            int[] B = new int[N];
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(s1[i]);
            }
            for (int i = 0; i < N; i++)
            {
                B[i] = int.Parse(s2[i]);
            }
            int max = 0;
            for (int l = 0; l < N; l++)
            {
                for (int d = N-1; d>l; d--)
                {
                    int n = uDekadno(op1(A, l, d)) * uDekadno(op2(B, l, d));
                    if (n > max) max = n;
                }
            }
            Console.WriteLine(max);
        }
    }
}