N=int(input()) X=list(map(int,input().split())) A=list(map(int,input().split())) result=sum(A) z=sum(A) v=[0]*N for i in range(N): v[i]=v[i-1]^A[i] k=[0]*N for i in range(N): k[i]=k[i-1]+A[i] dp=[0]*N for i in range(1,N): score=0 for j in range(i): w=k[i] if j>0: w-=k[j-1] u=v[i] if j>0: u^=v[j-1] ans=w-u-(X[i]-X[j]) if i>0: ans+=dp[i-1] score=max(score,ans) dp[i]=score print(result-dp[N-1])