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;
typedef long long ll;
const int inf = 0x3f3f3f3f;
#define dbg(x...) do { cout << "\033[32;1m" << #x <<" -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<class T, class... Ts> void err(const T& arg,const Ts&... args) { cout << arg << " "; err(args...); }
const int N = 100000 + 5;
vector<int> xall, yall;
int n;
struct Seg{
    int x1, x2, y1, y2;
}l[N];
vector<pair<int,int>> line[2*N], q[2*N];
ll c[2*N];
int getxid(int x){
    return lower_bound(xall.begin(),xall.end(), x) - xall.begin() + 1;
}
int getyid(int x){
    return lower_bound(yall.begin(),yall.end(), x) - yall.begin() + 1;
}
void add(int x, int y){
    for(;x<2*N;x+=x&-x) c[x]+=y;
}
ll ask(int x){
    ll res = 0;
    for(;x;x-=x&-x) res += c[x];
    return res;
}
int main(){
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        int x, y, x2, y2;
        scanf("%d%d%d%d", &x, &y, &x2, &y2);
        xall.push_back(x);
        xall.push_back(x2);
        yall.push_back(y);
        yall.push_back(y2);
        l[i] = Seg{x, x2, y, y2};
    }
    sort(xall.begin(),xall.end());xall.erase(unique(xall.begin(),xall.end()),xall.end());
    sort(yall.begin(),yall.end());yall.erase(unique(yall.begin(),yall.end()),yall.end());
    for(int i=1;i<=n;i++){
        if(l[i].x1 == l[i].x2){
            int xid = getxid(l[i].x1);
            if(l[i].y1 > l[i].y2) swap(l[i].y1, l[i].y2);
            q[xid].push_back(make_pair(getyid(l[i].y1), getyid(l[i].y2)));
        } else {
            if(l[i].x1 > l[i].x2) swap(l[i].x1, l[i].x2);
            line[getxid(l[i].x1)].push_back(make_pair(1, getyid(l[i].y1))); //  1表示添加
            line[getxid(l[i].x2)].push_back(make_pair(2, getyid(l[i].y1))); //  2表示删除
        }
    }
    ll res = 0;
    for(int i=1;i<=xall.size();i++){
        for(auto t : line[i]){
            int type = t.first, y = t.second;
            if(type == 1){
               //dbg(xall[i-1], type, yall[y-1]);
                add(y, 1);
            }
        }
        for(auto t : q[i]){
            int x1 = t.first, x2 = t.second;
            // dbg(x1, x2, ask(x2)-ask(x1-1));
            res += ask(x2) - ask(x1-1);
        }
        for(auto t : line[i]){
            int type = t.first, y = t.second;
            if(type == 2){
                //dbg(xall[i-1], type, yall[y-1]);
                add(y, -1);
            }
        }
    }
    cout << res << endl;
    return 0;
}
