import heapq import collections N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = [] for i in range(N): if A[i]>B[i]: A[i],B[i]=B[i],A[i] C.append([A[i],(A[i]+B[i])//2,B[i]]) mi = 10**9 ma = 0 h = [] COL = collections.Counter() for i,a in enumerate(A): mi = min(mi,a) ma = max(ma,a) heapq.heappush(h,(a,i,0)) COL[a]+=1 ans = ma-mi while h: before,i,ii= heapq.heappop(h) COL[before]-=1 if ii==0: heapq.heappush(h,((A[i]+B[i])//2,i,1)) ma = max(ma,(A[i]+B[i])//2) COL[(A[i]+B[i])//2]+=1 if ii==1: ma = max(ma,B[i]) COL[B[i]]+=1 if COL[before]==0 and mi==before: mi=h[0][0] ans = min(ans,ma-mi) print(ans)