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 <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#define maxn 400005
using namespace std;
typedef long long ll;
typedef set<int>:: iterator Ite;
const int DOWN = 0;
const int LEFT = 1;
const int UP = 2;
int n,m,rig[100005];
struct Point{
	int type,x,y,seg;
	Point(int a = 0,int b = 0,int c = 0,int d = 0): type(a),x(b),y(c),seg(d) {}
}ps[maxn];
bool cmp(const Point &a,const Point &b){
	if(a.y == b.y){
		if(a.type == b.type) return a.x < b.x;
		return a.type < b.type;
	}
	return a.y < b.y;
}
int work(){
	sort(ps+1,ps+m+1,cmp);
	int ans = 0;
	set <int> st;
	st.clear();
	for(int i=1;i<=m;i++){
		if(ps[i].type == 0) st.insert(ps[i].x);
		else if(ps[i].type == 2) st.erase(ps[i].x);
		else{
			int l = ps[i].x,r = rig[ps[i].seg];
			Ite itl = st.lower_bound(l),itr = st.upper_bound(r);
			ans += distance(itl,itr);
		}
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	m = 0;
	for(int i=1;i<=n;i++){
		int x1,y1,x2,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if(x1 == x2){
			if(y1 > y2) swap(y1,y2);
			ps[++m] = Point(0,x1,y1,0);
			ps[++m] = Point(2,x1,y2,0);
		}else{
			if(x1 > x2) swap(x1,x2);
			ps[++m] = Point(1,x1,y1,i);
			rig[i] = x2;
		}
	}
	printf("%d\n",work());
	return 0;
}

