#include <bits/stdc++.h>
using namespace std;
const int N = 10000 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);
template <class T, class S>
inline void add(T &a, S b) {
  a += b;
  if (a >= mod) a -= mod;
}
template <class T, class S>
inline void sub(T &a, S b) {
  a -= b;
  if (a < 0) a += mod;
}
template <class T, class S>
inline bool chkmax(T &a, S b) {
  return a < b ? a = b, true : false;
}
template <class T, class S>
inline bool chkmin(T &a, S b) {
  return a > b ? a = b, true : false;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
struct Bit {
  int a[N];
  void init() { memset(a, 0, sizeof(a)); }
  void modify(int x, int v) {
    for (int i = x; i < N; i += i & -i) {
      a[i] += v;
    }
  }
  int sum(int x) {
    int ans = 0;
    for (int i = x; i; i -= i & -i) {
      ans += a[i];
    }
    return ans;
  }
  int query(int L, int R) {
    if (L > R) return 0;
    return sum(R) - sum(L - 1);
  }
} bit;
int cnth, cntv;
struct H {
  bool operator<(const H &rhs) const { return x < rhs.x; }
  int x, y1, y2;
} h[N];
struct V {
  int y, x1, x2;
  bool operator<(const V &rhs) const { return x1 < rhs.x1; }
} v[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int X1, Y1, X2, Y2;
    scanf("%d%d%d%d", &X1, &Y1, &X2, &Y2);
    X1 += 5001;
    Y1 += 5001;
    X2 += 5001;
    Y2 += 5001;
    if (X1 == X2) {
      h[++cnth] = H{X1, min(Y1, Y2), max(Y1, Y2)};
    } else {
      v[++cntv] = V{Y1, min(X1, X2), max(X1, X2)};
    }
  }
  sort(v + 1, v + 1 + cntv);
  sort(h + 1, h + 1 + cnth);
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      que;
  long long tmp;
  int L, R;
  long long ans = 0;
  for (int i = 1; i <= cnth; i++) {
    while (!que.empty()) que.pop();
    bit.init();
    int p = 1;
    while (p <= cntv && v[p].x1 <= h[i].x) {
      bit.modify(v[p].y, 1);
      que.push(make_pair(v[p].x2, v[p].y));
      p++;
    }
    for (int j = i + 1; j <= cnth; j++) {
      while (!que.empty() && que.top().first < h[j].x) {
        bit.modify(que.top().second, -1);
        que.pop();
      }
      L = max(h[i].y1, h[j].y1);
      R = min(h[i].y2, h[j].y2);
      tmp = bit.query(L, R);
      ans += tmp * (tmp - 1) / 2;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

### Prompt

Please provide a cpp coded solution 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;
const int N = 10000 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);
template <class T, class S>
inline void add(T &a, S b) {
  a += b;
  if (a >= mod) a -= mod;
}
template <class T, class S>
inline void sub(T &a, S b) {
  a -= b;
  if (a < 0) a += mod;
}
template <class T, class S>
inline bool chkmax(T &a, S b) {
  return a < b ? a = b, true : false;
}
template <class T, class S>
inline bool chkmin(T &a, S b) {
  return a > b ? a = b, true : false;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
struct Bit {
  int a[N];
  void init() { memset(a, 0, sizeof(a)); }
  void modify(int x, int v) {
    for (int i = x; i < N; i += i & -i) {
      a[i] += v;
    }
  }
  int sum(int x) {
    int ans = 0;
    for (int i = x; i; i -= i & -i) {
      ans += a[i];
    }
    return ans;
  }
  int query(int L, int R) {
    if (L > R) return 0;
    return sum(R) - sum(L - 1);
  }
} bit;
int cnth, cntv;
struct H {
  bool operator<(const H &rhs) const { return x < rhs.x; }
  int x, y1, y2;
} h[N];
struct V {
  int y, x1, x2;
  bool operator<(const V &rhs) const { return x1 < rhs.x1; }
} v[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int X1, Y1, X2, Y2;
    scanf("%d%d%d%d", &X1, &Y1, &X2, &Y2);
    X1 += 5001;
    Y1 += 5001;
    X2 += 5001;
    Y2 += 5001;
    if (X1 == X2) {
      h[++cnth] = H{X1, min(Y1, Y2), max(Y1, Y2)};
    } else {
      v[++cntv] = V{Y1, min(X1, X2), max(X1, X2)};
    }
  }
  sort(v + 1, v + 1 + cntv);
  sort(h + 1, h + 1 + cnth);
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      que;
  long long tmp;
  int L, R;
  long long ans = 0;
  for (int i = 1; i <= cnth; i++) {
    while (!que.empty()) que.pop();
    bit.init();
    int p = 1;
    while (p <= cntv && v[p].x1 <= h[i].x) {
      bit.modify(v[p].y, 1);
      que.push(make_pair(v[p].x2, v[p].y));
      p++;
    }
    for (int j = i + 1; j <= cnth; j++) {
      while (!que.empty() && que.top().first < h[j].x) {
        bit.modify(que.top().second, -1);
        que.pop();
      }
      L = max(h[i].y1, h[j].y1);
      R = min(h[i].y2, h[j].y2);
      tmp = bit.query(L, R);
      ans += tmp * (tmp - 1) / 2;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

```