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)] dp = [[[0,0] for i in range(3)] for i in range(n)] dp[0][0] = [a[0],a[0]] dp[0][1] = [b[0],b[0]] dp[0][2] = [c[0],c[0]] for i in range(1, n): ai, bi,ci = a[i],b[i], c[i] for jj,j in enumerate([ai,bi,ci]): tmp = [10**10, -1, -1 ] tmp = min(tmp, [max(dp[i-1][0][0],j) - min(dp[i-1][0][1],j), max(dp[i-1][0][0],j ),min(dp[i-1][0][1],j) ]) tmp = min(tmp, [max(dp[i-1][1][0],j) - min(dp[i-1][1][1],j), max(dp[i-1][1][0],j ),min(dp[i-1][1][1],j) ]) tmp = min(tmp, [max(dp[i-1][2][0],j) - min(dp[i-1][2][1],j), max(dp[i-1][2][0],j ),min(dp[i-1][2][1],j) ]) dp[i][jj] = tmp[1:] ans = float("inf") for i in range(3): ans = min(dp[-1][i][0] - dp[-1][i][1], ans) print(ans)