#include #include #include #include #include #include #include #include #include #include using namespace std; struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<ostream &operator<<(ostream &o,const vector&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<> n; vector a(2*n); for (int64 i=0; i<2*n; i++) cin >> a[i]; int64 ans = 0; int64 l = 0; int64 r = 2*n - 1; while(l < r) { if (a[l]-a[l+1] > a[r]-a[r-1]) { ans += a[l] - a[l+1]; l+=2; } else { ans += a[r] - a[r-1]; r-=2; } } cout << ans << endl; }