#include using namespace std; #if __has_include() #include using namespace atcoder; typedef modint998244353 mint; #endif typedef long long ll; typedef pair pii; typedef pair pll; const int INF = 1e9; const long long LINF = 1e18; const int MOD = 998244353; const int MOD1 = 1e9+7; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(x) x.begin(), x.end() template bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} void yorn(bool ans){cout << (ans?"Yes":"No") << endl; return;} int main(){ // 尺取法 int n; cin >> n; vector a(n),b(n); rep(i,n) cin >> a.at(i); rep(i,n) cin >> b.at(i); map> m; rep(i,n){ m[a.at(i)].insert(i); m[b.at(i)].insert(i); m[(a.at(i)+b.at(i))/2].insert(i); } vector num(n); set aru; auto l = m.begin(); auto r = m.begin(); for(auto i:l->second){ num.at(i)++; aru.insert(i); } //rep(i,n) cout << num.at(i) << ' '; ll ans = LINF; for(;l!=m.end();l++){ //int f = i.first; //auto s = i.second; bool ok = true; while((int)aru.size()second){ num.at(j)++; aru.insert(j); } } if(!ok) break; ans = min(ans,(ll)(r->first)-(ll)(l->first)); for(auto j:l->second){ num.at(j)--; if(num.at(j)==0) aru.erase(j); } } cout << ans << endl; //cout << 999 << endl; }