#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e4 + 10;
struct Node1 {
  Node1(int y = 0, int xl = 0, int xr = 0) : y(y), xl(xl), xr(xr) {}
  int y, xl, xr;
};
struct Node2 {
  Node2() {}
  Node2(int x, int y, int tag) : x(x), y(y), tag(tag) {}
  int x, y, tag;
};
int n;
vector<Node1> hor;
vector<Node2> vec;
int bit[MAXN], vis[MAXN];
void update(int p, int v) {
  for (int i = p; i <= 10001; i += (i & -i)) {
    bit[i] += v;
  }
}
int get(int p) {
  int ret = 0;
  for (int i = p; i > 0; i -= (i & -i)) {
    ret += bit[i];
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  int len = 0;
  for (int i = 1; i <= n; i++) {
    int sx, sy, ex, ey;
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    if (sx > ex) swap(sx, ex);
    if (sy > ey) swap(sy, ey);
    sx += 5001;
    sy += 5001;
    ex += 5001;
    ey += 5001;
    if (sx == ex) {
      vec.push_back(Node2(sx, sy, len));
      vec.push_back(Node2(sx, ey, len + 1));
      len += 2;
    } else {
      hor.push_back(Node1(sy, sx, ex));
    }
  }
  sort(hor.begin(), hor.end(), [](Node1 n1, Node1 n2) { return n1.y < n2.y; });
  sort(vec.begin(), vec.end(), [](Node2 n1, Node2 n2) { return n1.y < n2.y; });
  long long ans = 0;
  for (int i = 0; i < hor.size(); i++) {
    memset(bit, 0, sizeof(bit));
    memset(vis, 0, sizeof(vis));
    int p = 0;
    for (; p < vec.size() && vec[p].y <= hor[i].y; p++) {
      if (vec[p].tag % 2 == 0) {
        vis[vec[p].tag / 2] = 1;
        update(vec[p].x, 1);
      } else {
        vis[vec[p].tag / 2] = 0;
        update(vec[p].x, -1);
      }
    }
    for (int j = i + 1; j < hor.size(); j++) {
      for (; p < vec.size() && vec[p].y < hor[j].y; p++) {
        if (vec[p].tag % 2 == 1 && vis[vec[p].tag / 2] == 1) {
          vis[vec[p].tag / 2] = 0;
          update(vec[p].x, -1);
        }
      }
      int liml = max(hor[i].xl, hor[j].xl);
      int limr = min(hor[i].xr, hor[j].xr);
      if (liml > limr) continue;
      long long cnt = get(limr) - get(liml - 1);
      ans += cnt * (cnt - 1) / 2;
    }
  }
  printf("%lld\n", ans);
}

### Prompt

In cpp, your task is to solve 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;
const int MAXN = 2e4 + 10;
struct Node1 {
  Node1(int y = 0, int xl = 0, int xr = 0) : y(y), xl(xl), xr(xr) {}
  int y, xl, xr;
};
struct Node2 {
  Node2() {}
  Node2(int x, int y, int tag) : x(x), y(y), tag(tag) {}
  int x, y, tag;
};
int n;
vector<Node1> hor;
vector<Node2> vec;
int bit[MAXN], vis[MAXN];
void update(int p, int v) {
  for (int i = p; i <= 10001; i += (i & -i)) {
    bit[i] += v;
  }
}
int get(int p) {
  int ret = 0;
  for (int i = p; i > 0; i -= (i & -i)) {
    ret += bit[i];
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  int len = 0;
  for (int i = 1; i <= n; i++) {
    int sx, sy, ex, ey;
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    if (sx > ex) swap(sx, ex);
    if (sy > ey) swap(sy, ey);
    sx += 5001;
    sy += 5001;
    ex += 5001;
    ey += 5001;
    if (sx == ex) {
      vec.push_back(Node2(sx, sy, len));
      vec.push_back(Node2(sx, ey, len + 1));
      len += 2;
    } else {
      hor.push_back(Node1(sy, sx, ex));
    }
  }
  sort(hor.begin(), hor.end(), [](Node1 n1, Node1 n2) { return n1.y < n2.y; });
  sort(vec.begin(), vec.end(), [](Node2 n1, Node2 n2) { return n1.y < n2.y; });
  long long ans = 0;
  for (int i = 0; i < hor.size(); i++) {
    memset(bit, 0, sizeof(bit));
    memset(vis, 0, sizeof(vis));
    int p = 0;
    for (; p < vec.size() && vec[p].y <= hor[i].y; p++) {
      if (vec[p].tag % 2 == 0) {
        vis[vec[p].tag / 2] = 1;
        update(vec[p].x, 1);
      } else {
        vis[vec[p].tag / 2] = 0;
        update(vec[p].x, -1);
      }
    }
    for (int j = i + 1; j < hor.size(); j++) {
      for (; p < vec.size() && vec[p].y < hor[j].y; p++) {
        if (vec[p].tag % 2 == 1 && vis[vec[p].tag / 2] == 1) {
          vis[vec[p].tag / 2] = 0;
          update(vec[p].x, -1);
        }
      }
      int liml = max(hor[i].xl, hor[j].xl);
      int limr = min(hor[i].xr, hor[j].xr);
      if (liml > limr) continue;
      long long cnt = get(limr) - get(liml - 1);
      ans += cnt * (cnt - 1) / 2;
    }
  }
  printf("%lld\n", ans);
}

```