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>
#define maxn 100005
#define maxpoints 200005
#define maxlen 200005
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int DOWN = 0;
const int LEFT = 1;
const int UP = 2;
int n,rig[maxn],x1[maxn],x2[maxn],y1_[maxn],y2[maxn];
int compress(int* t1,int* t2){
	vector <int> xs;
	xs.clear();
	for(int i=1;i<=n;i++){
		xs.push_back(t1[i]);
		xs.push_back(t2[i]);
	}
	sort(xs.begin(),xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	for(int i=1;i<=n;i++){
		t1[i] = lower_bound(xs.begin(),xs.end(),t1[i]) - xs.begin() + 1;
		t2[i] = lower_bound(xs.begin(),xs.end(),t2[i]) - xs.begin() + 1;
	}
	return xs.size();
}
struct Point{
	int x,y,type,id;//id: belong to which segment.
	Point(int x = 0,int y = 0,int type = 0,int id = 0): x(x),y(y),type(type),id(id) {}
	bool operator < (const Point &p)const
	{
		if(y == p.y){
			if(type == p.type) return x < p.x;
			return type < p.type;
		}
		return y < p.y;
	}
}ps[maxpoints]; int m;
int bit[maxlen],len;
void add(int pos,int x){
	for(int i=pos;i<=len;i += i & -i) bit[i] += x;
}
int query(int pos){
	int res = 0;
	for(int i=pos;i>0;i -= i & -i) res += bit[i];
	return res;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d%d%d",&x1[i],&y1_[i],&x2[i],&y2[i]);
	len = compress(x1,x2);
	for(int i=1;i<=n;i++){
		if(x1[i] == x2[i]){
			if(y1_[i] > y2[i]) swap(y1_[i],y2[i]);
			ps[++m] = Point(x1[i],y1_[i],DOWN,i);
			ps[++m] = Point(x2[i],y2[i],UP,i);
		}else{
			if(x1[i] > x2[i]) swap(x1[i],x2[i]);
			ps[++m] = Point(x1[i],y1_[i],LEFT,i);
			rig[i] = x2[i];
		}
	}
	sort(ps + 1,ps + m + 1);
	memset(bit,0,sizeof(bit));
	int ans = 0;
	for(int i=1;i<=m;i++){
		Point p = ps[i];
		if(p.type == DOWN) add(p.x,1);
		else if(p.type == UP) add(p.x,-1);
		else ans += query(rig[p.id]) - query(p.x - 1);
	}
	printf("%d\n",ans);
	return 0;
}

