#include <bits/stdc++.h>
using namespace std;
struct seg {
  int x1, y1, x2, y2;
  seg() {}
  seg(int _x1, int _y1, int _x2, int _y2)
      : x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}
} H[100005], V[100005];
int ay[100005 << 2], ax[100005 << 2], ft[100005 << 2];
vector<int> v[100005 << 2];
bool cmpx(seg t1, seg t2) {
  if (t1.x1 != t2.x1) return t1.x1 < t2.x1;
  return t1.y1 < t2.y1;
}
bool cmpy(seg t1, seg t2) {
  if (t1.y1 != t2.y1) return t1.y1 < t2.y1;
  return t1.x1 < t2.x1;
}
inline bool giaongang(seg &t1, seg t2) {
  if (t1.x1 != t2.x1) return false;
  if (t1.y1 <= t2.y1 && t2.y1 <= t1.y2) {
    t1.y2 = ((t1.y2) > (t2.y2) ? (t1.y2) : (t2.y2));
    return true;
  }
  if (t1.y2 + 1 == t2.y1) {
    t1.y2 = t2.y2;
    return true;
  }
  return false;
}
inline void noiduongngang(int &n) {
  int cnt = 0, i;
  for ((i) = 0; (i) < (n); (i)++) {
    if (cnt && giaongang(H[cnt - 1], H[i])) {
    } else
      H[cnt++] = H[i];
  }
  n = cnt;
}
inline bool giaodoc(seg &t1, seg t2) {
  if (t1.y1 != t2.y1) return false;
  if (t1.x1 <= t2.x1 && t2.x1 <= t1.x2) {
    t1.x2 = ((t1.x2) > (t2.x2) ? (t1.x2) : (t2.x2));
    return true;
  }
  if (t1.x2 + 1 == t2.x1) {
    t1.x2 = t2.x2;
    return true;
  }
  return false;
}
inline void noiduongdoc(int &n) {
  int cnt = 0, i;
  for ((i) = 0; (i) < (n); (i)++) {
    if (cnt && giaodoc(V[cnt - 1], V[i])) {
    } else
      V[cnt++] = V[i];
  }
  n = cnt;
}
inline void upd(int n, int i, int val) {
  while (i <= n) ft[i] += val, i += i & -i;
}
inline int qr(int n, int i) {
  int res = 0;
  while (i > 0) res += ft[i], i -= i & -i;
  return res;
}
inline long long giaodiem(int cnth, int cntv) {
  int cnty = 0, i;
  for ((i) = 0; (i) < (cnth); (i)++) {
    ay[cnty++] = H[i].y1;
    ay[cnty++] = H[i].y2;
  }
  for ((i) = 0; (i) < (cntv); (i)++) ay[cnty++] = V[i].y1;
  sort(ay, ay + cnty);
  cnty = unique(ay, ay + cnty) - ay;
  int cntx = 0;
  for ((i) = 0; (i) < (cnth); (i)++) ax[cntx++] = H[i].x1;
  for ((i) = 0; (i) < (cntv); (i)++) {
    ax[cntx++] = V[i].x1;
    ax[cntx++] = V[i].x2;
  }
  sort(ax, ax + cntx);
  cntx = unique(ax, ax + cntx) - ax;
  sort(H, H + cnth, cmpy);
  int idx = 0, j = 0;
  long long res = 0;
  for ((i) = 0; (i) < (cnty); (i)++) {
    while (j < cnth && H[j].y1 == ay[i]) {
      int posx = lower_bound(ax, ax + cntx, H[j].x1) - ax + 1;
      upd(cntx, posx, 1);
      int posy = lower_bound(ay, ay + cnty, H[j].y2) - ay;
      v[posy].push_back(posx);
      j++;
    }
    while (idx < cntv && V[idx].y1 == ay[i]) {
      int id1 = lower_bound(ax, ax + cntx, V[idx].x1) - ax + 1;
      int id2 = upper_bound(ax, ax + cntx, V[idx].x2) - ax;
      res += qr(cntx, id2) - qr(cntx, id1 - 1);
      idx++;
      if (idx == cntv) return res;
    }
    for (typeof(v[i].begin()) ite = v[i].begin(); ite != v[i].end(); ite++)
      upd(cntx, *ite, -1);
  }
  return res;
}
inline void input() {
  int i, n, cnth, cntv;
  int x1, x2, y1, y2;
  scanf("%d", &n);
  cnth = cntv = 0;
  for ((i) = (1); (i) <= (n); (i)++) {
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    if (x1 == x2) {
      if (y1 > y2) swap(y1, y2);
      H[cnth++] = seg(x1, y1, x2, y2);
    } else {
      if (x1 > x2) swap(x1, x2);
      V[cntv++] = seg(x1, y1, x2, y2);
    }
  }
  sort(H, H + cnth, cmpx);
  noiduongngang(cnth);
  sort(V, V + cntv, cmpy);
  noiduongdoc(cntv);
  long long res = 0;
  for ((i) = 0; (i) < (cnth); (i)++) res += H[i].y2 - H[i].y1 + 1;
  for ((i) = 0; (i) < (cntv); (i)++) res += V[i].x2 - V[i].x1 + 1;
  res -= giaodiem(cnth, cntv);
  printf("%I64d", res);
}
int main() {
  input();
  return 0;
}
