#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Line {
int x, l, r;
bool operator < (const Line& line) const {
if (x != line.x) return x < line.x;
else if (l != line.l) return l < line.l;
return r < line.r;
}
};
vector<Line> cols, rows;
void merge(vector<Line>& v)
{
if (v.size() == 0) return ;
sort(v.begin(), v.end());
vector<Line> res;
int pre_x = v[0].x;
int l = v[0].l, r = v[0].r;
for (int i = 1; i < v.size(); ++i)
{
if (v[i].x != pre_x || v[i].l > r)
{
res.push_back({pre_x, l, r});
pre_x = v[i].x, l = v[i].l, r = v[i].r;
}
else r = max(r, v[i].r);
}
res.push_back({pre_x, l, r});
v = res;
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
{
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2) rows.push_back({x1, min(y1, y2), max(y1, y2)});
else cols.push_back({y1, min(x1, x2), max(x1, x2)});
}
long long res = 0;
merge(rows), merge(cols);
for (auto &t : rows) res += (t.r - t.l + 1);
for (auto &t : cols) res += (t.r - t.l + 1);
for (auto &row : rows)
for (auto &col : cols)
{
if (row.x >= col.l && row.x <= col.r && col.x >= row.l && col.x <= row.r) --res;
}
cout << res << endl;
return 0;
}