#include #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n - 1); i >= 0; --i) #define ALL(obj) (obj).begin(), (obj).end() #define pb push_back #define to_s to_string #define len(v) (int)v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define print(x) cout << (x) << '\n' #define debug(x) cout << #x << ": " << (x) << '\n' using namespace std; using ll = long long; typedef pair P; ll MOD = 1e9 + 7; ll devc(ll x, ll y) { return 1 + (x - 1) / y; } int main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); ll N; cin >> N; vector A(N); rep(i, 2 * N) cin >> A[i]; ll f = 0, b = 2 * N - 1; ll ans = 0; while(b - f > 1){ if(A[f] - A[f+1] >= A[b] - A[b-1]){ ans += A[f] - A[f + 1]; f += 2; }else{ ans += A[b] - A[b - 1]; b -= 2; } } ans += abs(A[f] - A[b]); print(ans); return 0; }