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 <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using P = pair<int,int>;
const int flag = 1e9;

template <typename T, typename F>
class SegTree{
  int n; T uni; F f;
  vector<T> dat;
public:
  SegTree(int _n, F f, T uni) : f(f), uni(uni) {
    n = 1;
    while(n < _n) n *= 2;
    dat = vector<T>(2*n,uni);
  }
  void set(int k, const T x) {
    dat[k+n] = x;
  }
  void build() {
    for(int i = n-1; i >= 0; i--) {
      dat[i] = f(dat[2*i],dat[2*i+1]);
    }
  }
  void update(int k, T x) {
    k += n;
    dat[k] += x;
    while(k >>= 1){
      dat[k] = f(dat[2*k],dat[2*k+1]);
    }
  }
  T query(int a, int b) {
    T l = uni, r = uni;
    for(a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if(a & 1) l = f(l,dat[a++]);
      if(b & 1) r = f(dat[--b],r);
    }
    return f(l,r);
  }
};

int main(){
  int n;
  cin >> n;
  auto f = [](int a, int b){return a + b;};
  SegTree<int,decltype(f)> st(2*n,f,0);
  vector<int> px;
  vector<P> qx;
  vector<int> qy;
  vector<P> event;
  int k = 0, l = 0;
  rep(i,n) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    px.push_back(x1); px.push_back(x2);
    if(y1 == y2) {
      event.push_back(P(y1,k++));
      if(x1 > x2) swap(x1,x2);
      qx.push_back(P(x1,x2));
    } else {
      if(y1 > y2) swap(y1,y2);
      event.push_back(P(y1,-flag-l));
      qy.push_back(x1);
      l++;
      event.push_back(P(y2,flag+l));
      qy.push_back(x1);
      l++;
    }
  }
  sort(px.begin(),px.end());
  map<int,int> m;
  rep(i,2*n) m[px[i]] = i;
  sort(event.begin(),event.end());
  int ans = 0;
  for(auto e : event) {
    if(e.second >= flag) {
      int a = e.second - flag;
      st.update(m[qy[a]],-1);
    } else if(e.second <= -flag) {
      int a = -e.second - flag;
      st.update(m[qy[a]],1);
    } else {
      int a = e.second;
      ans += st.query(m[qx[a].first],m[qx[a].second]+1);
    }
  }
  cout << ans << endl;
}
