#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<vector<int>> c(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        c[i].push_back(a[i]);
        c[i].push_back(b[i]);
        c[i].push_back((a[i] + b[i]) / 2);
    }
    const int INF = 2e9;
    vector<int> vals;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;
    int ma = -INF;
    for (int i = 0; i < n; i++) {
        sort(c[i].begin(), c[i].end());
        for (int j : c[i]) {
            vals.push_back(j);
        }
        c[i].push_back(INF);
        pq.push({c[i][0], i});
        ma = max(ma, c[i][0]);
    }
    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    vector<int> idx(n, 0);
    int ans = INF;
    for (int mi : vals) {
        while (pq.top().first < mi) {
            int i = pq.top().second;
            pq.pop();
            idx[i]++;
            pq.push({c[i][idx[i]], i});
            ma = max(ma, c[i][idx[i]]);
        }
        ans = min(ans, ma - mi);
    }
    cout << ans << endl;
}