#include <bits/stdc++.h>
using namespace std;
int n, a, b, c, d, A[200100], tot;
long long ans, all;
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (a + b >= c + d) {
      A[++tot] = (a + b);
      ans += (a - b);
      A[++tot] = (c + d);
      ans += (c - d);
    } else if (a > d)
      all += a - d;
    else if (b > c)
      all += c - b;
  }
  sort(A + 1, A + tot + 1);
  for (int i = 1; i <= tot; i += 2) ans += A[i + 1] - A[i];
  printf("%lld\n", all + ans / 2);
  return 0;
}
