#include <bits/stdc++.h>
using namespace std;
char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
inline long long readll() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
void write(int x) {
  if (!x) putchar('0');
  if (x < 0) x = -x, putchar('-');
  static int sta[20];
  register int tot = 0;
  while (x) sta[tot++] = x % 10, x /= 10;
  while (tot) putchar(sta[--tot] + 48);
}
const int INF = 0x3f3f3f3f, maxn = 5007;
const long long MOD = 998244353;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long P = 19260817;
int mod1(int x) {
  if (x >= MOD) x -= MOD;
  return x;
}
int n;
struct node {
  int pmtQwQ, x2, pmtpmt, y2;
  friend bool operator<(const node &a, const node &b) { return a.y2 < b.y2; }
} row[maxn + 5], col[maxn + 5];
struct BIT {
  int t[maxn << 2];
  void clear() { memset(t, 0, sizeof(t)); }
  void update(int x, int val) {
    for (; x <= 10000; x += x & (-x)) t[x] += val;
  }
  int query(int x) {
    int rt = 0;
    for (; x; x -= (x & (-x))) rt += t[x];
    return rt;
  }
} T;
int ox[maxn << 1], oy[maxn << 1];
int cnt1, cnt2, cntx, cnty;
queue<int> q;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int pmtQwQ, x2, y2, pmtpmt;
    scanf("%d%d%d%d", &pmtQwQ, &pmtpmt, &x2, &y2);
    ox[++cntx] = pmtQwQ, ox[++cntx] = x2;
    oy[++cnty] = pmtpmt, oy[++cnty] = y2;
    if (pmtQwQ > x2) swap(pmtQwQ, x2);
    if (pmtpmt > y2) swap(pmtpmt, y2);
    if (pmtpmt == y2)
      row[++cnt1] = (node){pmtQwQ, x2, pmtpmt, y2};
    else
      col[++cnt2] = (node){pmtQwQ, x2, pmtpmt, y2};
  }
  sort(ox + 1, ox + cntx + 1), sort(oy + 1, oy + cnty + 1);
  cntx = unique(ox + 1, ox + cntx + 1) - ox - 1;
  cnty = unique(oy + 1, oy + cnty + 1) - oy - 1;
  for (int i = 1; i <= cnt1; i++) {
    row[i].pmtQwQ = lower_bound(ox + 1, ox + cntx + 1, row[i].pmtQwQ) - ox;
    row[i].x2 = lower_bound(ox + 1, ox + cntx + 1, row[i].x2) - ox;
    row[i].pmtpmt = lower_bound(oy + 1, oy + cnty + 1, row[i].pmtpmt) - oy;
    row[i].y2 = lower_bound(oy + 1, oy + cnty + 1, row[i].y2) - oy;
  }
  for (int i = 1; i <= cnt2; i++) {
    col[i].pmtQwQ = lower_bound(ox + 1, ox + cntx + 1, col[i].pmtQwQ) - ox;
    col[i].x2 = lower_bound(ox + 1, ox + cntx + 1, col[i].x2) - ox;
    col[i].pmtpmt = lower_bound(oy + 1, oy + cnty + 1, col[i].pmtpmt) - oy;
    col[i].y2 = lower_bound(oy + 1, oy + cnty + 1, col[i].y2) - oy;
  }
  sort(row + 1, row + cnt1 + 1), sort(col + 1, col + cnt2 + 1);
  queue<int> q;
  long long ans = 0;
  for (int i = 1; i <= cnt1; i++) {
    T.clear();
    while (!q.empty()) q.pop();
    for (int j = 1; j <= cnt2; j++) {
      if (row[i].pmtQwQ <= col[j].pmtQwQ && row[i].x2 >= col[j].pmtQwQ &&
          col[j].pmtpmt <= row[i].pmtpmt && col[j].y2 >= row[i].y2) {
        T.update(col[j].pmtQwQ, 1);
        q.push(j);
      }
    }
    for (int j = i + 1; j <= cnt1; j++) {
      while (!q.empty() && col[q.front()].y2 < row[j].pmtpmt) {
        T.update(col[q.front()].pmtQwQ, -1);
        q.pop();
      }
      int l = max(row[i].pmtQwQ, row[j].pmtQwQ), r = min(row[i].x2, row[j].x2);
      if (l >= r) continue;
      int res = T.query(r) - T.query(l - 1);
      ans += 1ll * res * (res - 1) / 2;
    }
  }
  printf("%lld", ans);
  return 0;
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

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;
char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
inline long long readll() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
void write(int x) {
  if (!x) putchar('0');
  if (x < 0) x = -x, putchar('-');
  static int sta[20];
  register int tot = 0;
  while (x) sta[tot++] = x % 10, x /= 10;
  while (tot) putchar(sta[--tot] + 48);
}
const int INF = 0x3f3f3f3f, maxn = 5007;
const long long MOD = 998244353;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long P = 19260817;
int mod1(int x) {
  if (x >= MOD) x -= MOD;
  return x;
}
int n;
struct node {
  int pmtQwQ, x2, pmtpmt, y2;
  friend bool operator<(const node &a, const node &b) { return a.y2 < b.y2; }
} row[maxn + 5], col[maxn + 5];
struct BIT {
  int t[maxn << 2];
  void clear() { memset(t, 0, sizeof(t)); }
  void update(int x, int val) {
    for (; x <= 10000; x += x & (-x)) t[x] += val;
  }
  int query(int x) {
    int rt = 0;
    for (; x; x -= (x & (-x))) rt += t[x];
    return rt;
  }
} T;
int ox[maxn << 1], oy[maxn << 1];
int cnt1, cnt2, cntx, cnty;
queue<int> q;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int pmtQwQ, x2, y2, pmtpmt;
    scanf("%d%d%d%d", &pmtQwQ, &pmtpmt, &x2, &y2);
    ox[++cntx] = pmtQwQ, ox[++cntx] = x2;
    oy[++cnty] = pmtpmt, oy[++cnty] = y2;
    if (pmtQwQ > x2) swap(pmtQwQ, x2);
    if (pmtpmt > y2) swap(pmtpmt, y2);
    if (pmtpmt == y2)
      row[++cnt1] = (node){pmtQwQ, x2, pmtpmt, y2};
    else
      col[++cnt2] = (node){pmtQwQ, x2, pmtpmt, y2};
  }
  sort(ox + 1, ox + cntx + 1), sort(oy + 1, oy + cnty + 1);
  cntx = unique(ox + 1, ox + cntx + 1) - ox - 1;
  cnty = unique(oy + 1, oy + cnty + 1) - oy - 1;
  for (int i = 1; i <= cnt1; i++) {
    row[i].pmtQwQ = lower_bound(ox + 1, ox + cntx + 1, row[i].pmtQwQ) - ox;
    row[i].x2 = lower_bound(ox + 1, ox + cntx + 1, row[i].x2) - ox;
    row[i].pmtpmt = lower_bound(oy + 1, oy + cnty + 1, row[i].pmtpmt) - oy;
    row[i].y2 = lower_bound(oy + 1, oy + cnty + 1, row[i].y2) - oy;
  }
  for (int i = 1; i <= cnt2; i++) {
    col[i].pmtQwQ = lower_bound(ox + 1, ox + cntx + 1, col[i].pmtQwQ) - ox;
    col[i].x2 = lower_bound(ox + 1, ox + cntx + 1, col[i].x2) - ox;
    col[i].pmtpmt = lower_bound(oy + 1, oy + cnty + 1, col[i].pmtpmt) - oy;
    col[i].y2 = lower_bound(oy + 1, oy + cnty + 1, col[i].y2) - oy;
  }
  sort(row + 1, row + cnt1 + 1), sort(col + 1, col + cnt2 + 1);
  queue<int> q;
  long long ans = 0;
  for (int i = 1; i <= cnt1; i++) {
    T.clear();
    while (!q.empty()) q.pop();
    for (int j = 1; j <= cnt2; j++) {
      if (row[i].pmtQwQ <= col[j].pmtQwQ && row[i].x2 >= col[j].pmtQwQ &&
          col[j].pmtpmt <= row[i].pmtpmt && col[j].y2 >= row[i].y2) {
        T.update(col[j].pmtQwQ, 1);
        q.push(j);
      }
    }
    for (int j = i + 1; j <= cnt1; j++) {
      while (!q.empty() && col[q.front()].y2 < row[j].pmtpmt) {
        T.update(col[q.front()].pmtQwQ, -1);
        q.pop();
      }
      int l = max(row[i].pmtQwQ, row[j].pmtQwQ), r = min(row[i].x2, row[j].x2);
      if (l >= r) continue;
      int res = T.query(r) - T.query(l - 1);
      ans += 1ll * res * (res - 1) / 2;
    }
  }
  printf("%lld", ans);
  return 0;
}

```