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 <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#define BOTTOM 0
#define LEFT 1
#define RIGHT 2
#define TOP 3
using namespace std;

class P{
public:
	int x,y;
	P(int xx=0,int yy=0){
		x=xx;
		y=yy;
	}
};

class Segment{
public:
	P p1,p2;
	Segment(P pp1=P(),P pp2=P()){
		p1=pp1;
		p2=pp2;
	}
};

class EndPoint{
public:
	P p;
	int seg,st;
	EndPoint(){}
	EndPoint(P pp,int segg,int stt){
		p=pp;
		seg=segg;
		st=stt;
	}

	bool operator <(const EndPoint &ep)const{
		if(p.y==ep.p.y){
			return st<ep.st;
		}
		return p.y<ep.p.y;
	}
};

EndPoint EP[2000000];

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));
	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=lower_bound(BT.begin(),BT.end(),S[EP[i].seg].p1.x);
			set<int>::iterator e=upper_bound(BT.begin(),BT.end(),S[EP[i].seg].p2.x);
			cnt+=distance(b,e);
		}
	}
	return cnt;
}

int main(void){
	int n;
	vector<Segment> ss;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		Segment s;
		scanf("%d %d",&s.p1.x,&s.p1.y);
		scanf("%d %d",&s.p2.x,&s.p2.y);
		ss.push_back(s);
	}
	printf("%d\n",manhattanIntersection(ss));
	return 0;
}