import sys N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) l = [(A[i],i) for i in range(N)] + [(B[i],i) for i in range(N)] + [(A[i] // 2 + B[i] // 2,i) for i in range(N)] l.sort() now = l[0][0] ii = l[0][1] ans = 10 ** 10 inf = 10 ** 10 t = 0 for i in range(N): a = A[i] b = B[i] c = (a + b) // 2 k = inf for u in (a,b,c): if u >= now and u < k: k = u if k > t: t = k ans = t - now for n,jj in l[1:]: a = A[ii] b = B[ii] c = (a + b) // 2 k = inf for u in (a,b,c): if u >= n and u < k: k = u if k == inf: print(ans) exit() if k > t: t = k if t - n < ans: ans = t - n now = n ii = jj print(ans)