#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; typedef pair Pid; typedef pair Pdi; typedef pair Pl; typedef pair> PP; const double PI = 3.1415926535897932; // acos(-1) const double EPS = 1e-15; const int INF = 1001001001; const int mod = 1e+9 + 7; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define chadd(x, y) x = (x + y) % mod int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int sz = n * 2; vector a(sz); for(int i = 0; i < sz; ++i) cin >> a[i]; int left = 0, right = sz - 1; ll res = 0; int remain = sz; while(remain > 2){ ll foo = a[left] - a[left + 1]; ll bar = a[right] - a[right - 1]; if(foo >= bar){ res += foo; left = left + 2; } else{ res += bar; right = right - 2; } remain -= 2; } if(remain % 2 == 0){ ll foo = a[left] - a[right]; ll bar = a[right] - a[left]; res += max(foo, bar); } else{ res += a[left]; } cout << res << endl; }