program x;

var a,b:array[1..20000] of integer;
    n,i,max,r,l,br,axor,band:integer;

function binarify(a:integer):string;
var s:string;
begin
    s:='';
    if a=0 then binarify:='0'
    else begin
        while a<>1 do begin
            if a mod 2=0 then s:='0'+s
            else s:='1'+s;
            a:=a div 2;
        end;
        s:='1'+s;
        binarify:=s;
    end;
end;

function two_to(r:integer):integer;
var a:integer;
begin
    a:=1;
    for i:=1 to r-1 do a:=a*2;
    two_to:=a;
end;

function debinarify(s:string):integer;
var a,i:integer;
begin
    a:=0;
    for i:=1 to length(s) do
        if s[length(s)+1-i]='1' then 
            a:=a+two_to(i);
    debinarify:=a;
end;

function intxor(a,b:integer):integer;
var x,y,z:string;
    i:integer;
    b1,b2:boolean;
begin
    x:=binarify(a);
    y:=binarify(b);
    if length(x)>length(y) then begin
        z:=copy(x,1,length(x)-length(y));
        delete(x,1,length(x)-length(y));
    end else begin
        z:=copy(y,1,length(y)-length(x));
        delete(y,1,length(y)-length(x));
    end;
    for i:=1 to length(x) do begin
        if x[i]='1' then b1:=true
        else b1:=false;
        if y[i]='1' then b2:=true
        else b2:=false;
        if (b1 xor b2) then z:=z+'1'
        else z:=z+'0';
    end;
    intxor:=debinarify(z);
end;

function intand(a,b:integer):integer;
var x,y,z:string;
    i:integer;
    b1,b2:boolean;
begin
    x:=binarify(a);
    y:=binarify(b);
    z:='';
    if length(x)>length(y) then 
        delete(x,1,length(x)-length(y))
    else if length(x)<length(y) then
        delete(y,1,length(y)-length(x));
    for i:=1 to length(x) do begin
        if x[i]='1' then b1:=true
        else b1:=false;
        if y[i]='1' then b2:=true
        else b2:=false;
        if (b1 and b2) then z:=z+'1'
        else z:=z+'0';
    end;
    intand:=debinarify(z);
end;

begin
    read(n);
    for i:=1 to n do read(a[i]);
    for i:=1 to n do read(b[i]);
    max:=0;
    for l:=1 to n-1 do
        for r:=l to n do begin
            if r=l then br:=a[r]*b[r]
            else begin
                axor:=a[r];
                band:=b[r];
                for i:=r-1 to l do begin
                    axor:=intxor(axor,a[i]);
                    band:=intand(band,b[i]);
                end;
                br:=axor*band;
            end;
            if br>max then max:=br;
        end;
    writeln(max);
end.