func_code_string:    #include <bits/stdc++.h>      using namespace std;   #define int long long   const int inf = 1e18;      struct node {       int x, y;       node *L;       node *R;       int val;       int mx;          node(int xx, int yy) {           L = nullptr;           R = nullptr;           x = xx;           y = rand();           val = yy;           mx = yy;       }   };      node *root = nullptr;      int getmx(node *v) {       if (v == nullptr)return -inf;       return v->mx;   }      void recalc(node *v) {       v->mx = max(v->val, max(getmx(v->L), getmx(v->R)));   }      pair<node *, node *> split(node *v, int key) {       if (v == nullptr)return {nullptr, nullptr};       if (v->x <= key) {           auto tmp = split(v->R, key);           v->R = tmp.first;           recalc(v);           return {v, tmp.second};       } else {           auto tmp = split(v->L, key);           v->L = tmp.second;           recalc(v);           return {tmp.first, v};       }   }      node *merge(node *L, node *R) {       if (L == nullptr)return R;       if (R == nullptr)return L;       if (L->y < R->y) {           auto tmp = merge(L->R, R);           L->R = tmp;           recalc(L);           return L;       } else {           auto tmp = merge(L, R->L);           R->L = tmp;           recalc(R);           return R;       }   }      void add(pair<int, int> a) {       auto tmp = split(root, a.first);       root = merge(merge(tmp.first, new node(a.first, a.second)), tmp.second);   }      int ans(int val) {       node *v = root;       if (getmx(v) < val) {           return -1;       }       int mn = inf;       while (v != nullptr) {           if (v->val >= val) {               mn = min(v->x, mn);           }           if (getmx(v->L) < val) {               v = v->R;           } else {               v = v->L;           }       }       return mn;   }      int get(vector<pair<int, int>> first, vector<pair<int, int>> sec) {       root = nullptr;       sort(first.begin(), first.end());       sort(sec.begin(), sec.end());       int res = -inf;       for (int i = (int) first.size() - 1; i >= 0; --i) {           while (sec.size() != 0 && sec.back().first >= first[i].first) {               add(sec.back());               sec.pop_back();           }           int h = ans(first[i].second);           if (h != -1) {               res = max(res, (first[i].second - h) * 2);           }       }       return res;   }      int get2(vector<pair<int, int>> first, vector<pair<int, int>> sec) {       root = nullptr;       sort(first.begin(), first.end());       sort(sec.begin(), sec.end());       reverse(sec.begin(), sec.end());       int res = -inf;       for (int i = 0; i < first.size(); ++i) {           while (sec.size() != 0 && sec.back().first <= first[i].first) {               add(sec.back());               sec.pop_back();           }           int h = ans(first[i].second);           if (h != -1) {               res = max(res, (first[i].second - first[i].first) * 2);           }       }       return res;   }      signed main() {       cin.tie();       cout.tie();       ios_base::sync_with_stdio(false);   #ifdef foo       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);   #endif       int n;       cin >> n;       int a[n];       int b[n];       for (int i = 0; i < n; ++i) {           cin >> a[i];       }       for (int i = 0; i < n; ++i) {           cin >> b[i];       }       vector<pair<int, int>> f;       vector<pair<int, int>> s;       for (int i = 0; i < n; ++i) {           if (a[i] <= b[i])               f.push_back({a[i], b[i]});           if (b[i] <= a[i])               s.push_back({b[i], a[i]});       }       int ans = 0;       ans = max(ans, get(f, s));       swap(f, s);       ans = max(ans, get(f, s));       f.clear();       s.clear();       for (int i = 0; i < n; ++i) {           if (a[i] <= b[i])               f.push_back({a[i], b[i]});           if (b[i] <= a[i])               s.push_back({b[i], a[i]});       }       ans = max(ans, get2(f, s));       swap(f, s);       ans = max(ans, get2(f, s));       int tot = 0;       for (int i = 0; i < n; ++i) {           tot += abs(a[i] - b[i]);       }       cout << tot - ans;   }      