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 <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs(a - b) < EPS)

class Point{
public:
  double x, y;

  Point(double x = 0, double y = 0) : x(x), y(y) {}

  Point operator + (Point p){return Point(x + p.x, y + p.y);}
  Point operator - (Point p){return Point(x - p.x, y - p.y);}
  Point operator * (double a){return Point(x * a, y * a);}
  Point operator / (double a){return Point(x / a, y / a);}

  double abs(){return sqrt(norm());}
  double norm(){return x * x + y * y;}

  bool operator < (const Point &p) const{
    return x != p.x ? x < p.x : y < p.y;
  }
  bool operator == (const Point &p) const{
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }

};

typedef Point Vector;

class Segment{
public:
  Point p1, p2;
  Segment(){}
  Segment(Point p1, Point p2): p1(p1), p2(p2){}
};

typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0): c(c), r(r){}
};

typedef vector<Point> Polygon;

double dot(Vector a, Vector b){
  return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b){
  return a.x * b.y - a.y * b.x;
}

Point reflect(Point p0, Point p1, Point p2){
  Vector v01 = Vector(p0.x - p1.x, p0.y - p1.y);
  Vector v21 = Vector(p2.x - p1.x, p2.y - p1.y);
  double t = -1 * ((p2.x - p1.x) * (p1.x - p0.x) + (p2.y - p1.y) * (p1.y - p0.y)) / (pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2));
  return (v21 * t - v01) * 2 + p0;
}

Point project(Point p0, Point p1, Point p2){
  Vector v01 = Vector(p0.x - p1.x, p0.y - p1.y);
  Vector v21 = Vector(p2.x - p1.x, p2.y - p1.y);
  double t = -1 * ((p2.x - p1.x) * (p1.x - p0.x) + (p2.y - p1.y) * (p1.y - p0.y)) / (pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2));
  return v21 * t + p1;
}

double dis(Point p1, Point p2){
  return (p1 - p2).abs();
}

double getdis(Segment s, Point p){
  if(dot(s.p2 - s.p1, p - s.p1) < 0) return dis(s.p1, p);
  if(dot(s.p1 - s.p2, p - s.p2) < 0) return dis(s.p2, p);
  return dis(project(p, s.p1, s.p2), p);
}

string ccw(Point p0, Point p1, Point p2){
  Vector v01 = Vector(p1.x - p0.x, p1.y - p0.y);
  Vector v02 = Vector(p2.x - p0.x, p2.y - p0.y);
  if(equals(cross(v01, v02), 0)){
    if(dot(v01, v02) < 0) return "ONLINE_BACK";
    else if(equals(v01.abs(), v02.abs()) == true || v01.abs() > v02.abs()) return "ON_SEGMENT";
    else return "ONLINE_FRONT";
  }
  else if(cross(v01, v02) > 0) return "COUNTER_CLOCKWISE";
  else return "CLOCKWISE";
}

bool intersect(Segment s1, Segment s2){
  if(ccw(s1.p1, s1.p2, s2.p2) == "ON_SEGMENT" || ccw(s1.p1, s1.p2, s2.p1) == "ON_SEGMENT") return true;
  if(ccw(s2.p1, s2.p2, s1.p2) == "ON_SEGMENT" || ccw(s2.p1, s2.p2, s1.p1) == "ON_SEGMENT") return true;
  if(ccw(s1.p1, s1.p2, s2.p1) != ccw(s1.p1, s1.p2, s2.p2)){
    if(ccw(s1.p1, s2.p1, s2.p2) != ccw(s1.p2, s2.p1, s2.p2)) return true;
  }
  return false;
}

Point getcrosspoint(Segment s1, Segment s2){
  Vector base = s2.p2 - s2.p1;
  Vector hypo1 = s1.p1 - s2.p1;
  Vector hypo2 = s1.p2 - s2.p2;
  double d1, d2;
  d1 = abs(cross(base, hypo1)) / base.abs();
  d2 = abs(cross(base, hypo2)) / base.abs();
  return s1.p1 + (s1.p2 - s1.p1) * (d1 / (d1 + d2));
}

pair<Point, Point> getcrosspointcl(Circle c, Line l){
  Point p = project(c.c, l.p1, l.p2), s;
  if(p == l.p1) s = l.p2;
  else s = l.p1;
  Vector v1 = Vector(p - s);
  Vector v2 = Vector(c.c - p);
  double k1, k2, a, b, d;
  a = v1.abs() * v1.abs();
  b = -2 * pow(v1.abs(), 2) -2 * dot(v1, v2);
  d = pow(v1.abs(), 2) + 2 * dot(v1, v2) + pow(v2.abs(), 2) - pow(c.r, 2);
  k1 = (-1 * b + pow(b * b - 4 * a * d, 0.5)) / (2 * a);
  k2 = (-1 * b - pow(b * b - 4 * a * d, 0.5)) / (2 * a);
  return make_pair(s + v1 * k1, s + v1 * k2);
}

