#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " , ";
  __f(comma + 1, args...);
}
int i, j, n, y, y2;
const int N = 10005;
const int D = 5000;
int st[4 * N];
void update(int node, int l, int r, int i, int val) {
  if (l > r or l > i or r < i) return;
  if (l == r and l == i) {
    st[node] += val;
    return;
  }
  int mid = (l + r) / 2;
  update(2 * node + 1, l, mid, i, val);
  update(2 * node + 2, mid + 1, r, i, val);
  st[node] = st[2 * node + 1] + st[2 * node + 2];
}
int query(int node, int l, int r, int i, int j) {
  if (l > r or l > j or r < i) return 0;
  if (i <= l and r <= j) return st[node];
  int mid = (l + r) / 2;
  return query(2 * node + 1, l, mid, i, j) +
         query(2 * node + 2, mid + 1, r, i, j);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  vector<pair<int, int> > h[N], v[N];
  for (i = 0; i < n; ++i) {
    int u, v1, w, x;
    cin >> u >> v1 >> w >> x;
    u += D, v1 += D, w += D, x += D;
    if (u == w)
      v[u].push_back({min(v1, x), max(v1, x)});
    else
      h[v1].push_back({min(u, w), max(u, w)});
  }
  long long ans = 0;
  vector<int> bag[N];
  for (y = 0; y < N; ++y) {
    for (auto seg : h[y]) {
      for (i = 0; i < N; ++i) bag[i].clear();
      memset(st, 0, sizeof st);
      int l = seg.first;
      int r = seg.second;
      for (i = l; i <= r; ++i) {
        for (auto xseg : v[i]) {
          if (xseg.first <= y and xseg.second > y) {
            bag[xseg.second].push_back(i);
            update(0, 0, N - 1, i, 1);
          }
        }
      }
      for (y2 = y + 1; y2 < N; ++y2) {
        for (auto seg2 : h[y2]) {
          int q = query(0, 0, N - 1, seg2.first, seg2.second);
          ans += q * 1LL * (q - 1) / 2;
        }
        for (auto x : bag[y2]) update(0, 0, N - 1, x, -1);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

There are n segments drawn on a plane; the i-th segment connects two points (x_{i, 1}, y_{i, 1}) and (x_{i, 2}, y_{i, 2}). Each segment is non-degenerate, and is either horizontal or vertical — formally, for every i ∈ [1, n] either x_{i, 1} = x_{i, 2} or y_{i, 1} = y_{i, 2} (but only one of these conditions holds). Only segments of different types may intersect: no pair of horizontal segments shares any common points, and no pair of vertical segments shares any common points.

We say that four segments having indices h_1, h_2, v_1 and v_2 such that h_1 < h_2 and v_1 < v_2 form a rectangle if the following conditions hold:

  * segments h_1 and h_2 are horizontal; 
  * segments v_1 and v_2 are vertical; 
  * segment h_1 intersects with segment v_1; 
  * segment h_2 intersects with segment v_1; 
  * segment h_1 intersects with segment v_2; 
  * segment h_2 intersects with segment v_2. 



Please calculate the number of ways to choose four segments so they form a rectangle. Note that the conditions h_1 < h_2 and v_1 < v_2 should hold.

Input

The first line contains one integer n (1 ≤ n ≤ 5000) — the number of segments.

Then n lines follow. The i-th line contains four integers x_{i, 1}, y_{i, 1}, x_{i, 2} and y_{i, 2} denoting the endpoints of the i-th segment. All coordinates of the endpoints are in the range [-5000, 5000].

It is guaranteed that each segment is non-degenerate and is either horizontal or vertical. Furthermore, if two segments share a common point, one of these segments is horizontal, and another one is vertical.

Output

Print one integer — the number of ways to choose four segments so they form a rectangle.

Examples

Input


7
-1 4 -1 -2
6 -1 -2 -1
-2 3 6 3
2 -2 2 4
4 -1 4 3
5 3 5 1
5 2 1 2


Output


7


Input


5
1 5 1 0
0 1 5 1
5 4 0 4
4 2 4 0
4 3 4 5


Output


0

Note

The following pictures represent sample cases:

<image> <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " , ";
  __f(comma + 1, args...);
}
int i, j, n, y, y2;
const int N = 10005;
const int D = 5000;
int st[4 * N];
void update(int node, int l, int r, int i, int val) {
  if (l > r or l > i or r < i) return;
  if (l == r and l == i) {
    st[node] += val;
    return;
  }
  int mid = (l + r) / 2;
  update(2 * node + 1, l, mid, i, val);
  update(2 * node + 2, mid + 1, r, i, val);
  st[node] = st[2 * node + 1] + st[2 * node + 2];
}
int query(int node, int l, int r, int i, int j) {
  if (l > r or l > j or r < i) return 0;
  if (i <= l and r <= j) return st[node];
  int mid = (l + r) / 2;
  return query(2 * node + 1, l, mid, i, j) +
         query(2 * node + 2, mid + 1, r, i, j);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  vector<pair<int, int> > h[N], v[N];
  for (i = 0; i < n; ++i) {
    int u, v1, w, x;
    cin >> u >> v1 >> w >> x;
    u += D, v1 += D, w += D, x += D;
    if (u == w)
      v[u].push_back({min(v1, x), max(v1, x)});
    else
      h[v1].push_back({min(u, w), max(u, w)});
  }
  long long ans = 0;
  vector<int> bag[N];
  for (y = 0; y < N; ++y) {
    for (auto seg : h[y]) {
      for (i = 0; i < N; ++i) bag[i].clear();
      memset(st, 0, sizeof st);
      int l = seg.first;
      int r = seg.second;
      for (i = l; i <= r; ++i) {
        for (auto xseg : v[i]) {
          if (xseg.first <= y and xseg.second > y) {
            bag[xseg.second].push_back(i);
            update(0, 0, N - 1, i, 1);
          }
        }
      }
      for (y2 = y + 1; y2 < N; ++y2) {
        for (auto seg2 : h[y2]) {
          int q = query(0, 0, N - 1, seg2.first, seg2.second);
          ans += q * 1LL * (q - 1) / 2;
        }
        for (auto x : bag[y2]) update(0, 0, N - 1, x, -1);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

```