import sys input = sys.stdin.readline from heapq import * INF=1<<60 N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) M=[] mx=-INF for i in range(N): if A[i]>B[i]:A[i],B[i]=B[i],A[i] M.append(A[i]+B[i]>>1) heap=[] for i,a in enumerate(A): heappush(heap, (a,i)) mx = max(mx,a) ans=mx-heap[0][0] while True: x,i = heappop(heap) if x==B[i]:break if x==M[i]: b=B[i] heappush(heap, (b,i)) mx = max(mx,b) else: m = M[i] heappush(heap, (m,i)) mx = max(mx,m) ans = min(ans, mx-heap[0][0]) print(ans)