import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) c = [(a[i]+b[i])//2 for i in range(n)] all = [(a[i], i) for i in range(n)] + [(b[i], i) for i in range(n)] + [(c[i], i) for i in range(n)] s = sorted(list(set(a + b + c))) all.sort() m = len(s) r = 0 ll = 0 rr = 0 d = defaultdict(int) now = 0 ans = float("inf") for l in range(m): while r < m and now != n: while rr < 3*n and all[rr][0] == s[r]: d[all[rr][1]] += 1 now += (d[all[rr][1]] == 1) rr += 1 r += 1 if now == n: ans = min(ans, s[r-1] - s[l]) if now < n: break while ll < 3*n and all[ll][0] == s[l]: d[all[ll][1]] -= 1 now -=(d[all[ll][1]] == 0) ll += 1 print(ans)