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] for i in range(N-1): for j in range(i,N): w=sum(A[i:j+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)