double arg(Vector p){
  return atan2(p.y, p.x);
}
Vector polar(double a, double r){
  return Point(cos(r) * a, sin(r) * a);
}

pair<Point, Point> getcrosspointcc(Circle c1, Circle c2){
  Vector cc = Vector(c1.c - c2.c);
  double a = acos((c1.r * c1.r + cc.abs() * cc.abs() - c2.r * c2.r) / (2 * c1.r * cc.abs()));
  double t = arg(c2.c - c1.c);
  return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}

void printans(double a, double b, double c, double d){
  cout << fixed << setprecision(10) << a << " " << b << " " << c << " " << d << endl;
}

int contains(Polygon g, Point p){
  int n = g.size();
  bool x = false;
  for(int i = 0; i < n; i++){
    Point a = g[i] - p, b = g[(i + 1) % n] - p;
    if(abs(cross(a, b)) < EPS && dot(a, b) < EPS) return 1;
    if(a.y > b.y) swap(a, b);
    if(a.y < EPS && EPS < b.y && cross(a, b) > EPS) x = !x;
  }
  return (x ? 2 : 0);
}

void scan(Polygon p){
  int n = p.size();
  sort(p.begin(), p.end());
  stack<Point> s, s2;
  s.push(p[0]);
  s.push(p[1]);
  for(int i = 2; i < n; i++){
    Point p1 = p[i];
    Point p0 = s.top(); s.pop();
    Point p2 = s.top();
    while(ccw(p0, p1, p2) == "COUNTER_CLOCKWISE"){
      p0 = p2;
      s.pop();
      if(s.size() == 0) break;
      p2 = s.top();
    }
    s.push(p0);
    s.push(p1);
  }
  s2.push(p[n - 1]);
  s2.push(p[n - 2]);
  for(int i = n - 3; i >= 0; i--){
    Point p1 = p[i];
    Point p0 = s2.top(); s2.pop();
    Point p2 = s2.top();
    while(ccw(p0, p1, p2) == "COUNTER_CLOCKWISE"){
      p0 = p2;
      s2.pop();
      if(s2.size() == 0) break;
      p2 = s2.top();
    }
    s2.push(p0);
    s2.push(p1);
  }
  vector<Point> ans;
  while(s2.size() > 0){
    ans.push_back(s2.top());
    //cout << s2.top().x << " " << s2.top().y << endl;
    s2.pop();
  }
  s.pop();
  while(s.size() > 1){
    ans.push_back(s.top());
    //cout << s.top().x << " " << s.top().y << endl;
    s.pop();
  }
  int m = ans.size();
  int mini = 0;
  for(int i = 1; i < m; i++){
    if(ans[i].y < ans[mini].y){
      mini = i;
    }
  }
  cout << m << endl;
  for(int i = 0; i < m; i++){
    Point p = ans[(i + mini) % m];
    cout << p.x << " " << p.y << endl;
  }
}

bool compy(const Segment& s1, const Segment& s2){
  if(s1.p1.y == s2.p1.y) return s1.p2.y > s2.p2.y;
  return s1.p1.y < s2.p1.y;
}

int sgimg(vector<Segment>& s){
  int n = s.size();
  sort(s.begin(), s.end(), compy);
  /*for(int i = 0; i < n; i++){
    cout << s[i].p1.x << " " << s[i].p1.y << " " << s[i].p2.x << " " << s[i].p2.y << endl;
  }*/
  vector<Segment> st;
  int cnt = 0;
  //cout << endl << endl;
  for(int i = 0; i < n; i++){
    //cout << s[i].p1.x << " " << s[i].p1.y << " " << s[i].p2.x << " " << s[i].p2.y << " : ";
    //cout << st.size() << " : ";
    if(s[i].p1.x == s[i].p2.x) st.push_back(s[i]);
    if(s[i].p1.y == s[i].p2.y){
      int y = s[i].p1.y;
      int a = s[i].p1.x, b = s[i].p2.x;
      if(a > b){
        int t = a;
        a = b;
        b = t;
      }

      for(auto it = st.begin(); it != st.end();){
        if(it->p2.y < y) st.erase(it);
        else it++;
      }
      /*for(auto it = st.begin(); it != st.end();it++){
        cout << it->p1.x << " " << it->p1.y << " " << it->p2.x << " " << it->p2.y << "->";
      }
      cout << "a : " << a << "b : " << b << " ";*/
      for(auto it = st.begin(); it != st.end(); it++){
        if(a <= it->p1.x && it->p1.x <= b) cnt++;
      }
    }
    //cout << cnt << endl;
  }
  return cnt;
}

void solve(){
  int n; cin >> n;
  vector<Segment> s(n);
  for(int i = 0; i < n; i++){
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    Point p1 = Point(x1, y1);
    Point p2 = Point(x2, y2);
    if(p1.y <= p2.y) s[i] = Segment(Point(x1, y1), Point(x2, y2));
    else s[i] = Segment(Point(x2, y2), Point(x1, y1));
  }
  cout << sgimg(s) << endl;
  return;
}

int main(){
  solve();
  return 0;
}

