#include <bits/stdc++.h>
const char en = '\n';
using namespace std;
long long size = 470000;
vector<long long> F(500000, 0);
long long lastone(long long x) { return x & (x ^ (x - 1)); }
long long get(long long p) {
  long long res = 0;
  for (long long i = p; i > 0; i -= lastone(i)) res += F[i];
  return res;
}
long long se(long long p, long long h) {
  for (long long i = p; i < size; i += lastone(i)) F[i] += h;
}
int main() {
  ios::sync_with_stdio(false);
  map<long long, vector<pair<long long, long long>>> R, S;
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a > c) swap(a, c);
    if (b > d) swap(b, d);
    if (a == c) {
      R[a].push_back(make_pair(b, d));
    } else {
      S[b].push_back(make_pair(a, c));
    }
  }
  for (auto it = R.begin(); it != R.end(); it++) {
    sort(it->second.begin(), it->second.end());
    long long zac = it->second[0].first, kon = it->second[0].second;
    vector<pair<long long, long long>> X;
    for (int i = 1; i < it->second.size(); i++) {
      if (it->second[i].first <= kon + 1)
        kon = max(kon, it->second[i].second);
      else {
        sum += kon - zac + 1;
        X.push_back(make_pair(zac, kon));
        zac = it->second[i].first;
        kon = it->second[i].second;
      }
    }
    sum += kon - zac + 1;
    X.push_back(make_pair(zac, kon));
    it->second = X;
  }
  for (auto it = S.begin(); it != S.end(); it++) {
    sort(it->second.begin(), it->second.end());
    long long zac = it->second[0].first, kon = it->second[0].second;
    vector<pair<long long, long long>> X;
    for (int i = 1; i < it->second.size(); i++) {
      if (it->second[i].first <= kon + 1)
        kon = max(kon, it->second[i].second);
      else {
        sum += kon - zac + 1;
        X.push_back(make_pair(zac, kon));
        zac = it->second[i].first;
        kon = it->second[i].second;
      }
    }
    sum += kon - zac + 1;
    X.push_back(make_pair(zac, kon));
    it->second = X;
  }
  map<long long, long long> CC;
  for (auto it = R.begin(); it != R.end(); it++) {
    for (int i = 0; i < it->second.size(); i++) {
      CC[it->second[i].first] = 0;
      CC[it->second[i].second] = 0;
    }
  }
  for (auto it = S.begin(); it != S.end(); it++) {
    CC[it->first] = 0;
  }
  int pp = 2;
  for (auto it = CC.begin(); it != CC.end(); it++) {
    it->second = pp++;
  }
  for (auto it = R.begin(); it != R.end(); it++) {
    for (int i = 0; i < it->second.size(); i++) {
      it->second[i].first = CC[it->second[i].first];
      it->second[i].second = CC[it->second[i].second];
    }
  }
  map<long long, vector<pair<long long, long long>>> SS;
  for (auto it = S.begin(); it != S.end(); it++) {
    SS[CC[it->first]] = it->second;
  }
  S = SS;
  vector<pair<long long, pair<long long, long long>>> PP;
  for (auto it = S.begin(); it != S.end(); it++) {
    for (int i = 0; i < it->second.size(); i++) {
      PP.push_back(make_pair(it->second[i].first,
                             make_pair(it->first, it->second[i].second)));
    }
  }
  sort(PP.begin(), PP.end());
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      Q;
  int pos = 0;
  for (auto it = R.begin(); it != R.end(); it++) {
    while (pos < PP.size() && PP[pos].first <= it->first) {
      se(PP[pos].second.first, 1);
      Q.push(make_pair(PP[pos].second.second, PP[pos].second.first));
      pos++;
    }
    while (Q.size() > 0 && Q.top().first < it->first) {
      pair<long long, long long> x = Q.top();
      Q.pop();
      se(x.second, -1);
    }
    for (int i = 0; i < it->second.size(); i++) {
      pair<long long, long long> x = it->second[i];
      sum -= (get(x.second) - get(x.first - 1));
    }
  }
  cout << sum << en;
}
