#include <bits/stdc++.h>   using namespace std;   void readi(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readll(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readc(char &x) {     char c;     while ((c = getchar()) ==    )       ;     x = c;   }   void writes(string s) { puts(s.c_str()); }   void writeln() { writes(  ); }   void writei(int x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   void writell(long long x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   inline long long inc(int &x) { return ++x; }   inline long long inc(long long &x) { return ++x; }   inline long long inc(int &x, long long y) { return x += y; }   inline long long inc(long long &x, long long y) { return x += y; }   inline double inc(double &x, double y) { return x += y; }   inline long long dec(int &x) { return --x; }   inline long long dec(long long &x) { return --x; }   inline long long dec(int &x, long long y) { return x -= y; }   inline long long dec(long long &x, long long y) { return x -= y; }   inline double dec(double &x, double y) { return x -= y; }   inline long long mul(int &x) { return x = ((long long)x) * x; }   inline long long mul(long long &x) { return x = x * x; }   inline long long mul(int &x, long long y) { return x *= y; }   inline long long mul(long long &x, long long y) { return x *= y; }   inline double mul(double &x, double y) { return x *= y; }   inline long long divi(int &x) { return x = sqrt(x); }   inline long long divi(long long &x) { return x = sqrt(x); }   inline long long divi(int &x, long long y) { return x /= y; }   inline long long divi(long long &x, long long y) { return x /= y; }   inline double divi(double &x, double y) { return x /= y; }   inline long long mod(int &x, long long y) { return x %= y; }   inline long long mod(long long &x, long long y) { return x %= y; }   long long n, m, i, j, cnt, cas;   long long ans;   vector<long long> all;   struct Scanning_line {     long long l, r, h, ad;   } s[200005];   struct seg {     long long l, r, add;     long long sum;   } tr[800005];   void build(long long x, long long l, long long r) {     if (l == r) {       tr[x].l = l;       tr[x].r = r;       tr[x].add = tr[x].sum = 0;       return;     }     tr[x].l = l;     tr[x].r = r;     tr[x].add = tr[x].sum = 0;     build(x * 2, l, (l + r) / 2);     build(x * 2 + 1, (l + r) / 2 + 1, r);   }   void pushup(long long x) {     if (tr[x].add)       tr[x].sum = all[tr[x].r] - all[tr[x].l - 1];     else if (tr[x].l == tr[x].r)       tr[x].sum = 0;     else       tr[x].sum = tr[x * 2].sum + tr[x * 2 + 1].sum;   }   void update(long long x, long long l, long long r, long long c) {     if (tr[x].l > r || tr[x].r < l) return;     if (l <= tr[x].l && tr[x].r <= r) {       tr[x].add += c;       pushup(x);       return;     }     update(x * 2, l, r, c);     update(x * 2 + 1, l, r, c);     pushup(x);   }   bool cmp(Scanning_line x, Scanning_line y) { return x.h < y.h; }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     cnt = 0;     for (i = 1; i <= n; i++) {       long long w, x, y, z;       cin >> w >> x >> y >> z;       if (w > y) swap(w, y);       if (x > z) swap(x, z);       w--;       x--;       all.push_back(w);       all.push_back(y);       s[++cnt] = {w, y, x, 1};       s[++cnt] = {w, y, z, -1};     }     stable_sort(all.begin(), all.end());     stable_sort(s + 1, s + cnt + 1, cmp);     all.resize(unique(all.begin(), all.end()) - all.begin());     ans = 0;     build(1, 0, all.size());     for (i = 1; i <= cnt; i++) {       if (i != 1 && s[i].h != s[i - 1].h) {         ans += abs(s[i].h - s[i - 1].h) * tr[1].sum;       }       long long l = upper_bound(all.begin(), all.end(), s[i].l) - all.begin();       long long r = upper_bound(all.begin(), all.end(), s[i].r) - all.begin();       update(1, l, r - 1, s[i].ad);     }     cout << ans << endl;     return 0;   }   