#include <bits/stdc++.h>
using namespace std;
const int64_t N = 524288;
int64_t ans = 0;
struct dot {
  int64_t type;
  int64_t x;
  dot() {}
  dot(int64_t type, int64_t x) : type(type), x(x) {}
  bool operator<(const dot& p) const {
    if (x != p.x) return x < p.x;
    return type < p.type;
  }
};
map<int64_t, vector<dot>> byX, byY;
struct event {
  int64_t type;
  int64_t x;
  int64_t y1, y2;
  event() {}
  event(int64_t type, int64_t x, int64_t y1, int64_t y2)
      : type(type), x(x), y1(y1), y2(y2) {}
  bool operator<(const event& e) const {
    if (x != e.x) return x < e.x;
    return type < e.type;
  }
};
struct node {
  int64_t l, r;
  int64_t val;
  node() {}
  node(int64_t l, int64_t r) : l(l), r(r), val(0) {}
};
vector<int64_t> xco, yco;
vector<event> liste;
node tree[2 * N];
void build() {
  for (int64_t i = 0; i < N; i++) tree[N + i] = node(i, i + 1);
  for (int64_t i = N - 1; i > 0; i--)
    tree[i] = node(tree[2 * i].l, tree[2 * i + 1].r);
}
void add(int64_t v, int64_t d) {
  v += N;
  tree[v].val += d;
  while (v > 1) {
    v >>= 1;
    tree[v].val += d;
  }
}
int64_t sum(int64_t v, int64_t l, int64_t r) {
  if (l <= tree[v].l && tree[v].r <= r) return tree[v].val;
  if (l >= tree[v].r || tree[v].l >= r) return 0;
  return sum(2 * v, l, r) + sum(2 * v + 1, l, r);
}
void procces(map<int64_t, vector<dot>>& inp) {
  for (auto it : inp) {
    int64_t x = it.first;
    vector<dot> pts = it.second;
    sort(pts.begin(), pts.end());
    vector<dot> b;
    int64_t balance = 0, last = 0;
    for (dot dt : pts) {
      if (dt.type == -1) {
        if (balance == 0) last = dt.x;
        balance++;
      } else {
        balance--;
        if (balance == 0) {
          ans += dt.x - last;
          b.push_back({-1, last});
          b.push_back({1, dt.x});
        }
      }
    }
    inp[x] = b;
  }
}
int64_t get_size(vector<int64_t>& a) {
  return unique(a.begin(), a.end()) - a.begin();
}
void shrink() {
  procces(byX);
  procces(byY);
  for (auto it : byX) {
    xco.push_back(it.first);
    vector<dot> a = it.second;
    for (dot dt : a) yco.push_back(dt.x);
  }
  for (auto it : byY) {
    yco.push_back(it.first);
    vector<dot> a = it.second;
    for (dot dt : a) xco.push_back(dt.x);
  }
  sort(xco.begin(), xco.end());
  xco.resize(get_size(xco));
  sort(yco.begin(), yco.end());
  yco.resize(get_size(yco));
  for (auto it : byX) {
    int64_t x = lower_bound(xco.begin(), xco.end(), it.first) - xco.begin();
    vector<dot> a = it.second;
    for (int64_t i = 0; i < (int64_t)a.size(); i += 2) {
      int64_t y1 = lower_bound(yco.begin(), yco.end(), a[i].x) - yco.begin();
      int64_t y2 =
          lower_bound(yco.begin(), yco.end(), a[i + 1].x) - yco.begin();
      liste.push_back({1, x, y1, y2});
    }
  }
  for (auto it : byY) {
    int64_t y = lower_bound(yco.begin(), yco.end(), it.first) - yco.begin();
    vector<dot> a = it.second;
    for (int64_t i = 0; i < (int64_t)a.size(); i++) {
      int64_t x = lower_bound(xco.begin(), xco.end(), a[i].x) - xco.begin();
      liste.push_back({(a[i].type == -1 ? -1 : 0), x, y, y});
    }
  }
  sort(liste.begin(), liste.end());
}
signed work();
signed main() {
  ;
  ;
  ;
  return work();
}
signed work() {
  int64_t n;
  cin >> n;
  while (n--) {
    int64_t x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if (x1 > x2) swap(x1, x2);
    if (y1 > y2) swap(y1, y2);
    if (x1 == x2) {
      y2++;
      byX[x1].push_back({-1, y1});
      byX[x1].push_back({1, y2});
    } else if (y1 == y2) {
      x2++;
      byY[y1].push_back({-1, x1});
      byY[y1].push_back({1, x2});
    }
  }
  shrink();
  build();
  for (event e : liste) {
    if (e.type == -1)
      add(e.y1, 1);
    else if (e.type == 0)
      add(e.y1, -1);
    else
      ans -= sum(1, e.y1, e.y2);
  }
  cout << ans << endl;
  return 0;
}
