#include using namespace std; int main(){ long n; cin >> n; vector v(2*n); for(int i = 0; i < 2*n; i++){ cin >> v.at(i); } int left = 0; int right = 2 * n -1; long score; for(int i = 0; i < n; i++){ long l = v.at(left) - v.at(left + 1); long r = v.at(right) - v.at(right -1); if(r >= l){ score += r; right -= 2; } else { score += l; left += 2; } } cout << score << endl; }