#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<int,int,int>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ma = 0, ans = INF;
    priority_queue<asc(T)> pq;
    vector<vector<int>> a(n,vector<int>(3));
    rep(i,n) cin >> a[i][0];
    rep(i,n){
        cin >> a[i][2];
        if(a[i][2]<a[i][0]) swap(a[i][2], a[i][0]);
        a[i][1] = (a[i][0] + a[i][2]) / 2;
        pq.push({a[i][0], i, 0});
        chmax(ma, a[i][0]);
    }
    while(1){
        int p,q,r;
        tie(p,q,r) = pq.top();
        pq.pop();
        chmin(ans, ma-p);
        if(r==2) break;
        pq.push({a[q][r+1],q,r+1});
        chmax(ma, a[q][r+1]);
    }
    cout << ans << '\n';
    return 0;
}