#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
const int MOD = int(1e9) + 7;
const long long N = 1000010;
const long long INFll = 1ll * INF * INF;
const long double INFld = 1e+018;
const long double EPS = 0.000000001;
const int sdx[4] = {-1, 0, 1, 0};
const int sdy[4] = {0, 1, 0, -1};
const long double PI = 3.1415926535897932384;
template <typename T>
ostream& operator<<(ostream& out, pair<T, T>& a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T>
istream& operator>>(istream& in, pair<T, T>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (int i = 0; i < a.size(); ++i) in >> a[i];
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> a) {
  for (int i = 0; i < a.size(); ++i)
    if (i == a.size() - 1)
      out << a[i];
    else
      out << a[i] << " ";
  return out;
}
struct event {
  int pos;
  char seg;
  int info;
  int dop;
  event(int a, char b, int c, int d) { pos = a, seg = b, info = c, dop = d; }
};
class segtree {
 public:
  int n;
  vector<int> t;
  vector<int> d;
  int h;
  void build(vector<int>& v) {
    for (int i = n; i < 2 * n; i++) t[i] = v[i - n];
    for (int i = n - 1; i > 0; --i) t[i] = t[i << 1] + t[i << 1 | 1];
  }
  void calc(int p, int k) {
    if (d[p] == 0)
      t[p] = t[p << 1] + t[p << 1 | 1];
    else
      t[p] = d[p] * k;
  }
  void apply(int p, int value, int k) {
    t[p] = value * k;
    if (p < n) d[p] = value;
  }
  void resolve(int l, int r) {
    int k = 2;
    for (l += n, r += n - 1; l > 1; k <<= 1) {
      l >>= 1, r >>= 1;
      for (int i = r; i >= l; --i) calc(i, k);
    }
  }
  void push(int l, int r) {
    int s = h, k = 1 << (h - 1);
    for (l += n, r += n - 1; s > 0; --s, k >>= 1)
      for (int i = l >> s; i <= r >> s; ++i)
        if (d[i] != 0) {
          apply(i << 1, d[i], k);
          apply(i << 1 | 1, d[i], k);
          d[i] = 0;
        }
  }
  void modify(int l, int r, int value) {
    push(l, l + 1);
    push(r - 1, r);
    int l0 = l, r0 = r, k = 1;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1, k <<= 1) {
      if (l & 1) apply(l++, value, k);
      if (r & 1) apply(--r, value, k);
    }
    resolve(l0, l0 + 1);
    resolve(r0 - 1, r0);
  }
  int query(int l, int r) {
    push(l, l + 1);
    push(r - 1, r);
    int res = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) res += t[l++];
      if (r & 1) res += t[--r];
    }
    return res;
  }
  segtree(int n) : n(n), t() {
    h = 32 - __builtin_clz(n);
    t.resize(n << 1, 0);
    d.resize(n << 1, 0);
  }
};
bool hor_comp(event a, event b) {
  return a.pos > b.pos || (a.pos == b.pos && a.info < b.info);
}
bool ver_comp(event a, event b) {
  return a.pos < b.pos || (a.pos == b.pos && a.info > b.info);
}
bool comp(event a, event b) {
  bool f = a.pos > b.pos;
  f |= (a.pos == b.pos && a.seg == 'h' && b.seg == 'v' && b.seg == MOD);
  f |= (a.pos == b.pos && a.seg == 'v' && b.seg == 'h' && a.info == MOD);
  f |= (a.pos == b.pos && a.seg == 'h' && b.seg == 'v' && b.info != MOD);
  f |= (a.pos == b.pos && a.seg == b.seg && a.seg == 'v' && a.info == MOD &&
        b.info != MOD);
  return f;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<event> e;
  map<int, int> m;
  vector<int> b;
  vector<event> h, v;
  for (int i = 0; i < n; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if (x1 > x2) swap(x1, x2);
    if (y1 < y2) swap(y1, y2);
    if (x1 == x2)
      v.push_back(event(x1, 'v', y1, y2));
    else if (y1 == y2)
      h.push_back(event(y1, 'h', x1, x2));
    b.push_back(x1);
    b.push_back(x2);
  }
  sort(b.begin(), b.end());
  int cur = 0;
  m[b[0]] = cur++;
  for (int i = 1; i < b.size(); i++)
    if (b[i - 1] != b[i]) m[b[i]] = cur++;
  sort(h.begin(), h.end(), hor_comp);
  vector<event> a;
  if (h.size()) a.push_back(h[0]);
  for (int i = 1; i < h.size(); i++)
    if (a.back().pos == h[i].pos && a.back().dop >= h[i].info)
      a.back().dop = max(a.back().dop, h[i].dop);
    else
      a.push_back(h[i]);
  h = a;
  while (a.size()) a.pop_back();
  sort(v.begin(), v.end(), ver_comp);
  if (v.size()) a.push_back(v[0]);
  for (int i = 1; i < v.size(); i++)
    if (a.back().pos == v[i].pos && a.back().dop <= v[i].info)
      a.back().dop = min(a.back().dop, v[i].dop);
    else
      a.push_back(v[i]);
  v = a;
  e = h;
  for (int i = 0; i < v.size(); i++) {
    int x = v[i].pos, y1 = v[i].info, y2 = v[i].dop;
    e.push_back(event(y1, 'v', MOD, x));
    e.push_back(event(y2, 'v', y1, x));
  }
  sort(e.begin(), e.end(), comp);
  segtree t(cur);
  int lst = MOD;
  long long ans = 0;
  int fst = -1;
  for (int i = 0; i < e.size(); i++)
    if (e[i].seg == 'v') {
      int lst = e[i].info;
      if (e[i].info == MOD) t.modify(m[e[i].dop], m[e[i].dop] + 1, 1);
      if (lst != MOD) {
        ans += (abs(e[i].pos - lst) + 1);
        t.modify(m[e[i].dop], m[e[i].dop] + 1, 0);
      }
    } else {
      int l = e[i].info, r = e[i].dop;
      int len = r - l + 1;
      l = m[l], r = m[r];
      ans += (len - t.query(l, r + 1));
    }
  cout << ans << endl;
  if (0)
    cerr << fixed << setprecision(0)
         << "TIME = " << clock() / (long double)CLOCKS_PER_SEC * 1000 << "\n";
  return 0;
}
