import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) events = [] for i in range(N): events.append((A[i], i)) events.append((B[i], i)) events.append(((A[i]+B[i])//2, i)) events.sort(key=lambda p: p[0]) cnt = [0] * N st = set() j = 0 ans = 10**18 for i in range(len(events)): l = events[i][0] while j < len(events) and len(st) < N: r, k = events[j] if cnt[k] == 0: st.add(k) cnt[k] += 1 j += 1 if len(st) == N: r = events[j-1][0] ans = min(ans, r - l) _, k = events[i] cnt[k] -= 1 if cnt[k] == 0: st.remove(k) print(ans)