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;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

struct M {
  using T = int;
  static T op(const T& a, const T& b) { return a + b; }
  static constexpr T e() { return 0; }
};

template<class M> struct ST {
  using T = typename M::T;
  int n;
  V<T> t;

  ST(int n) : n(n) {
    t.assign(2 * n, M::e());
  }

  void build() {
    for (int i = n - 1; i; i--) t[i] = M::op(t[2 * i], t[2 * i + 1]);
  }

  T get(int l, int r) {
    T resl = M::e(), resr = M::e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) { 
      if (l & 1) resl = M::op(resl, t[l++]); 
      if (r & 1) resr = M::op(t[--r], resr);
    }
    return M::op(resl, resr);
  }

  void set(int i, const T& a) {
    for (t[i += n] = a; i >>= 1;) t[i] = M::op(t[2 * i], t[2 * i + 1]);
  }
};

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  struct seg { int id, x1, y1, x2, y2; };
  V<seg> a(n);
  V<> x, y;
  for (int i = 0; i < n; i++) {
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    x.push_back(x1), y.push_back(y1);
    x.push_back(x2), y.push_back(y2);
    a[i] = seg{i, x1, y1, x2, y2};
  }
  sort(x.begin(), x.end()), sort(y.begin(), y.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  y.erase(unique(y.begin(), y.end()), y.end());
  for (int i = 0; i < n; i++) {
    a[i].x1 = lower_bound(x.begin(), x.end(), a[i].x1) - x.begin();
    a[i].y1 = lower_bound(y.begin(), y.end(), a[i].y1) - y.begin();
    a[i].x2 = lower_bound(x.begin(), x.end(), a[i].x2) - x.begin();
    a[i].y2 = lower_bound(y.begin(), y.end(), a[i].y2) - y.begin();
  }

  struct event { int type, x1, x2; };
  VV<event> y2e(y.size());
  for (int i = 0; i < n; i++) {
    if (a[i].x1 == a[i].x2) {
      y2e[min(a[i].y1, a[i].y2)].push_back(event{0, a[i].x1, -1});
      y2e[max(a[i].y1, a[i].y2)].push_back(event{2, a[i].x1, -1});
    } else {
      y2e[a[i].y1].push_back(event{1, min(a[i].x1, a[i].x2), max(a[i].x1, a[i].x2)});
    }
  }
  auto comp = [](const event& a, const event& b) { return a.type < b.type; };
  for (auto&& v : y2e) sort(v.begin(), v.end(), comp);
  ST<M> st(x.size());
  int res = 0;
  for (int j = 0; j < y.size(); j++) {
    for (auto&& e : y2e[j]) {
      if (e.type == 0) st.set(e.x1, st.t[e.x1 + x.size()] + 1);
      else if (e.type == 1) res += st.get(e.x1, e.x2 + 1);
      else st.set(e.x1, st.t[e.x1 + x.size()] - 1);
    }
  }
  cout << res << '\n';
}
