#include using namespace std; int main() { int n; cin >> n; vector a(n); for(auto &e : a) cin >> e; vector b(n); for(auto &e : b) cin >> e; multiset s; vector> ev; for(int i = 0; i < n; i++) { int c = (a[i] + b[i]) / 2; if(a[i] > b[i]) swap(a[i], b[i]); s.insert(a[i]); ev.push_back({a[i], c}); ev.push_back({c, b[i]}); } #define get_dif (*(s.rbegin()) - *(s.begin())) int ans = get_dif; sort(ev.begin(), ev.end()); for(auto e : ev) { s.erase(s.lower_bound(e.first)); s.insert(e.second); ans = min(ans, get_dif); } #undef get_dif cout << ans << endl; return 0; }