import heapq n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): if a[i] > b[i]: a[i], b[i] = b[i], a[i] hq = [] for i in range(n): heapq.heappush(hq, (a[i], i, 0)) ma = max(a) ans = max(a) - min(a) for _ in range(n * 2): x, i, j = heapq.heappop(hq) if ans > ma - x: ans = ma - x if j == 0: heapq.heappush(hq, ((a[i] + b[i]) // 2, i, 1)) if ma < (a[i] + b[i]) // 2: ma = (a[i] + b[i]) // 2 elif j == 1: heapq.heappush(hq, (b[i], i, 2)) if ma < b[i]: ma = b[i] else: break print(ans)