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<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<complex>
using namespace std;

struct Seg{
    int x1, x2, y1, y2;
    Seg(int x1, int y1, int x2, int y2) :x1(x1), y1(y1), x2(x2), y2(y2) {}
};

bool yparaAsc( const Seg& left, const Seg& right ) {
    return left.x1 != right.x1 ? left.x1 < right.x1 : left.y1 < right.y1;
};

struct Time{
    int x; //x??§?¨?
    int y; //y??§?¨?
    int act; //?????????????????????0 ??§?????????1 ??§?????????
    Time(int x, int y, int act) : x(x), y(y), act(act) {}

    bool operator<( const Time& right ) const {
        return x != right.x ? x < right.x : act < right.act;
    }
};

int segmentIntersection(vector<Seg> &input){
    int n = input.size();
    vector<Seg> xpara, ypara;
    for (int i=0;i<n;i++){
        Seg s = input[i];
        if(s.x1 == s.x2) ypara.push_back(s);
        if(s.y1 == s.y2) xpara.push_back(s);
    }

    sort(ypara.begin(), ypara.end(), yparaAsc);

    /*
    for (int i=0;i<ypara.size();i++){
        cout << ypara[i].x1 << " " << ypara[i].y1 << " " << ypara[i].y2 << " " <<endl;
    }
    cout << endl;
    */

    vector<Time> Timeline;
    for (int i=0;i<xpara.size();i++){
        Seg s = xpara[i];
        Time t1(s.x1, s.y1, 0), t2(s.x2, s.y1, 1);
        Timeline.push_back(t1);
        Timeline.push_back(t2);
    }
    sort(Timeline.begin(), Timeline.end());

    /*
    for (int i=0;i<Timeline.size();i++){
        cout << Timeline[i].x << " " << Timeline[i].y << " "  << Timeline[i].act << " " <<endl;
    }
    cout << endl;
    */
    set<int> st;
    int i=0;
    int j=0;
    int S=0;
    while(1){
        if(i >= ypara.size() && j >= Timeline.size()) break;

        if(i >= ypara.size()){
            if(Timeline[j].act == 0) st.insert(Timeline[j].y);
            if(Timeline[j].act == 1) st.erase(Timeline[j].y);
            j++;
            continue;
        }

        if(j >= Timeline.size()){
            set<int>::iterator a = lower_bound(st.begin(), st.end(), ypara[i].y1);
            set<int>::iterator b = upper_bound(st.begin(), st.end(), ypara[i].y2);
            S += distance(a, b);
            i++;
            continue;
        }

        if((ypara[i].x1 < Timeline[j].x) || (ypara[i].x1 == Timeline[j].x && Timeline[j].act == 1)){
            set<int>::iterator a = lower_bound(st.begin(), st.end(), ypara[i].y1);
            set<int>::iterator b = upper_bound(st.begin(), st.end(), ypara[i].y2);
            S += distance(a, b);
            /*
            cout << i << " " << j <<endl;

            set<int>::iterator it = st.begin();
            while( it != st.end() )
            {
                cout << *it << " ";
                ++it;
            }
            cout << endl;
            */
            i++;
        }else{
            if(Timeline[j].act == 0) st.insert(Timeline[j].y);
            if(Timeline[j].act == 1) st.erase(Timeline[j].y);
            j++;
        }
    }
    return S;
}

int main(){
    int n, x1, x2, y1, y2;
    cin >> n;
    vector<Seg> input;
    for (int i=0;i<n;i++){
        cin >> x1 >> y1 >> x2 >> y2;
        if (x1 > x2) swap(x1, x2);
        if (y1 > y2) swap(y1, y2);
        Seg s(x1, y1, x2, y2);
        input.push_back(s);
    }

    cout << segmentIntersection(input) << endl;

    return 0;
}