#include <bits/stdc++.h>
using namespace std;
const long long shift = 1000000010;
map<long long, int> tr;
long long ans;
long long prev(long long x) { return x - (x & -x); }
long long next(long long x) { return x + (x & -x); }
int sumtree(long long from, long long to) {
  from += shift;
  to += shift;
  long long cur = to + 1;
  int sumto = 0;
  while (cur > 0ll) {
    sumto += tr[cur];
    cur = prev(cur);
  }
  int sumfrom = 0;
  cur = from;
  while (cur > 0ll) {
    sumfrom += tr[cur];
    cur = prev(cur);
  }
  return sumto - sumfrom;
}
void updatetree(long long num, int delta) {
  num += shift;
  long long cur = num + 1;
  while (cur > 0 && cur < shift + shift) {
    tr[cur] += delta;
    cur = next(cur);
  }
}
void dedupe(map<int, vector<pair<int, int> > >& g) {
  for (auto& row : g) {
    priority_queue<pair<int, int>, vector<pair<int, int> >,
                   std::greater<pair<int, int> > >
        q;
    vector<pair<int, int> > newrow;
    for (auto& el : row.second) {
      q.push(el);
    }
    while (!q.empty()) {
      auto cur = q.top();
      q.pop();
      while (!q.empty() && (q.top().first <= cur.second + 1)) {
        cur.second = max(cur.second, q.top().second);
        q.pop();
      }
      newrow.push_back(cur);
      ans += cur.second - cur.first + 1;
    }
    row.second = newrow;
  }
}
int main() {
  ans = 0;
  int n;
  scanf("%d\n", &n);
  map<int, vector<pair<int, int> > > h;
  map<int, vector<pair<int, int> > > v;
  int a, b, c, d;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d%d\n", &a, &b, &c, &d);
    if (a == c) {
      h[a].push_back(make_pair(min(b, d), max(b, d)));
    } else if (b == d) {
      v[b].push_back(make_pair(min(a, c), max(a, c)));
    }
  }
  dedupe(h);
  dedupe(v);
  priority_queue<pair<int, pair<int, int> >,
                 vector<pair<int, pair<int, int> > >,
                 std::greater<pair<int, pair<int, int> > > >
      qv;
  for (auto& row : v) {
    int y = row.first;
    for (auto& el : row.second) {
      qv.push(make_pair(el.first, make_pair(1, y)));
      qv.push(make_pair(el.second, make_pair(2, y)));
    }
  }
  for (auto& row : h) {
    int x = row.first;
    if (!qv.empty())
      while ((!qv.empty()) &&
             ((qv.top().first < x) ||
              ((qv.top().first == x) && (qv.top().second.first == 1)))) {
        auto top = qv.top();
        qv.pop();
        if ((top.first <= x) && (top.second.first == 1)) {
          updatetree(top.second.second, 1);
        } else if ((top.first < x) && (top.second.first == 2)) {
          updatetree(top.second.second, -1);
        }
      }
    for (auto& el : row.second) {
      ans -= sumtree(el.first, el.second);
    }
  }
  cout << ans << endl;
  return 0;
}
