For given $n$ segments which are parallel to X-axis or Y-axis, find the number of intersections of them.

Constraints

* $1 \leq n \leq 100,000$
* $ -1,000,000,000 \leq x_1, y_1, x_2, y_2 \leq 1,000,000,000$
* Two parallel segments never overlap or touch.
* The number of intersections $\leq 1,000,000$

Input

In the first line, the number of segments $n$ is given. In the following $n$ lines, the $i$-th segment is given by coordinates of its end points in the following format:

$x_1 \; y_1 \; x_2 \; y_2$

The coordinates are given in integers.

Output

Print the number of intersections in a line.

Example

Input

6
2 2 2 5
1 3 5 3
4 1 4 4
5 2 7 2
6 1 6 3
6 5 6 7


Output

3

#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+5;

#define BOTTOM 0
#define LEFT 1
#define RIGHT 2
#define TOP 3

struct point{
    double x,y;
    point(){}
    point(double x,double y):x(x),y(y){}
    point operator + (point &p){
        return point(x+p.x,y+p.y);
    }
    point operator - (point &p){
        return point(x-p.x,y-p.y);
    }
    point operator * (double k){
        return point(x*k,y*k);
    }
    point operator / (double k){
        return point(x/k,y/k);
    }
};

struct segment{
    point p1,p2;
};

struct endpoint{
    point p;
    int seg,st;
    endpoint(){}
    endpoint(point p,int seg,int st):p(p),seg(seg),st(st){}
    bool operator < (const endpoint &ep)const{
        if(p.y==ep.p.y){
            return st<ep.st;//y相同时，按照下断点，左端点，右端点，上端点的顺序排列
        }else{
            return p.y<ep.p.y;
        }
    }
};
endpoint ep[2*maxn];

int manhattanIntersection(vector<segment>s)
{
    int n=s.size();
    for(int i=0,k=0;i<n;i++){
        if(s[i].p1.y==s[i].p2.y){
            if(s[i].p1.x>s[i].p2.x){
                swap(s[i].p1,s[i].p2);
            }
        }else if(s[i].p1.y>s[i].p2.y){
            swap(s[i].p1,s[i].p2);
        }
        if(s[i].p1.y==s[i].p2.y){
            ep[k++]=endpoint(s[i].p1,i,LEFT);
            ep[k++]=endpoint(s[i].p2,i,RIGHT);
        }else{
            ep[k++]=endpoint(s[i].p1,i,BOTTOM);
            ep[k++]=endpoint(s[i].p2,i,TOP);
        }
    }
    sort(ep,ep+(2*n));
//    for(int i=0;i<2*n;i++){
//        cout<<ep[i].p.x<<" "<<ep[i].p.y<<endl;
//    }
//    cout<<endl;
    set<int>bt;
    bt.insert(1000000001);
    int cnt=0;
    for(int i=0;i<2*n;i++){
        if(ep[i].st==TOP){
            bt.erase(ep[i].p.x);
        }else if(ep[i].st==BOTTOM){
            bt.insert(ep[i].p.x);
        }else if(ep[i].st==LEFT){
            set<int>::iterator b=bt.lower_bound(s[ep[i].seg].p1.x);
            set<int>::iterator e=bt.upper_bound(s[ep[i].seg].p2.x);
            cnt+=distance(b,e);
        }
    }
    return cnt;
}

int main()
{
    int n;
    cin>>n;
    vector<segment>s;
    segment temp;
    for(int i=0;i<n;i++){
        cin>>temp.p1.x>>temp.p1.y>>temp.p2.x>>temp.p2.y;
        s.push_back(temp);
    }
    int res=manhattanIntersection(s);
    cout<<res<<endl;
    return 0;
}

