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"

#define int long long

using namespace std;
#define REP(i, s, n) for(signed i = (s); i < signed(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for(int i = signed(n) - 1; i >= 0; i--)
#define all(co) co.begin(), co.end()

typedef pair<int, int> P;
typedef long long LL;

#ifdef int
const long long INF = 1ll << 62ll;
#else
const singed INF = 1 << 29;
#endif

struct edge{ int from, to, cost; };

int dr[] = { -1, 0, 1, 0 };
int dc[] = { 0, 1, 0, -1 };

template<typename T = int>
vector<vector<T>> vvector(int h, int w, T def = T()){ return move(vector<vector<T>>(h, vector<T>(w, def))); }

const int MAX_SIZE = 200001;
int BIT[MAX_SIZE];
int BIT_N;

void add(int i, int x)
{
	while (i <= BIT_N)
	{
		BIT[i] += x;
		i += i & -i;
	}
}

int sum(int i)
{
	int s = 0;
	while (i > 0)
	{
		s += BIT[i];
		i -= i & -i;
	}
	return s;
}

signed main()
{
	int n;
	while (cin >> n && n)
	{
		typedef pair<P, P> PP;
		vector<PP> lines;
		set<int> points;
		rep(i, n)
		{
			int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
			if (y1 > y2) swap(y1, y2);
			if(y1 == y2) lines.push_back(PP(P(y1, 1), P(x1, x2)));
			else
			{
				lines.push_back(PP(P(y1, 0), P(x1, x2)));
				lines.push_back(PP(P(y2, 2), P(x1, x2)));
			}
			points.insert(x1);
			points.insert(x2);
		}
		map<int, int> table;
		int idx = 1;
		for (int x : points)
		{
			table[x] = idx;
			idx++;
		}
		BIT_N = table.size();
		sort(all(lines));

		int ans = 0;
		vector<int> tate(table.size() + 1);
		for (PP pp : lines)
		{
			int y1 = pp.first.first, option = pp.first.second,
				x1 = table[pp.second.first], x2 = table[pp.second.second];
			if (x1 > x2) swap(x1, x2);

			if (option == 0) add(x1, 1);
			if (option == 2) add(x1, -1);
			if (option == 1) ans += sum(x2) - sum(x1 - 1);
		}

		cout << ans << endl;
	}
	return 0;
}