#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-18;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
template <class T>
pair<vector<int>, vector<T> > compress(vector<T> a) {
  vector<T> ord = a;
  vector<int> res(0);
  sort((ord).begin(), (ord).end());
  (ord).erase(unique(((ord)).begin(), ((ord)).end()), (ord).end());
  for (auto &w : a)
    res.emplace_back(lower_bound((ord).begin(), (ord).end(), w) - ord.begin());
  return make_pair(res, ord);
}
struct Bit {
  vector<long long int> bit;
  int size;
  void init(int n) {
    size = 1;
    while (size < n) size *= 2;
    bit = vector<long long int>(size, 0);
  }
  void add(int k, long long int v) {
    for (int i = k + 1; i <= size; i += i & -i) bit[i - 1] += v;
  }
  long long int sum(int k) {
    long long int res = 0;
    for (int i = k; i > 0; i -= i & -i) res += bit[i - 1];
    return res;
  }
  long long int sum(int l, int r) { return sum(r) - sum(l); }
  long long int get(int k) { return sum(k + 1) - sum(k); }
  long long int update(int k, long long int x) { add(k, x - get(k)); }
};
const int MAX_N = 1000010;
const int X_START = 0;
const int Y_QUERY = 1;
const int X_END = 2;
int n;
vector<pair<int, pair<int, int> > > sweep;
int cnt[MAX_N];
Bit bit;
vector<long long int> ys;
vector<int> cy;
long long int ans = 0;
unordered_map<long long int, vector<pair<long long int, long long int> > > vs;
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (int)(n); i++) {
    long long int xa, ya, xb, yb;
    scanf("%lld %lld %lld %lld", &xa, &ya, &xb, &yb);
    ys.emplace_back(min(ya, yb));
    ys.emplace_back(max(ya, yb));
    if (xa == xb) {
      ans += abs(yb - ya) + 1;
      sweep.emplace_back(xa, pair<int, int>(Y_QUERY, i));
      vs[xa].emplace_back(min(ya, yb), i);
    } else {
      ans += abs(xb - xa) + 1;
      sweep.emplace_back(min(xa, xb), pair<int, int>(X_START, i));
      sweep.emplace_back(max(xa, xb), pair<int, int>(X_END, i));
      vs[ya + INFLL].emplace_back(min(xa, xb), max(xa, xb));
    }
  }
  for (auto &ve : vs) {
    vector<pair<long long int, long long int> > v = ve.second;
    sort((v).begin(), (v).end());
    long long int cur = -INFLL;
    for (auto &w : v) {
      long long int end =
          (ve.first < INFLL / 2 ? ys[w.second * 2 + 1] : w.second);
      if (w.first <= cur) {
        ans -= min(end, cur) - w.first + 1;
        if (ve.first < INFLL / 2) ys[w.second * 2] = min(end, cur) + 1;
      }
      chmax(cur, end);
    }
  }
  cy = compress(ys).first;
  sort((sweep).begin(), (sweep).end());
  bit.init(2 * n);
  for (auto &w : sweep) {
    int x = w.first;
    int t = w.second.first;
    int id = w.second.second;
    int ya = cy[id * 2];
    int yb = cy[id * 2 + 1];
    if (t == X_START) {
      if (cnt[ya] == 0) bit.add(ya, 1);
      cnt[ya]++;
    } else if (t == X_END) {
      cnt[ya]--;
      if (cnt[ya] == 0) bit.add(ya, -1);
    } else if (t == Y_QUERY) {
      ans -= bit.sum(ya, yb + 1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
