#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } template class Compress{ public: vector data; int offset; Compress(vector data_, int offset=0): offset(offset){ data = data_; sort(begin(data), end(data)); data.erase(unique(begin(data), end(data)), end(data)); }; int operator[](T x) { auto p = lower_bound(data.begin(), data.end(), x); assert(x == *p); return offset+(p-data.begin()); } T inv(int x){ return data[x-offset]; } int size(){ return data.size(); } }; const ll inf = 1e18; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector a(n), b(n); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; vector v; for(int i = 0; i < n; i++){ if(a[i] > b[i]) swap(a[i], b[i]); v.push_back(a[i]); v.push_back(b[i]); v.push_back((a[i]+b[i])/2); } auto cp = Compress(v); int m = cp.size(); auto indices = vec2d(3, m, vector()); for(int i = 0; i < n; i++){ indices[0][cp[a[i]]].push_back(i); indices[1][cp[(a[i]+b[i])/2]].push_back(i); indices[2][cp[b[i]]].push_back(i); } ll ans = inf; ll mx = *max_element(a.begin(), a.end()); for(int i = 0; i < m; i++){ int x = cp.data[i]; chmin(ans, mx-x); for(int idx: indices[0][i]){ chmax(mx, (a[idx]+b[idx])/2); } for(int idx: indices[1][i]){ chmax(mx, b[idx]); } for(int idx: indices[2][i]){ chmax(mx, inf); } } cout << ans << endl; }