from heapq import heapify, heappop, heappush import sys input = sys.stdin.readline n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) M = [] for i in range(n): if A[i] > B[i]: A[i], B[i] = B[i], A[i] M.append((A[i] + B[i]) // 2) H = [] max_ = -10**18 for i in range(n): heappush(H, (A[i], i)) max_ = max(max_, A[i]) ans = max_ - H[0][0] while True: x, i = heappop(H) if x == B[i]: break elif x == M[i]: heappush(H, (B[i], i)) max_ = max(max_, B[i]) else: heappush(H, (M[i], i)) max_ = max(max_, M[i]) ans = min(ans, max_ - H[0][0]) print(ans)