import sys input = sys.stdin.readline from heapq import heappop,heappush,heapify N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) X=[] for i in range(N): Y=[A[i],B[i],(A[i]+B[i])//2] Y.sort() X.append(tuple(Y)) ANS=1<<31 MAX=0 for x in X: MAX=max(MAX,x[0]) X.sort() MIN=1<<31 while X: k=list(heappop(X)) ANS=min(ANS,MAX-min(MIN,k[0])) u=k.pop(0) if len(k)==0: MIN=min(MIN,u) else: heappush(X,tuple(k)) MAX=max(MAX,k[0]) print(ANS)