#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <atcoder/all>

#define ALL(V) std::begin(V), std::end(V)

using ll = long long;

const ll INF = 5e15;

ll op(ll a, ll b) {
    return std::max(a, b);
}

ll e() {
    return -INF;
}

int main() {
    using pll = std::pair<ll, ll>;

    ll N;
    std::cin >> N;
    std::vector<ll> A(N), B(N);
    for (auto &e : A) std::cin >> e;
    for (auto &e : B) std::cin >> e;

    std::vector<std::priority_queue<ll, std::vector<ll>, std::greater<ll>>> pq_v(N);
    std::vector<ll> all;
    for (int i = 0; i < N; i++) {
        ll arr[] = { A[i], B[i], (A[i] + B[i]) / 2 };
        for (auto e : arr) {
            all.push_back(e);
            pq_v[i].push(e);
        }
        pq_v[i].push(INF);
    }

    std::priority_queue<pll, std::vector<pll>, std::greater<pll>> pq;
    std::vector<ll> init(N);
    for (int i = 0; i < N; i++) {
        ll v = pq_v[i].top();
        init[i] = v;
        pq.emplace(v, i);
    }

    atcoder::segtree<ll, op, e> seg(init);

    {
        std::sort(ALL(all));
        auto ite = std::unique(ALL(all));
        all.erase(ite, all.end());
    }

    ll ans = INF;
    for (auto e : all) {
        while (true) {
            auto [ v, i ] = pq.top();
            if (e <= v) break;
            pq.pop();
            pq_v[i].pop();
            ll v2 = pq_v[i].top();
            pq.emplace(v2, i);
            seg.set(i, v2);
        }
        auto max = seg.prod(0, N);
        ans = std::min(ans, max - e);
    }

    std::cout << ans << std::endl;
    return 0;
}