#include <bits/stdc++.h>
using namespace std;
struct MyStruct {
  long long val;
  long long under;
  long long scorev;
  long long scoreu;
  MyStruct(long long v, long long u, long long sv, long long su)
      : val(v), under(u), scorev(sv), scoreu(su) {}
  bool operator<(const MyStruct& m) const { return val < m.val; }
};
int main() {
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long a1[n], a2[n], b1[n], b2[n];
  for (long long i = 0; i < n; ++i) cin >> a1[i] >> b1[i] >> a2[i] >> b2[i];
  long long ans = 0;
  priority_queue<MyStruct> pq;
  for (long long i = 0; i < n; ++i) {
    long long cnum = a1[i] + b1[i], dnum = a2[i] + b2[i];
    if (cnum < dnum) {
      if (a1[i] > b2[i]) {
        ans += a1[i] - b2[i];
      } else if (b1[i] > a2[i]) {
        ans -= b1[i] - a2[i];
      }
      continue;
    }
    if (cnum == dnum) {
      ans += (a1[i] - b2[i]);
      continue;
    }
    pq.push(MyStruct(cnum, dnum, a1[i], a2[i]));
  }
  bool first = true;
  while (!pq.empty()) {
    MyStruct top = pq.top();
    pq.pop();
    if (first)
      ans += top.scorev;
    else
      ans += (top.scorev - top.val);
    if (top.under != -1) pq.push(MyStruct(top.under, -1, top.scoreu, -1));
    first = !first;
  }
  cout << ans << endl;
}

### Prompt

Generate a Cpp solution to the following problem:

Alice and Bonnie are sisters, but they don't like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking photos. Alice goes first.

There are n stacks of photos. Each stack contains exactly two photos. In each turn, a player may take only a photo from the top of one of the stacks.

Each photo is described by two non-negative integers a and b, indicating that it is worth a units of happiness to Alice and b units of happiness to Bonnie. Values of a and b might differ for different photos.

It's allowed to pass instead of taking a photo. The game ends when all photos are taken or both players pass consecutively.

The players don't act to maximize their own happiness. Instead, each player acts to maximize the amount by which her happiness exceeds her sister's. Assuming both players play optimal, find the difference between Alice's and Bonnie's happiness. That is, if there's a perfectly-played game such that Alice has x happiness and Bonnie has y happiness at the end, you should print x - y.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the number of two-photo stacks. Then follow n lines, each describing one of the stacks. A stack is described by four space-separated non-negative integers a1, b1, a2 and b2, each not exceeding 109. a1 and b1 describe the top photo in the stack, while a2 and b2 describe the bottom photo in the stack.

Output

Output a single integer: the difference between Alice's and Bonnie's happiness if both play optimally.

Examples

Input

2
12 3 4 7
1 15 9 1


Output

1


Input

2
5 4 8 8
4 12 14 0


Output

4


Input

1
0 10 0 10


Output

-10

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct MyStruct {
  long long val;
  long long under;
  long long scorev;
  long long scoreu;
  MyStruct(long long v, long long u, long long sv, long long su)
      : val(v), under(u), scorev(sv), scoreu(su) {}
  bool operator<(const MyStruct& m) const { return val < m.val; }
};
int main() {
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long a1[n], a2[n], b1[n], b2[n];
  for (long long i = 0; i < n; ++i) cin >> a1[i] >> b1[i] >> a2[i] >> b2[i];
  long long ans = 0;
  priority_queue<MyStruct> pq;
  for (long long i = 0; i < n; ++i) {
    long long cnum = a1[i] + b1[i], dnum = a2[i] + b2[i];
    if (cnum < dnum) {
      if (a1[i] > b2[i]) {
        ans += a1[i] - b2[i];
      } else if (b1[i] > a2[i]) {
        ans -= b1[i] - a2[i];
      }
      continue;
    }
    if (cnum == dnum) {
      ans += (a1[i] - b2[i]);
      continue;
    }
    pq.push(MyStruct(cnum, dnum, a1[i], a2[i]));
  }
  bool first = true;
  while (!pq.empty()) {
    MyStruct top = pq.top();
    pq.pop();
    if (first)
      ans += top.scorev;
    else
      ans += (top.scorev - top.val);
    if (top.under != -1) pq.push(MyStruct(top.under, -1, top.scoreu, -1));
    first = !first;
  }
  cout << ans << endl;
}

```