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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-9, pi = acos(-1.0);
namespace std {
	bool operator<(const Point &lhs, const Point &rhs) {
		if (lhs.real() < rhs.real() - eps) return true;
		if (lhs.real() > rhs.real() + eps) return false;
		return lhs.imag() < rhs.imag();
	}
}
Point input_point() { ld x, y; cin >> x >> y; return Point(x, y); } // ????????\???
bool eq(ld a, ld b) { return (abs(a - b) < eps); } // ????????????????????????
ld dot(Point a, Point b) { return real(conj(a) * b); } // ??????
ld cross(Point a, Point b) { return imag(conj(a) * b); } // ??????

														 // ??´????????????
class Line {
public:
	Point a, b;
	Line() : a(Point(0, 0)), b(Point(0, 0)) {}
	Line(Point a, Point b) : a(a), b(b) {}
	Point operator[](const int _num) {
		if (_num == 0)return a;
		else if (_num == 1)return b;
		else assert(false);
	}
};

// ????????????
class Circle {
public:
	Point p;
	ld r;
	Circle() : p(Point(0, 0)), r(0) {}
	Circle(Point p, ld r) : p(p), r(r) {}
};

/* ????????????(????????????????????????) */
// ??????????¨????
#define BOTTOM 0
#define LEFT 1
#define RIGHT 2
#define TOP 3

class EndPoint {
public:
	Point p;
	ll seg, st; // ??\????????????ID, ??????????¨????
	EndPoint() {}
	EndPoint(Point p, ll seg, ll st) :p(p), seg(seg), st(st) {}
	
	bool operator < (const EndPoint& ep) const {
		// y ??§?¨?????°???????????????´???
		if (p.imag() == ep.p.imag()) {
			return st < ep.st; // y ??????????????´??????, ?????????, ?????????, ?????????, ???????????????????????????
		}
		else return p.imag() < ep.p.imag();
	}
};

vector<EndPoint> EP;
// ??????????????????: ????????????????????????
ll manhattanIntersection(vector<Line> S) {
	ll n = S.size();

	for (int i = 0, k = 0; i < n;i++) {
		// ?????? p1, p2 ??????????????????????????¶??????????????´
		if (S[i].a.imag() == S[i].b.imag()) {
			if (S[i].a.real() > S[i].b.real()) swap(S[i].a, S[i].b);
		}
		else if (S[i].a.imag() > S[i].b.imag()) swap(S[i].a, S[i].b);

		if (S[i].a.imag() == S[i].b.imag()) {	// ?°´????????????????????????????????????
			EP[k++] = EndPoint(S[i].a, i, LEFT);
			EP[k++] = EndPoint(S[i].b, i, RIGHT);
		}
		else {									// ?????´?????????????????????????????????
			EP[k++] = EndPoint(S[i].a, i, BOTTOM);
			EP[k++] = EndPoint(S[i].b, i, TOP);
		}
	}
	sort(EP.begin(), EP.end()); // ????????? y ??§?¨??????¢?????????????????´???

	set<ll> BT; // ????????¢?´¢??¨
	BT.insert(INF); // ??????????¨????
	ll cnt = 0;

	for (int i = 0; i < 2 * n;i++) {
		if (EP[i].st == TOP) {
			BT.erase(EP[i].p.real()); // ??????????????????
		}
		else if (EP[i].st == BOTTOM) {
			BT.insert(EP[i].p.real()); // ??????????????????
		}
		else if (EP[i].st == LEFT) {
			auto b = lower_bound(BT.begin(), BT.end(), S[EP[i].seg].a.real()); // O(log n)
			auto e = upper_bound(BT.begin(), BT.end(), S[EP[i].seg].b.real()); // O(log n)
			cnt += distance(b, e); // b ??¨ e ????????¢(????????°)?????????, O(k)
		}
	}
	return cnt;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll n; cin >> n;
	EP.resize(2 * n);
	vector<Line> S;
	for (int i = 0; i < n;i++) {
		Point a = input_point(), b = input_point();
		S.push_back(Line(a, b));
	}
	cout << manhattanIntersection(S) << endl;
	return 0;
}