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] for i in range(N-1): for j in range(i,N): w=k[j] if i>0: w-=k[i-1] u=v[j] if i>0: u^=v[i-1] ans=z-(w-u)+X[j]-X[i] result=min(result,ans) print(result)