import heapq N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = [] mi_max = 10**9 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_max = min(mi_max,B[i]) mi = 10**9 ma = 0 h = [] for i,a in enumerate(A): mi = min(mi,a) ma = max(ma,a) heapq.heappush(h,(a,i,0)) ans = ma-mi while h: before,i,ii= heapq.heappop(h) if ii==0: heapq.heappush(h,((A[i]+B[i])//2,i,1)) ma = max(ma,(A[i]+B[i])//2) if ii==1: ma = max(ma,B[i]) if len(h): mi=min(h[0][0],mi_max) ans = min(ans,ma-mi) print(ans)