#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int ls[N * 75], rs[N * 75], sum[N * 75], flag[N * 75];
int cnt;
void update(int &x, int l, int r, int pos, int val) {
  if (!x) {
    x = ++cnt;
  }
  if (l == r) {
    flag[x] += val;
    if (flag[x])
      sum[x] = 1;
    else
      sum[x] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(ls[x], l, mid, pos, val);
  else
    update(rs[x], mid + 1, r, pos, val);
  sum[x] = sum[ls[x]] + sum[rs[x]];
}
int query(int x, int l, int r, int L, int R) {
  if (!x || !sum[x]) return 0;
  if (l == L && r == R) return sum[x];
  int mid = (l + r) >> 1;
  if (R <= mid) return query(ls[x], l, mid, L, R);
  if (L > mid) return query(rs[x], mid + 1, r, L, R);
  return query(ls[x], l, mid, L, mid) + query(rs[x], mid + 1, r, mid + 1, R);
}
struct point {
  int x, y1, y2, type, flag;
  point() {}
  point(int x, int y1, int y2, int type, int flag)
      : x(x), y1(y1), y2(y2), type(type), flag(flag) {}
  friend bool operator<(const point &p, const point &q) {
    if (p.x != q.x) return p.x < q.x;
    if (p.type != q.type) return p.type < q.type;
    return p.y1 < q.y1;
  }
} a[N << 1];
int main() {
  int n;
  int root = 0;
  int m = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    if (x1 == x2) {
      if (y1 > y2) swap(y1, y2);
      a[++m] = point(x1, y1, y2, 1, 1);
    } else {
      if (x1 > x2) swap(x1, x2);
      a[++m] = point(x1, y1, y2, 0, 1);
      a[++m] = point(x2, y1, y2, 0, -1);
    }
  }
  sort(a + 1, a + m + 1);
  long long ans = 0;
  for (int i = 1; i <= m;) {
    int j = i;
    int pre = sum[root];
    while (j <= m && a[j].x == a[i].x) j++;
    for (int k = i; k < j; k++) {
      if (!a[k].type && a[k].flag == 1) {
        update(root, -1000000000, 1000000000, a[k].y1, a[k].flag);
      }
    }
    int len = 0;
    if (i > 1)
      len = a[i].x - a[i - 1].x;
    else
      len = 1;
    ans += 1LL * sum[root] + 1LL * pre * (len - 1);
    int ii = i;
    while (i < j && !a[i].type) i++;
    if (i == j) {
      for (int k = ii; k < j; k++)
        if (!a[k].type && a[k].flag == -1) {
          update(root, -1000000000, 1000000000, a[k].y1, a[k].flag);
        }
      continue;
    }
    int nowx = a[i].y1, nowy = a[i].y2;
    for (int k = i + 1; k < j; k++) {
      if (nowy + 1 >= a[k].y1)
        nowy = max(nowy, a[k].y2);
      else {
        int p = query(root, -1000000000, 1000000000, nowx, nowy);
        ans += (nowy - nowx + 1) - p;
        nowx = a[k].y1;
        nowy = a[k].y2;
      }
    }
    int p = query(root, -1000000000, 1000000000, nowx, nowy);
    ans += (nowy - nowx + 1) - p;
    for (int k = ii; k < j; k++)
      if (!a[k].type && a[k].flag == -1) {
        update(root, -1000000000, 1000000000, a[k].y1, a[k].flag);
      }
    i = j;
  }
  cout << ans << endl;
  return 0;
}
