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 <algorithm>

using namespace std;

namespace {
	template<class T>
	struct Vec2
	{
		Vec2(T _x, T _y) : x(_x), y(_y) {}
		Vec2 operator+(const Vec2& rhs) const { return Vec2(x + rhs.x, y + rhs.y); }
		Vec2 operator-(const Vec2& rhs) const { return Vec2(x - rhs.x, y - rhs.y); }
		Vec2 operator*(const T t) const { return Vec2(x*t, y*t); }
		bool operator<(const Vec2& rhs) const { return x != rhs.x ? x < rhs.x : y < rhs.y; }
		T dot(const Vec2& rhs) const { return x*rhs.x + y*rhs.y; }
		T cross(const Vec2& rhs) const { return x*rhs.y - y*rhs.x; }
		T x, y;
	};

	typedef long long ll;
	typedef Vec2<ll> P;

	struct EndPoint
	{
		EndPoint(const pair<P, P>& _seg, bool _start) : seg(_seg), start(_start) {}
		bool operator<(const EndPoint& rhs) const { return cod().x < rhs.cod().x; }
		const P& cod() const { return start ? seg.first : seg.second; }

		pair<P, P> seg;
		bool start;
	};
}

static int countIntersection(const vector<EndPoint>& X)
{
	int num_int = 0;
	set<ll> Y;
	for (size_t i = 0; i < X.size(); i++) {
		const P& p0 = X[i].seg.first;
		const P& p1 = X[i].seg.second;
		if (p0.x == p1.x) {
			num_int += distance(Y.lower_bound(p0.y), Y.lower_bound(p1.y));
		}
		else if (X[i].start) {
			Y.insert(p0.y);
		}
		else {
			Y.erase(p0.y);
		}
	}

	return num_int;
}

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

	vector<EndPoint> X;
	for (int i = 0; i < n; i++) {
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		P a(x1, y1), b(x2, y2);
		if (b < a) {
			swap(a, b);
		}
		a = a * 4;
		b = b * 4;
		if (a.y == b.y) {
			a.x--;
			b.x++;
			X.push_back(EndPoint(make_pair(a, b), true));
			X.push_back(EndPoint(make_pair(a, b), false));
		}
		else {
			a.y--;
			b.y++;
			X.push_back(EndPoint(make_pair(a, b), false));
		}
	}
	sort(X.begin(), X.end());
	cout << countIntersection(X) << endl;
	return 0;
}
