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<algorithm>
#include<cstdio>
#include<vector>

using namespace std;

typedef pair<int, int> i_i;

#define rep(i, n) for(i = 0;i < n;++i)
#define int(x) int x; scanf("%d",&x)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define pb push_back
#define all(x) (x).begin(), (x).end()

struct rsqsegtree{
  vector<int> t;
  int re;
  int n;
  void use(int N){
    re = 0; n = N;
    int i, j;
    for(i = 0;;++i)if((1 << i) >= n)break;
    ++i; t.resize(1 << i); t[0] = 1 << i;
    for(i = 1;i < t[0];++i)t[i] = re;
    t[0] >>= 1;
    return;
  }
  void update(int at, int data){
    t[t[0] + at] += data;
    int tmp;
    for(int x = t[0] + at;x >= 2;x >>= 1)
    t[x >> 1] = (t[(x >> 1) << 1] + t[((x >> 1) << 1) + 1]);
    return;
  }
  int query(int l, int r, int k, int kl, int kr){
    if(k >= t.size())return re;
    if(kl >= r || kr <= l)return re;
    if(l <= kl && kr <= r)return t[k];
    return query(l, r, k * 2, kl, (kl + kr) >> 1) + query(l, r, k * 2 + 1, (kl + kr) >> 1, kr);
  }
  int getsum(int l, int r){ return query(l, r, 1, 0, t[0]); }
  void deb(void){
    int x = 1;
    t[0] *= 2;
    printf("t[0] : %d\n", t[0]);
    for(int i = 1;i < t[0];++i){
      printf("%11d", t[i]);
      if(i == (1 << x) - 1){ puts(""); ++x; }
    }
    t[0] /= 2;
    return;
  }
};

struct query{
  int q, y, l, r;
};
bool ysort(query qwe, query rty){
  if(qwe.y != rty.y)return qwe.y < rty.y;
  return qwe.q > rty.q;
}

rsqsegtree ST;
query Q[300000];
vector<int> x;
int qh = 0;

int inv(int d){
  int l = 0, r = x.size(), m;
  for(;l + 1 < r;){
    m = l + (r - l) / 2;
    if(d == x[m])return m;
    if(d > x[m])l = m;
    else r = m;
  }
  return l;
}

signed main(void){
  int i, j;
  int(n);
  rep(i, n){
    int4(x1, y1, x2, y2);
    if(x1 == x2){
      Q[qh++] = (query){1, min(y1, y2), x1, 0};
      Q[qh++] = (query){-1, max(y1, y2), x1, 0};
      x.pb(x1);
    }else{
      Q[qh++] = (query){0, y1, min(x1, x2), max(x1, x2)};
      x.pb(x1);
      x.pb(x2);
    }
  }
  sort(Q, Q + qh, ysort);
  sort(all(x));
  x.erase(unique(all(x)), x.end());

  ST.use(x.size());
  int res = 0;
  rep(i, qh){
    if(Q[i].q == 0)res += ST.getsum(inv(Q[i].l), inv(Q[i].r) + 1);
    else ST.update(inv(Q[i].l), Q[i].q);
  }
  printf("%d\n", res);

  return 0;
}