#include <bits/stdc++.h>
using namespace std;
const long long LINF = (long long)1e18;
const int INF = (int)1e9 + 7;
const int N = (int)1e5 + 5;
const double EPS = (double)1e-9;
const double PI = (double)3.14159265359;
const int MODULO[6] = {INF,        1000019677, 1000019393,
                       1000007521, 1000024073, 1000009667};
const int PF[5] = {77, 31, 98, 45, 67};
const int nx[4] = {0, 0, 1, -1};
const int ny[4] = {1, -1, 0, 0};
inline bool eq(const long double &a, const long double &b) {
  return fabs(a - b) < EPS;
}
int n;
pair<pair<int, int>, pair<int, int> > data[N];
vector<pair<int, pair<int, int> > > v[2];
long long t[N * 6];
int sz;
vector<int> points;
inline int getid(int x) {
  return upper_bound(points.begin(), points.end(), x) - points.begin();
}
inline void upd(int v, int l, int r, int val, int pos) {
  if (l == r) {
    t[v] += val;
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid)
    upd(v + v, l, mid, val, pos);
  else
    upd(v + v + 1, mid + 1, r, val, pos);
  t[v] = t[v + v] + t[v + v + 1];
}
inline int get(int v, int l, int r, int vbvvctnd, int so_sorry) {
  if (vbvvctnd > r || l > so_sorry) return 0;
  if (vbvvctnd <= l && r <= so_sorry) return t[v];
  int mid = (l + r) / 2;
  return get(v + v, l, mid, vbvvctnd, so_sorry) +
         get(v + v + 1, mid + 1, r, vbvvctnd, so_sorry);
}
inline void merge_seg(vector<pair<int, pair<int, int> > > &a) {
  vector<pair<int, pair<int, int> > > q;
  sort(a.begin(), a.end());
  for (int i = 0; i < int(a.size()); i++) {
    if (!i || a[i].first != q.back().first)
      q.push_back(a[i]);
    else {
      if (a[i].second.first > q.back().second.second)
        q.push_back(a[i]);
      else
        q.back().second.second =
            max(q.back().second.second, a[i].second.second);
    }
  }
  a = q;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    pair<pair<int, int>, pair<int, int> > data;
    scanf("%d%d%d%d", &data.first.first, &data.first.second, &data.second.first,
          &data.second.second);
    if (data.first.first == data.second.first) {
      if (data.first.second > data.second.second)
        swap(data.first.second, data.second.second);
      v[0].push_back(
          {data.first.first, {data.first.second, data.second.second}});
    } else {
      if (data.first.first > data.second.first)
        swap(data.first.first, data.second.first);
      v[1].push_back(
          {data.first.second, {data.first.first, data.second.first}});
    }
  }
  merge_seg(v[0]);
  merge_seg(v[1]);
  vector<pair<int, pair<int, int> > > all;
  long long ans = 0;
  for (auto it : v[0]) {
    all.push_back({it.second.first, {it.first, 1}});
    points.push_back(it.first);
    all.push_back({it.second.second + 1, {it.first, -1}});
    ans += it.second.second - it.second.first + 1;
  }
  sort(all.begin(), all.end());
  for (auto it : v[1]) {
    points.push_back(it.second.second);
    points.push_back(it.second.first);
  }
  sort(points.begin(), points.end());
  int l = 0;
  for (auto it : v[1]) {
    while (l < all.size() && all[l].first <= it.first)
      upd(1, 1, points.size(), all[l].second.second,
          getid(all[l].second.first)),
          l++;
    ans -= get(1, 1, points.size(), getid(it.second.first),
               getid(it.second.second));
    ans += it.second.second - it.second.first + 1;
  }
  printf("%I64d\n", ans);
  return 0;
}
