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 <stdio.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

struct POINT{    
    int x;
    int y1;
    int y2;    //y軸方向の線分の上端のみに使う
    char iEvent;    //0:追加(線分左端)  1:交差(交点)  2:削除(線分右端)

};

bool operator<(const POINT &a, const POINT &b){    //イベントが起きる順番
    if (a.x == b.x && a.iEvent == b.iEvent){
        return a.y1 < b.y1;
    }
    if (a.x == b.x){
        return a.iEvent < b.iEvent;
    }
    return a.x < b.x;
} 

/*bool operator<(const xSEGMENT &zSeg1, const xSEGMENT &zSeg2){    //線分を並べる順
    if(zSeg1.y == zSeg2.y){    //問題の条件から起こらないはず
        return zSeg1.x1 < zSeg2.x1;
    }
    return zSeg1.y < zSeg2.y;
}*/



void INTERSECT(const set<int> &siSegment, const POINT &zPoint, int &nCount){
    std::set<int>::iterator it = siSegment.lower_bound(zPoint.y1);
    if((*it) < zPoint.y1){
        return;
    }
    while((*it) <= zPoint.y2 && it != siSegment.end()){
        it++;
        nCount++;
    }
//    printf("%d/n",nCount);
    return;
}

int main(){
    int n;
    scanf("%d", &n);
    vector<POINT> vzEventPoint;

    for(int i = 0; i < n; i++){
        int x1,x2,y1,y2;
        scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
        if(y1 == y2){
            if(x1 > x2){
                swap(x1, x2);
            }
            POINT zPointLeft,zPointRight;
            zPointLeft.x = x1;
            zPointLeft.y1 = y1;
            zPointLeft.y2 = y1;
            zPointLeft.iEvent = 0;
            zPointRight.x = x2;
            zPointRight.y1 = y1;
            zPointRight.y2 = y1;
            zPointRight.iEvent = 2;
            
            vzEventPoint.push_back(zPointLeft);
            vzEventPoint.push_back(zPointRight);
        }
        if(x1 == x2){
            if(y1 > y2){
                swap(y1, y2);
            }
            POINT zPoint;
            zPoint.x = x1;
            zPoint.y1 = y1;
            zPoint.y2 = y2;
            zPoint.iEvent = 1;
            vzEventPoint.push_back(zPoint);
        }
        
        
    }
    sort(vzEventPoint.begin(), vzEventPoint.end());
    
    set<int> siSegment;    //y座標だけ入れる
    int nCount = 0;
    for (int i = 0; i < vzEventPoint.size(); i++) {
        if (vzEventPoint[i].iEvent == 0) {    
            siSegment.insert(vzEventPoint[i].y1);
        } else if(vzEventPoint[i].iEvent == 2) {
            siSegment.erase(vzEventPoint[i].y1);
        } else {
            INTERSECT(siSegment, vzEventPoint[i], nCount);
        }
    }
    
    printf("%d\n",nCount);
    return 0;
}
