#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
const ll INF = (ll)1e9 + 7, mod = (ll)1e9 + 9, pw = 31, N = (ll)1e5 + 123,
         M = (ll)1e6 + 123;
const double eps = 1e-11;
const long long inf = 1e18;
ll n;
ll ans = 0;
struct segment {
  ll l, r, num;
};
struct node {
  ll x, t, num;
};
vector<segment> hor, ver;
bool cmp(segment a, segment b) {
  if (a.num == b.num) return a.l < b.l;
  return a.num < b.num;
}
bool cmp2(node a, node b) {
  if (a.x == b.x) return a.t < b.t;
  return a.x < b.x;
}
vector<vector<pii>> d;
vector<node> point;
struct tree {
  ll a, l, r;
  tree() { a = l = r = 0; }
} t[5 * M];
ll sz = 1;
void upd(ll id, ll x, ll v = 1, ll l = -INF, ll r = INF) {
  if (!v || l > r) return;
  if (l == r) {
    t[v].a += x;
    return;
  }
  ll mid = l + (r - l) / 2;
  if (id <= mid) {
    if (!t[v].l) t[v].l = ++sz;
    upd(id, x, t[v].l, l, mid);
  } else {
    if (!t[v].r) t[v].r = ++sz;
    upd(id, x, t[v].r, mid + 1, r);
  }
  t[v].a = t[t[v].l].a + t[t[v].r].a;
}
ll get(ll l, ll r, ll v = 1, ll tl = -INF, ll tr = INF) {
  if (l > r || !v || tl > tr || tl > r || tr < l) return 0;
  if (l <= tl && tr <= r) return t[v].a;
  ll mid = tl + (tr - tl) / 2;
  return get(l, r, t[v].l, tl, mid) + get(l, r, t[v].r, mid + 1, tr);
}
void check(ll v) {
  for (auto seg : d[v]) {
    ans -= get(seg.first, seg.second);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ll x1, lalka, x2, y2;
    cin >> x1 >> lalka >> x2 >> y2;
    if (x1 == x2) {
      if (lalka > y2) swap(lalka, y2);
      hor.push_back({lalka, y2, x1});
    } else {
      if (x1 > x2) swap(x1, x2);
      ver.push_back({x1, x2, lalka});
    }
  }
  sort(hor.begin(), hor.end(), &cmp);
  ll last = -INF;
  for (ll i = 0; i < hor.size(); i++) {
    if (!i || hor[i].num != hor[i - 1].num)
      last = hor[i].l;
    else
      last = max(last, max(hor[i - 1].r + 1, hor[i].l));
    if (hor[i].r < last) continue;
    ans += hor[i].r - last + 1;
    if (i && hor[i].num == hor[i - 1].num)
      d[d.size() - 1].push_back({last, hor[i].r});
    else
      d.push_back({{last, hor[i].r}}),
          point.push_back({hor[i].num, 1, (ll)d.size() - 1});
  }
  sort(ver.begin(), ver.end(), &cmp);
  for (ll i = 0; i < ver.size(); i++) {
    if (!i || ver[i].num != ver[i - 1].num)
      last = ver[i].l;
    else
      last = max(last, max(ver[i - 1].r + 1, ver[i].l));
    if (ver[i].r < last) continue;
    ans += ver[i].r - last + 1;
    point.push_back({last, 0, ver[i].num});
    point.push_back({ver[i].r, 2, ver[i].num});
  }
  sort(point.begin(), point.end(), &cmp2);
  for (auto i : point) {
    if (i.t == 0) upd(i.num, 1);
    if (i.t == 1) check(i.num);
    if (i.t == 2) upd(i.num, -1);
  }
  cout << ans;
  return 0;
}
