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 <vector>
#include <set>
#include <unordered_map>
#include <algorithm>

using namespace std;

namespace {
	struct EndPoint
	{
		EndPoint(int _x, pair<int, int> _y) : x(_x), y(_y) {}
		bool operator<(const EndPoint& rhs) const { return x < rhs.x; }

		int x;
		pair<int, int> y;
	};
}

template<size_t N>
struct FenwickTree
{
	FenwickTree() : a(N, 0) {}

	int sum(int x)
	{
		int s = 0;
		for (; x>0; x -= x&-x) {
			s = (s + a[x]);
		}
		return s;
	}

	void add(int x, int i)
	{
		for (; x<N; x += x&-x) {
			a[x] = (a[x] + i);
		}
	}

	vector<int> a;
};

static int countIntersection(const vector<EndPoint>& X)
{
	int num_int = 0;
	FenwickTree<500000> bit;
	for (size_t i = 0; i < X.size(); i++) {
		if (X[i].y.second < -500000) {
			bit.add(X[i].y.first + 1, 1);
		}
		else if (X[i].y.second > 500000) {
			bit.add(X[i].y.first + 1, -1);
		}
		else {
			num_int += bit.sum(X[i].y.second + 1) - bit.sum(X[i].y.first + 1);
		}
	}

	return num_int;
}

int main()
{
	int n = 0;
	cin >> n;

	vector<int> x, y;
	vector<pair<int, int> > c;
	for (int i = 0; i < n; i++) {
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		x.push_back(x1);
		x.push_back(x2);
		y.push_back(y1);
		y.push_back(y2);
		c.push_back(make_pair(x1, y1));
		c.push_back(make_pair(x2, y2));
	}

	sort(x.begin(), x.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	sort(y.begin(), y.end());
	y.erase(unique(y.begin(), y.end()), y.end());
	unordered_map<int, int> mx, my;
	for (int i = 0; i < x.size(); i++) {
		mx[x[i]] = i;
	}
	for (int i = 0; i < y.size(); i++) {
		my[y[i]] = i;
	}

	vector<EndPoint> X;
	for (int i = 0; i < n; i++) {
		int x1 = mx[c[i * 2].first], y1 = my[c[i * 2].second], x2 = mx[c[i * 2 + 1].first], y2 = my[c[i * 2 + 1].second];
		if (y1 == y2) {
			X.push_back(EndPoint(min(x1, x2) * 4 - 1, make_pair(y1 * 4, -1000000)));
			X.push_back(EndPoint(max(x1, x2) * 4 + 1, make_pair(y1 * 4, 1000000)));
		}
		else {
			X.push_back(EndPoint(x1 * 4, make_pair(min(y1, y2) * 4 - 1, max(y1, y2) * 4 + 1)));
		}
	}

	sort(X.begin(), X.end());
	cout << countIntersection(X) << endl;
	return 0;
}
