#include <bits/stdc++.h>
using namespace std;
priority_queue<long long> hsh;
int main() {
  long long sum = 0, n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    long long a, b, c, d;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    if (a <= d && b <= c) continue;
    if (a <= d && a - d <= c - b) {
      sum += c - b;
      continue;
    }
    if (b <= c && b - c <= d - a) {
      sum += a - d;
      continue;
    }
    hsh.push(a + b), hsh.push(c + d), sum += a + c;
  }
  while (!hsh.empty()) hsh.pop(), sum -= hsh.top(), hsh.pop();
  return printf("%lld\n", sum), 0;
}
