#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
inline void opt() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
typedef struct hor {
  long long x1, x2, y;
  hor(long long x1, long long y1, long long x2, long long y2) {
    this->y = y1;
    this->x1 = min(x1, x2);
    this->x2 = max(x1, x2);
  }
} hor;
bool operator<(const hor& a, const hor& b) {
  if (a.y != b.y) return a.y < b.y;
  if (a.x1 != b.x1)
    return a.x1 <= b.x1;
  else
    return a.x2 <= b.x2;
}
bool cmpHor(const hor& a, const hor& b) {
  if (a.y != b.y) return a.y < b.y;
  if (a.x1 != b.x1)
    return a.x1 <= b.x1;
  else
    return a.x2 <= b.x2;
}
typedef struct ver {
  long long y1, y2, x;
  ver(long long x1, long long y1, long long x2, long long y2) {
    this->x = x1;
    this->y1 = min(y1, y2);
    this->y2 = max(y1, y2);
  }
} ver;
bool operator<(const ver& a, const ver& b) {
  if (a.x != b.x) return a.x < b.x;
  if (a.y1 != b.y1)
    return a.y1 <= b.y1;
  else
    return a.y2 <= b.y2;
}
bool cmpVer(const ver& a, const ver& b) {
  if (a.x != b.x) return a.x < b.x;
  if (a.y1 != b.y1)
    return a.y1 <= b.y1;
  else
    return a.y2 <= b.y2;
}
vector<long long> t;
void update(int v, int l, int r, int pos, int x) {
  if (pos < l || pos > r) return;
  if (l == r) {
    if (x == 0)
      t[v] = 0;
    else
      t[v] = 1;
  } else {
    int m = (l + r) / 2;
    update(v * 2, l, m, pos, x);
    update(v * 2 + 1, m + 1, r, pos, x);
    t[v] = t[v * 2] + t[v * 2 + 1];
  }
}
long long get(int v, int tl, int tr, int ql, int qr) {
  if (ql > qr)
    return 0;
  else if (tl == ql && tr == qr)
    return t[v];
  else {
    int tm = (tl + tr) / 2;
    return get(v * 2, tl, tm, ql, min(tm, qr)) +
           get(v * 2 + 1, tm + 1, tr, max(tm + 1, ql), qr);
  }
}
int main() {
  opt();
  int n;
  cin >> n;
  map<long long, vector<hor>> horI;
  map<long long, vector<ver>> verI;
  for (int i = 0; i < n; i++) {
    long long x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if (y1 == y2) {
      horI[y1].push_back(hor(x1, y1, x2, y2));
    } else {
      verI[x1].push_back(ver(x1, y1, x2, y2));
    }
  }
  set<hor> h;
  set<ver> v;
  vector<long long> yCoord;
  long long test = 0;
  for (auto& y : horI) {
    auto& work = y.second;
    sort(work.begin(), work.end(), cmpHor);
    stack<hor> unite;
    unite.push(work[0]);
    for (int i = 1; i < work.size(); i++) {
      auto interval = work[i];
      hor top = unite.top();
      if (interval.x1 <= top.x2) {
        top.x2 = max(top.x2, interval.x2);
        unite.pop();
        unite.push(top);
      } else {
        unite.push(interval);
      }
    }
    while (!unite.empty()) {
      h.insert(unite.top());
      yCoord.push_back(unite.top().y);
      unite.pop();
    }
  }
  for (auto& x : verI) {
    auto& work = x.second;
    sort(work.begin(), work.end(), cmpVer);
    stack<ver> unite;
    unite.push(work[0]);
    for (int i = 1; i < work.size(); i++) {
      auto interval = work[i];
      ver top = unite.top();
      if (interval.y1 <= top.y2) {
        top.y2 = max(top.y2, interval.y2);
        unite.pop();
        unite.push(top);
      } else {
        unite.push(interval);
      }
    }
    while (!unite.empty()) {
      v.insert(unite.top());
      yCoord.push_back(unite.top().y1);
      yCoord.push_back(unite.top().y2);
      unite.pop();
    }
  }
  vector<long long> yComp = yCoord;
  sort(yComp.begin(), yComp.end());
  yComp.resize(unique(yComp.begin(), yComp.end()) - yComp.begin());
  long long prev = (long long)1e15;
  map<long long, vector<pair<long long, int>>> sweepHor;
  map<long long, vector<ver>> sweepVer;
  for (auto x : h) {
    auto p = x;
    p.y = lower_bound(yComp.begin(), yComp.end(), p.y) - yComp.begin();
    prev = min({p.x1, p.x2, prev});
    sweepHor[p.x1].push_back({p.y, 1});
    sweepHor[p.x2].push_back({p.y, 0});
  }
  for (auto x : v) {
    auto p = x;
    p.y1 = lower_bound(yComp.begin(), yComp.end(), p.y1) - yComp.begin();
    p.y2 = lower_bound(yComp.begin(), yComp.end(), p.y2) - yComp.begin();
    prev = min(prev, p.x);
    sweepVer[p.x].push_back(p);
  }
  t.assign(4 * yComp.size(), 0);
  auto horIt = sweepHor.begin();
  auto verIt = sweepVer.begin();
  long long ans = 0, open = 0;
  while ((horIt != sweepHor.end()) || (verIt != sweepVer.end())) {
    long long x = (long long)1e15, y = (long long)1e15;
    if (horIt != sweepHor.end()) x = (*horIt).first;
    if (verIt != sweepVer.end()) y = (*verIt).first;
    if (x < y) {
      auto segments = (*horIt).second;
      ans += (x - prev) * t[1];
      for (auto c : segments) {
        if (c.second == 1) {
          update(1, 0, yComp.size() - 1, c.first, 1);
          ans++;
        }
      }
      for (auto c : segments) {
        if (c.second == 0) {
          update(1, 0, yComp.size() - 1, c.first, 0);
        }
      }
      prev = x;
      horIt++;
    } else if (y < x) {
      auto segments = (*verIt).second;
      ans += (y - prev) * t[1];
      for (auto c : segments) {
        ans += yComp[c.y2] - yComp[c.y1] + 1;
        ans -= get(1, 0, yComp.size() - 1, c.y1, c.y2);
      }
      prev = y;
      verIt++;
    } else {
      ans += (x - prev) * t[1];
      auto verSegments = (*verIt).second;
      auto horSegments = (*horIt).second;
      for (auto c : horSegments) {
        if (c.second == 1) {
          update(1, 0, yComp.size() - 1, c.first, 1);
          ans++;
        }
      }
      for (auto c : verSegments) {
        ans += yComp[c.y2] - yComp[c.y1] + 1;
        ans -= get(1, 0, yComp.size() - 1, c.y1, c.y2);
      }
      for (auto c : horSegments) {
        if (c.second == 0) {
          update(1, 0, yComp.size() - 1, c.first, 0);
        }
      }
      prev = x;
      horIt++;
      verIt++;
    }
  }
  cout << ans;
  return 0;
}
