#include <bits/stdc++.h>
using namespace std;
int t[400002], n, sz;
struct seg {
  int l, r, d;
};
map<int, int> ha;
vector<int> _num;
vector<seg> y, x;
void discrete() {
  sort(_num.begin(), _num.end());
  _num.erase(unique(_num.begin(), _num.end()), _num.end());
  for (auto i : _num) ha[i] = ++sz;
}
void modify(int p, int v) {
  while (p <= sz) {
    t[p] += v;
    p += p & (-p);
  }
}
int getSum(int p) {
  int res = 0;
  while (p) {
    res += t[p];
    p -= p & (-p);
  }
  return res;
}
void compress(vector<seg>& v) {
  auto cmpd = [](seg a, seg b) {
    if (a.d == b.d) return a.l < b.l;
    return a.d < b.d;
  };
  sort(v.begin(), v.end(), cmpd);
  int k = 0;
  for (auto i = 0; i < v.size(); i++) {
    seg cur = v[i];
    while (i + 1 < v.size() && v[i + 1].d == cur.d && v[i + 1].l <= cur.r) {
      cur.r = max(cur.r, v[i + 1].r);
      i++;
    }
    v[k++] = cur;
  }
  v.resize(k);
}
int main(int argc, const char* argv[]) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x1, x2, y1, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    if (x1 == x2)
      y.push_back(seg{min(y1, y2), max(y1, y2), x1});
    else
      x.push_back(seg{min(x1, x2), max(x1, x2), y1});
    _num.push_back(x1);
    _num.push_back(x2);
  }
  discrete();
  compress(x);
  compress(y);
  vector<seg> newY;
  for (auto i : y) {
    newY.push_back(seg{i.l, 0, i.d});
    newY.push_back(seg{i.r, 1, i.d});
  }
  auto cmpNY = [](seg a, seg b) {
    if (a.l == b.l) {
      return a.r < b.r;
    } else
      return a.l < b.l;
  };
  sort(newY.begin(), newY.end(), cmpNY);
  long long ans = 0, sub = 0;
  for (auto i : x) ans += i.r - i.l + 1;
  for (auto i : y) ans += i.r - i.l + 1;
  auto iy = newY.begin();
  for (auto i : x) {
    while (iy != newY.end() && iy->l + iy->r <= i.d) {
      modify(ha[iy->d], iy->r == 0 ? 1 : -1);
      iy++;
    }
    sub += getSum(ha[i.r]) - getSum(ha[i.l] - 1);
  }
  cout << ans - sub << endl;
  return 0;
}
