#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  register char c = getchar();
  x = 0;
  for (; c < '0' || c > '9'; c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
}
priority_queue<int> q;
int main() {
  priority_queue<int> pq;
  int n, a, b, c, d;
  long long z = 0;
  read(n);
  while (n--) {
    read(a);
    read(b);
    read(c);
    read(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();
  }
  printf("%I64d", z);
}
