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<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

typedef long long ll;

bool debug = false;
const int NIL = -1;
const int INF = 1000000000;
const int NUM = 2000000001;
clock_t START, END;

int ans;

struct Point {
	int x, y, t, l;
	Point(int x = 0, int y = 0) :x(x), y(y) {}
	bool operator < (const Point& rhs) const {
		if (y == rhs.y)
			return t > rhs.t;
		return y < rhs.y;
	}
};
struct Node {
	Node* ch[2];
	int r, v;
	int cmp(int x) const {
		if (x == v) return -1;
		return x < v ? 0 : 1;
	}
};
struct Treap {
	void rotate(Node*& o, int d) {
		Node* k = o->ch[d ^ 1];
		o->ch[d ^ 1] = k->ch[d];
		k->ch[d] = o;
		o = k;
	}
	void insert(Node*& o, int x) {
		if (o == NULL) {
			o = new Node();
			o->ch[0] = o->ch[1] = NULL;
			o->v = x;
			o->r = rand();
		}
		else {
			int d = o->cmp(x);
			insert(o->ch[d], x);
			if (o->ch[d]->r > o->r)
				rotate(o, d ^ 1);
		}
	}
	void remove(Node*& o, int x) {
		int d = o->cmp(x);
		if (d == -1) {
			if (o->ch[0] == NULL)
				o = o->ch[1];
			else if (o->ch[1] == NULL)
				o = o->ch[0];
			else {
				int d2 = (o->ch[0]->r > o->ch[1]->r ? 1 : 0);
				rotate(o, d2);
				remove(o->ch[d2], x);
			}
		}
		else
			remove(o->ch[d], x);
	}
	void find(Node* o, int l, int r) {
		if (o) {
			int L = o->cmp(l);
			int R = o->cmp(r);
			if ((L == -1 || L == 0) && (R == -1 || R == 1)) {
				ans++;
				find(o->ch[0], l, r);
				find(o->ch[1], l, r);
			}
			else if (L == 1)
				find(o->ch[1], l, r);
			else
				find(o->ch[0], l, r);
		}
	}
};

int main(void)
{
	if (debug) {
		START = clock();
		freopen("in29.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	};
	int n;
	Point a, b;
	vector<Point> points;
	Treap Set;
	Node* root = NULL;
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d%d%d%d", &a.x, &a.y, &b.x, &b.y);
		if (a.y == b.y) {
			if (a.x > b.x)
				swap(a.x, b.x);
			a.t = 0;
			a.l = b.x;
			points.push_back(a);
		}
		else {
			if (a.y > b.y)
				swap(a.y, b.y);
			a.t = 1;
			b.t = -1;
			points.push_back(a);
			points.push_back(b);
		}
	}
	sort(points.begin(), points.end());
	for (vector<Point>::iterator it = points.begin(); it != points.end(); it++) {
		if (it->t == 0) {
			if (root)
				Set.find(root, it->x, it->l);
		}
		else if (it->t == 1) {
			Set.insert(root, it->x);
		}
		else
			Set.remove(root, it->x);
	}
	cout << ans << endl;
	if (debug) {
		END = clock();
		double endtime = (double)(END - START) / 1000;
		printf("total time = %lf s", endtime);
	}
	return 0;
}
