#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int> > > column, row, solve;
int U[500005], f[500005];
long long ans;
void add(int x, int v) {
  for (; x <= *U; x += x & -x) f[x] += v;
}
int ask(int x) {
  int s = 0;
  for (; x; x -= x & -x) s += f[x];
  return s;
}
vector<pair<int, pair<int, int> > > Rebuild(
    vector<pair<int, pair<int, int> > > a) {
  static vector<pair<int, pair<int, int> > > ret;
  ret.clear();
  sort(a.begin(), a.end());
  int last = 0;
  for (int i = 1; i <= a.size(); i++)
    if (i == a.size() || a[i].first != a[i - 1].first) {
      static vector<pair<int, int> > now;
      now.clear();
      for (int k = last; k < i; k++) now.push_back(a[k].second);
      sort(now.begin(), now.end());
      int L = now[0].first, R = now[0].second;
      for (int k = 1; k < now.size(); k++)
        if (now[k].first > R + 1) {
          ret.push_back(make_pair(a[i - 1].first, make_pair(L, R)));
          L = now[k].first;
          R = now[k].second;
        } else
          R = max(R, now[k].second);
      ret.push_back(make_pair(a[i - 1].first, make_pair(L, R)));
      last = i;
    }
  return ret;
}
int Find(int x) { return lower_bound(U + 1, U + *U + 1, x) - U; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    if (y1 == y2)
      row.push_back(make_pair(y1, make_pair(min(x1, x2), max(x1, x2))));
    else
      column.push_back(make_pair(x1, make_pair(min(y1, y2), max(y1, y2))));
  }
  row = Rebuild(row);
  column = Rebuild(column);
  *U = 0;
  for (int i = 0; i < row.size(); i++) {
    U[++*U] = row[i].second.first;
    U[++*U] = row[i].second.second;
    solve.push_back(row[i]);
    ans += (row[i].second.second - row[i].second.first + 1);
  }
  for (int i = 0; i < column.size(); i++) {
    U[++*U] = column[i].first;
    solve.push_back(
        make_pair(column[i].second.first, make_pair(-1e9 - 1, U[*U])));
    solve.push_back(
        make_pair(column[i].second.second + 1, make_pair(-1e9 - 3, U[*U])));
    ans += (column[i].second.second - column[i].second.first + 1);
  }
  sort(U + 1, U + *U + 1);
  *U = unique(U + 1, U + *U + 1) - (U + 1);
  sort(solve.begin(), solve.end());
  for (int i = 0; i < solve.size(); i++) {
    if (solve[i].second.first < -1e9)
      add(Find(solve[i].second.second), solve[i].second.first + (1e9) + 2);
    else
      ans -= ask(Find(solve[i].second.second)) -
             ask(Find(solve[i].second.first) - 1);
  }
  printf("%lld\n", ans);
}
