#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
const long long INF = ~0ULL >> 1;
const int maxn = 500000;
int c[maxn], cntx, cnty, N, hx[maxn], hy[maxn];
long long ans;
vector<pair<int, int> > A[maxn], B[maxn], sx[maxn], sy[maxn];
vector<int> E[maxn];
struct info {
  int x1, y1, x2, y2;
} seg[maxn];
void add(int x, int y) {
  while (x <= cntx) c[x] += y, x += x & (-x);
}
int query(int x) {
  int ret = 0;
  while (x) ret += c[x], x -= x & (-x);
  return ret;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d%d%d%d", &seg[i].x1, &seg[i].y1, &seg[i].x2, &seg[i].y2);
    if (seg[i].x1 > seg[i].x2) swap(seg[i].x1, seg[i].x2);
    if (seg[i].y1 > seg[i].y2) swap(seg[i].y1, seg[i].y2);
    hx[++cntx] = seg[i].x1;
    hx[++cntx] = seg[i].x2;
    hy[++cnty] = seg[i].y1;
    hy[++cnty] = seg[i].y2;
  }
  sort(hx + 1, hx + cntx + 1);
  sort(hy + 1, hy + cnty + 1);
  for (int i = 1; i <= N; i++) {
    if (seg[i].x1 == seg[i].x2) {
      int x = lower_bound(hx + 1, hx + cntx + 1, seg[i].x1) - hx;
      sx[x].push_back((make_pair(seg[i].y1, seg[i].y2)));
    } else {
      int y = lower_bound(hy + 1, hy + cnty + 1, seg[i].y1) - hy;
      sy[y].push_back((make_pair(seg[i].x1, seg[i].x2)));
    }
  }
  for (int i = 1; i <= cntx; i++) {
    sort(sx[i].begin(), sx[i].end());
    for (int j = 0; j < sx[i].size(); j++) {
      int k = j, cur = sx[i][j].second;
      while (k < sx[i].size() && sx[i][k].first <= cur) {
        cur = max(cur, sx[i][k].second);
        ++k;
      }
      A[i].push_back((make_pair(sx[i][j].first, cur)));
      int y = lower_bound(hy + 1, hy + cnty + 1, sx[i][j].first) - hy;
      E[y].push_back(i);
      y = lower_bound(hy + 1, hy + cnty + 1, cur) - hy;
      E[y + 1].push_back(-i);
      ans += cur - sx[i][j].first + 1;
      j = k - 1;
    }
  }
  for (int i = 1; i <= cnty; i++) {
    sort(sy[i].begin(), sy[i].end());
    for (int j = 0; j < sy[i].size(); j++) {
      int k = j, cur = sy[i][j].second;
      while (k < sy[i].size() && sy[i][k].first <= cur) {
        cur = max(cur, sy[i][k].second);
        ++k;
      }
      B[i].push_back((make_pair(sy[i][j].first, cur)));
      j = k - 1;
    }
  }
  for (int i = 1; i <= cnty; i++) {
    for (int j = 0; j < E[i].size(); j++)
      if (E[i][j] > 0)
        add(E[i][j], 1);
      else
        add(-E[i][j], -1);
    for (int j = 0; j < B[i].size(); j++) {
      int lx = lower_bound(hx + 1, hx + cntx + 1, B[i][j].first) - hx;
      int rx = lower_bound(hx + 1, hx + cntx + 1, B[i][j].second) - hx;
      ans += B[i][j].second - B[i][j].first + 1 - (query(rx) - query(lx - 1));
    }
  }
  printf("%lld\n", ans);
  return 0;
}
