from collections import * N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) D = [] for i in range(N): D.append((A[i], i)) D.append((B[i], i)) D.append(((A[i] + B[i])//2, i)) D.sort(reverse=True) cnt = 0 L = [0] * N ans = 10 ** 18 Q = deque() while D: now = D[-1][0] while D: if D[-1][0] == now: _, ind = D.pop() Q.append((ind, now)) L[ind] += 1 if L[ind] == 1: cnt += 1 else: break while cnt == N: val = Q[0][1] ans = min(ans, abs(Q[0][1] - Q[-1][-1])) while Q[0][1] == val: ind, _ = Q.popleft() L[ind] -= 1 if L[ind] == 0: cnt -= 1 if not Q: break print(ans)