#include<cstdio>#include<iostream>#include<algorithm>#include<math.h>using namespace std;int y[100000];int x[100000];struct node{ int l,r,flag; int yl,yr,s;} tree[44000];struct w{ int x,yl,yr; int flag;} p[44000],tem,q[44000];int cmp(struct w a,struct w b){ return a.x<b.x;}void build(int left,int right,int root){ tree[root].l=left; tree[root].r=right; tree[root].s=tree[root].flag=0; tree[root].yl=y[left]; tree[root].yr=y[right]; if(left+1==right) return; int mid=(left+right)>>1; build(left,mid,root<<1); build(mid,right,root<<1|1);}void build2(int left,int right,int root){ tree[root].l=left; tree[root].r=right; tree[root].s=tree[root].flag=0; tree[root].yl=x[left]; tree[root].yr=x[right]; if(left+1==right) return; int mid=(left+right)>>1; build2(left,mid,root<<1); build2(mid,right,root<<1|1);}void len(int t){ if(tree[t].flag>0) { tree[t].s=tree[t].yr-tree[t].yl; return ; } if(tree[t].l+1==tree[t].r) tree[t].s=0; else tree[t].s=tree[t<<1].s+tree[t<<1|1].s;}void update(int t,w e){ if(e.yl==tree[t].yl&&e.yr==tree[t].yr) { tree[t].flag+=e.flag; len(t); return; } if(e.yr<=tree[t<<1].yr) update(t<<1,e); else if(e.yl>=tree[t<<1|1].yl) update(t<<1|1,e); else { w tmp=e; tmp.yr=tree[t<<1].yr; update(t<<1,tmp); tmp=e; tmp.yl=tree[t<<1|1].yl; update(t<<1|1,tmp); } len(t);}int main(){ int t,cnt,cnt2; int x1,x2,y1,y2; while(~scanf("%d",&t)&&t) { cnt=1; cnt2=1; while(t--) { scanf("%d %d %d %d",&x1,&y1,&x2,&y2); q[cnt2].x=x1; q[cnt2].yl=y1; q[cnt2].yr=y2; q[cnt2].flag=1; x[cnt2++]=y1; q[cnt2].x=x2; q[cnt2].yl=y1; q[cnt2].yr=y2; q[cnt2].flag=-1; x[cnt2++]=y2; p[cnt].x=y1; p[cnt].yl=x1; p[cnt].yr=x2; p[cnt].flag=1; y[cnt++]=x1; p[cnt].x=y2; p[cnt].yl=x1; p[cnt].yr=x2; p[cnt].flag=-1; y[cnt++]=x2; } sort(p+1,p+cnt,cmp); sort(y+1,y+cnt); build(1,cnt-1,1); update(1,p[1]); int sum=tree[1].s; int low=tree[1].s; for(int i=2; i<cnt; i++) { update(1,p[i]); sum+=abs(low-tree[1].s); low=tree[1].s; } sort(q+1,q+cnt2,cmp); sort(x+1,x+cnt2); build2(1,cnt2-1,1); update(1,q[1]); sum+=tree[1].s; low=tree[1].s; for(int i=2; i<cnt2; i++) { update(1,q[i]); sum+=abs(low-tree[1].s); low=tree[1].s; } printf("%d\n",sum); }}