// Original C++ solution (slower):
#include<cstdio>

#include<cmath>

#include<cstring>

#include<iostream>

#include<algorithm>

#include<vector>

using namespace std;

#define clr(a,b) memset(a,b,sizeof(a))

#define pb(a)    push_back(a)

#define il       inline

#define reg      register

typedef long long ll;

typedef double db;

const int maxn=10000;

const int minn=200000+5;

struct Point

{

    db x,y;

    Point(){}

    Point(db x,db y):x(x),y(y){}

};

struct Seg

{

    Point a,b;

    int c;

    Seg(Point a,Point b,int c):a(a),b(b),c(c){}

    friend bool operator<(Seg p,Seg q){

        if(p.a.y!=q.a.y) return p.a.y<q.a.y;

    	return p.c!=q.c?p.c<q.c:p.a.x<q.a.x;

    }

};

db  x[minn<<2];

int q,lenx,ans,tree[minn<<2];

vector<Seg> ve;

void init()

{

    clr(tree,0);

    ve.clear();

    lenx=0;

    ans=0;

    return ;

}

void  pushpu(int k,int c)

{

    while(k)

    {

        tree[k]+=c;

        k>>=1;

    }

}

void update(int l,int r,int nu,int c,int k)

{

    if(nu==l&&r==nu)

    {

        pushpu(k,c);

        return ;

    }

    int mind=(l+r)/2;

    if(nu<=mind){update(l,mind,nu,c,k<<1);}

    if(nu>mind) {update(mind+1,r,nu,c,k<<1|1);}

    return ;

}

void query(int l,int r,int L,int R,int k)

{

    if(L<=l&&r<=R)

    {

        ans+=tree[k];

        return ;

    }

    int mind=(l+r)/2;

    if(L<=mind){query(l,mind,L,R,k<<1);}

    if(R>mind) {query(mind+1,r,L,R,k<<1|1);}

    return ;

}

int slove()

{

    sort(ve.begin(),ve.end());

    sort(x,x+lenx);

    int res=0;

    for(reg int i=0;i<ve.size();i++)

    {

        if(ve[i].a.x==ve[i].b.x){

            int nu=lower_bound(x,x+lenx,ve[i].a.x)-x+1;

            int c=ve[i].c>2?-1:ve[i].c;

            update(1,lenx,nu,c,1);

        }

        else

        {

            ans=0;

            int l=lower_bound(x,x+lenx,ve[i].a.x)-x+1;

            int r=lower_bound(x,x+lenx,ve[i].b.x)-x+1;

            query(1,lenx,l,r,1);

            res+=ans;

        }

    }

return res;

}

int main()

{

//    freopen("data.txt","r",stdin);

    init();

    scanf("%d",&q);

    Point a,b;

    while(q--)

    {

        scanf("%lf%lf",&a.x,&a.y);

        scanf("%lf%lf",&b.x,&b.y);

        if(a.x>b.x||a.y>b.y){swap(a,b);}

        if(a.x!=b.x)

        {

            x[lenx++]=a.x;x[lenx++]=b.x;

            ve.pb(Seg(a,b,2));

        }

        else

        {

            x[lenx++]=a.x;

            ve.pb(Seg(a,a,1));

            ve.pb(Seg(b,b,3));

        }

    }

    printf("%d\n",slove());

    return 0;

}




// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

int n,m,cnt,ans,HASH[200001],tr[200001];

struct point{int x,y;}a[200001];

struct seg{int k,x,y,r;}s[2000001];

inline bool cmp3(seg a,seg b){

    if(a.y==b.y)return a.k>b.k;

    return a.y<b.y;

}

int find(int x)

{

    int l=0,r=m+1;

    while(l+1<r)

    {

        int mid=(l+r)>>1;

        if(HASH[mid]>=x)r=mid;

        else l=mid;

    }

    return r;

}

void insert(int k,int l,int r,int t)//0横线,1竖线

{

    if(!k){s[++cnt].x=find(l);s[cnt].r=find(r);s[cnt].y=t;s[cnt].k=0;}

    else{

        s[++cnt].x=find(t);s[cnt].y=l;s[cnt].k=1;

        s[++cnt].x=find(t);s[cnt].y=r;s[cnt].k=-1;

    }

}

void update(int x,int y)

{

    while(x<2e5)

    {

        tr[x]+=y;

        x+=x&(-x);

    }

}

int ask(int x)

{

    int s=0;

    while(x){

        s+=tr[x];

        x-=x&(-x);

    }

    return s;

}

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=2*n;i++){

        scanf("%d%d",&a[i].x,&a[i].y);

        HASH[i]=a[i].x;

    }

    sort(HASH+1,HASH+2*n+1);

    m=unique(HASH+1,HASH+2*n+1)-(HASH+1);

    for(int i=1;i<2*n;i+=2){

        if(a[i].x==a[i+1].x){

            if(a[i].y>a[i+1].y)swap(a[i],a[i+1]);

            insert(1,a[i].y,a[i+1].y,a[i].x);

        }else{

            if(a[i].x>a[i+1].x)swap(a[i],a[i+1]);

            insert(0,a[i].x,a[i+1].x,a[i].y);

        }

    }

    sort(s+1,s+cnt+1,cmp3);

    for(int i=1;i<=cnt;i++){

//        if(!s[i].k)cout<<s[i].x<<" "<<s[i].r<<endl;

//        else cout<<s[i].x<<" "<<s[i].y<<" "<<s[i].k<<endl;

        if(!s[i].k)ans+=ask(s[i].r)-ask(s[i].x-1);

        else update(s[i].x,s[i].k);

    }

    printf("%d\n",ans);

    return 0;

}




// Fastest known solution for this problem: