#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
class Key
{
public:
int _left;
int _right;
int _key;
Key(int x=0,int y=0,int z=0)
:_left(x),
_right(y),
_key(z)
{}
};
function<bool(Key,Key)> func= [](Key x, Key y)
{
if(x._key<y._key)
return true;
else if(x._key==y._key)
return x._left<=y._left;
else
return false;
};
long long merge(vector<Key>& x)
{
vector<Key>arr;
long long number=0;
int key=x.begin()->_key;
int left=x.begin()->_left;
int right=x.begin()->_right;
for(auto&y:x)
{
if(y._key==key && right>=y._left)
{
right=max(right,y._right);
}
else
{
number+=right-left+1;
arr.push_back({left,right,key});
key=y._key;
left=y._left;
right=y._right;
}
}
number+=right-left+1;
arr.push_back({left,right,key});
x=arr;
return number;
}
int main()
{
int n;cin>>n;
vector<Key> row,column;
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)
row.push_back({y1,y2,x1});
else
row.push_back({y2,y1,x1});
}
else
{
if(x1<=x2)
column.push_back({x1,x2,y1});
else
column.push_back({x2,x1,y1});
}
}
sort(row.begin(),row.end(),func);
sort(column.begin(),column.end(),func);
long long number=0;
number+=merge(row);
number+=merge(column);
for(auto&x:row)
for(auto&y:column)
{
if( x._key>=y._left && x._key<=y._right && y._key>=x._left && y._key<=x._right)
number--;
}
cout<<number;
return 0;
}