import sys input = sys.stdin.readline from heapq import _heappop_max,_heapify_max,_siftdown_max heappop_max = _heappop_max;heapify_max = _heapify_max def heappush_max(heap:list,item): heap.append(item); _siftdown_max(heap, 0, len(heap)-1) INF=1<<60 N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) ans=INF X=[] Y=[] heap=[] for i,(a,b) in enumerate(zip(A,B)): if a>b:a,b=b,a m=a+b>>1 X.append([b,m]) heap.append(a) Y.append((a,i)) Y.append((b,i)) Y.append((m,i)) Y.sort() heapify_max(heap) for x,i in Y: mx=heap[0] ans = min(ans, mx-x) if X[i]: heappush_max(heap, X[i].pop()) else:break print(ans)