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>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 200005


enum Type{
	TATE,
	YOKO,
};

struct Line{

	Type type;
	int x1,y1,x2,y2;
};

struct Info{
	Info(int arg_x,int arg_index,Type arg_type){
		x = arg_x;
		index = arg_index;
		type = arg_type;
	}
	bool operator<(const struct Info &arg) const{

		if(x != arg.x){

			return x < arg.x;
		}else{

			return type < arg.type; //右から左に見た場合、縦棒が後に出るようにする
		}
	}
	Type type;
	int x,index;
};

int N;
vector<int> X,Y;
map<int,int> map_Y;
ll BIT[SIZE];
Line line[SIZE];



void add(int loc,ll value){

	BIT[loc] += value;

	loc += loc & -loc; //最後の1ビットを足した場所が次の★更新★場所

	while(loc <= N){
		BIT[loc] += value;
		loc += loc & -loc;
	}
}

ll getSum(int loc){

	ll sum = BIT[loc];

	loc -= loc & -loc; //最後の1ビットを引いた場所が次の★加算★場所

	while(loc > 0){
		sum += BIT[loc];
		loc -= loc & -loc;
	}
	return sum;
}

ll calc(int left,int right){ //left～rightの区間の総和を、sum(1～right)-sum(1～left-1)で求める
	return getSum(right)-getSum(left-1);
}

int main(){

	int num_line;
	scanf("%d",&num_line);

	for(int i = 0; i < num_line; i++){

		scanf("%d %d %d %d",&line[i].x1,&line[i].y1,&line[i].x2,&line[i].y2);

		Y.push_back(line[i].y1);
		Y.push_back(line[i].y2);

		if(line[i].x1 == line[i].x2){ //縦棒

			line[i].type = TATE;

		}else{ //横棒

			line[i].type = YOKO;
		}
	}

	//座標圧縮
	sort(Y.begin(),Y.end());
	Y.erase(unique(Y.begin(),Y.end()),Y.end());

	N = (int)Y.size();

	for(int i = 0; i <= N; i++){

		BIT[i] = 0;
	}

	for(int i = 0; i < Y.size(); i++){

		map_Y[Y[i]] = i+1;
	}

	vector<Info> info;

	for(int i = 0; i < num_line; i++){

		if(line[i].type == TATE){

			info.push_back(Info(line[i].x1,i,TATE));
		}else{

			info.push_back(Info(max(line[i].x1,line[i].x2),i,YOKO)); //BIT加算用
			info.push_back(Info(min(line[i].x1,line[i].x2)-1,i,YOKO)); //BIT削除用
		}
	}

	sort(info.begin(),info.end());

	ll ans = 0;

	for(int i = info.size()-1; i >= 0; i--){

		if(info[i].type == TATE){

			int left = map_Y[min(line[info[i].index].y1,line[info[i].index].y2)];
			int right = map_Y[max(line[info[i].index].y1,line[info[i].index].y2)];

			ans += calc(left,right);

		}else{ //横棒

			if(info[i].x == max(line[info[i].index].x1,line[info[i].index].x2)){ //横線の右側

				add(map_Y[line[info[i].index].y1],1);

			}else{ //横線の左側-1

				add(map_Y[line[info[i].index].y1],-1);
			}
		}
	}

	printf("%lld\n",ans);

	return 0;
}

