#include #define rep(i,n) for(int i=0;i P; const ll INF = 1e12; const int MOD = 1000000007; int main() { int n; cin >> n; vector a(2*n); rep(i,2*n) cin >> a[i]; int l = 0,r = 2*n-1; ll ans = 0; rep(i,n){ ll R = a[r] - a[r-1]; ll L = a[l] - a[l+1]; if(R < L){ ans += L; l += 2; }else{ ans += R; r -= 2; } } cout << ans << endl; return 0; }