#include <bits/stdc++.h>
using namespace std;
long long sum = 0;
map<long long, long long> crdmap;
vector<long long> sm;
struct segment {
  long long beg;
  long long end;
  long long crd;
};
bool segcmp(segment &a, segment &b) {
  pair<long long, pair<long long, long long>> f = {a.crd, {a.beg, a.end}};
  pair<long long, pair<long long, long long>> s = {b.crd, {b.beg, b.end}};
  return f < s;
}
void compression(set<long long> &allcrd) {
  long long value = 0;
  for (long long e : allcrd) crdmap[e] = value++;
}
vector<segment> updatevec(vector<segment> &v) {
  vector<segment> ans;
  sort(v.begin(), v.end(), segcmp);
  if (v.empty()) return ans;
  long long beg = v[0].beg;
  long long end = v[0].end;
  long long crd = v[0].crd;
  for (long long i = 1; i < v.size(); ++i) {
    segment e = v[i];
    if (e.crd == crd && e.beg <= end)
      end = max(end, e.end);
    else {
      ans.push_back({crdmap[beg], crdmap[end], crdmap[crd]});
      sum += end - beg + 1;
      beg = e.beg;
      end = e.end;
      crd = e.crd;
    }
  }
  ans.push_back({crdmap[beg], crdmap[end], crdmap[crd]});
  sum += end - beg + 1;
  return ans;
}
void update(long long v, long long l, long long r, long long i, long long x) {
  if (r - l == 1) {
    sm[v] += x;
    return;
  }
  long long mid = (l + r) / 2;
  if (i < mid)
    update(2 * v + 1, l, mid, i, x);
  else
    update(2 * v + 2, mid, r, i, x);
  sm[v] = sm[2 * v + 1] + sm[2 * v + 2];
}
long long get_sum(long long v, long long l, long long r, long long L,
                  long long R) {
  if (l >= R || L >= r) return 0;
  if (L <= l && r <= R) return sm[v];
  long long mid = (l + r) / 2;
  return get_sum(2 * v + 1, l, mid, L, R) + get_sum(2 * v + 2, mid, r, L, R);
}
int32_t main() {
  cin.tie();
  cout.tie();
  long long N;
  cin >> N;
  vector<segment> gor;
  vector<segment> ver;
  set<long long> allcrd;
  for (long long i = 0; i < N; ++i) {
    long long x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1 += 2e9;
    y1 += 2e9;
    x2 += 2e9;
    y2 += 2e9;
    allcrd.insert(x1);
    allcrd.insert(x2);
    allcrd.insert(y1);
    allcrd.insert(y2);
    if (y1 == y2)
      gor.push_back({min(x1, x2), max(x1, x2), y1});
    else
      ver.push_back({min(y1, y2), max(y1, y2), x1});
  }
  compression(allcrd);
  gor = updatevec(gor);
  ver = updatevec(ver);
  vector<pair<pair<long long, long long>, pair<long long, long long>>> arr;
  for (auto &e : gor) arr.push_back({{e.crd, 1ll}, {e.beg, e.end}});
  for (auto &e : ver) {
    arr.push_back({{e.beg, 0ll}, {e.crd, 1ll}});
    arr.push_back({{e.end, 2ll}, {e.crd, -1ll}});
  }
  sort(arr.begin(), arr.end());
  long long M = allcrd.size() + 1;
  sm.resize(4 * M);
  for (auto &e : arr) {
    if (e.first.second != 1)
      update(0, 0, M, e.second.first, e.second.second);
    else
      sum -= get_sum(0, 0, M, e.second.first, e.second.second + 1);
  }
  cout << sum;
}
