#include <bits/stdc++.h>
using namespace std;
priority_queue<int> q;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  priority_queue<int> pq;
  int n, a, b, c, d;
  long long z = 0;
  cin >> n;
  while (n--) {
    cin >> a >> b >> c >> d;
    if (a + b < c + d)
      z += max(0, a - d) - max(0, b - c);
    else {
      z += a + c;
      q.push(a + b);
      q.push(c + d);
    }
  }
  while (!q.empty()) {
    q.pop();
    z -= q.top();
    q.pop();
  }
  cout << z << '\n';
}
