#include using ll = long long; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector> p(n * 3); for (int i = 0; i < n; i++) { int a; cin >> a; p[i] = { a, i }; } for (int i = 0; i < n; i++) { int b; cin >> b; p[n + i] = { b, i }; p[n * 2 + i] = { (p[i].first + b) / 2, i }; } sort(p.begin(), p.end()); vector c(n, 0); int r = 1 << 30; int k = 0; int a1 = 0; int i1 = 0; for (int i0 = 0; i0 < n * 3; i0++) { while (k < n && i1 < n * 3) { auto [a, i] = p[i1++]; a1 = max(a1, a); k += c[i]++ == 0; } if (k < n) break; auto [a, i] = p[i0]; r = min(r, a1 - a); k -= --c[i] == 0; } cout << r << endl; return 0; }