//#define NDEBUG
#include "bits/stdc++.h"
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <random>
#ifdef _MSC_VER
#include <ppl.h>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/rational.hpp>
//#include <opencv2/core.hpp>
//#include <opencv2/imgproc.hpp>
//#include <opencv2/highgui.hpp>
//#else
//#include <omp.h>
#endif


using namespace std;

#define DUMPOUT cerr
#define dump(...) DUMPOUT<<"  ";DUMPOUT<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;DUMPOUT<<"    ";dump_func(__VA_ARGS__)

using uint = unsigned; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using pss = pair<string, string>;
template <typename _KTy, typename _Ty> ostream& operator << (ostream& o, const pair<_KTy, _Ty>& m) { o << "{" << m.first << ", " << m.second << "}"; return o; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& o, const map<_KTy, _Ty>& m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& o, const unordered_map<_KTy, _Ty>& m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; }
template <typename _Ty> ostream& operator << (ostream& o, const vector<_Ty>& v) { if (v.empty()) { o << "{ }"; return o; } o << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { o << ", " << *itr; } o << "}"; return o; }
template <typename _Ty> ostream& operator << (ostream& o, const deque<_Ty>& v) { if (v.empty()) { o << "{ }"; return o; } o << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { o << ", " << *itr; } o << "}"; return o; }
template <typename _Ty> ostream& operator << (ostream& o, const set<_Ty>& s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; } o << "}"; return o; }
template <typename _Ty> ostream& operator << (ostream& o, const unordered_set<_Ty>& s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; }	o << "}"; return o; }
template <typename _Ty> ostream& operator << (ostream& o, const stack<_Ty>& s) { if (s.empty()) { o << "{ }"; return o; } stack<_Ty> t(s); o << "{" << t.top(); t.pop(); while (!t.empty()) { o << ", " << t.top(); t.pop(); } o << "}";	return o; }
template <typename _Ty> ostream& operator << (ostream& o, const list<_Ty>& l) { if (l.empty()) { o << "{ }"; return o; } o << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { o << ", " << *itr; } o << "}"; return o; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& is, pair<_KTy, _Ty>& m) { is >> m.first >> m.second; return is; }
template <typename _Ty> istream& operator >> (istream& is, vector<_Ty>& v) { for (size_t t = 0; t < v.size(); t++) is >> v[t]; return is; }
template <typename _Ty> istream& operator >> (istream& is, deque<_Ty>& v) { for (size_t t = 0; t < v.size(); t++) is >> v[t]; return is; }
namespace aux { // print tuple
  template<typename Ty, unsigned N, unsigned L> struct tp { static void print(ostream& os, const Ty& v) { os << get<N>(v) << ", "; tp<Ty, N + 1, L>::print(os, v); } };
  template<typename Ty, unsigned N> struct tp<Ty, N, N> { static void print(ostream& os, const Ty& v) { os << get<N>(v); } };
}

template<typename... Tys> ostream& operator<<(ostream& os, const tuple<Tys...>& t) { os << "{"; aux::tp<tuple<Tys...>, 0, sizeof...(Tys) - 1>::print(os, t); os << "}"; return os; }

template<typename A, size_t N, typename T> inline void Fill(A(&array)[N], const T& val) { fill((T*)array, (T*)(array + N), val); }

template <typename ... Args>
std::string format(const std::string& fmt, Args ... args) {
  size_t len = std::snprintf(nullptr, 0, fmt.c_str(), args ...);
  std::vector<char> buf(len + 1);
  std::snprintf(&buf[0], len + 1, fmt.c_str(), args ...);
  return std::string(&buf[0], &buf[0] + len);
}

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(move(tail)...); }

#define PI 3.14159265358979323846
#define EPS 1e-8
#define rep(t,n) for(int t=0;t<(n);++t)
#define ALL(j) (j).begin(), (j).end()
#define SZ(j) ((int)(j).size())
#define fake false

class Timer {
public:
  double t = 0;
  Timer() {}
  static double time() {
#ifdef _MSC_VER
    return __rdtsc() / 2.8e9;
#else
    unsigned long long a, d;
    __asm__ volatile("rdtsc"
      : "=a"(a), "=d"(d));
    return (d << 32 | a) / 2.8e9;
#endif
  }
  void measure() { t = time() - t; }
  double elapsedMs() { return (time() - t) * 1000.0; }
} timer;

struct Xorshift {
  uint64_t x = 88172645463325252LL;
  unsigned next_int() {
    x = x ^ (x << 7);
    return x = x ^ (x >> 9);
  }
  unsigned next_int(unsigned mod) {
    x = x ^ (x << 7);
    x = x ^ (x >> 9);
    return x % mod;
  }
  unsigned next_int(unsigned l, unsigned r) {
    x = x ^ (x << 7);
    x = x ^ (x >> 9);
    return x % (r - l + 1) + l;
  }
  double next_double() {
    return double(next_int()) / UINT_MAX;
  }
} rnd;

template<typename T>
void shuffle_vector(vector<T>& v, Xorshift& rnd) {
  int n = v.size();
  for (int i = n - 1; i >= 1; i--) {
    int r = rnd.next_int(i);
    swap(v[i], v[r]);
  }
}



namespace geom {
  constexpr double eps = 1e-8;

  /* point */
  struct Point {
    double x, y;
    Point() : x(0.0), y(0.0) {}
    Point(double x, double y) : x(x), y(y) {}
    Point operator+(const Point& p) const { return Point(this->x + p.x, this->y + p.y); }
    Point operator-(const Point& p) const { return Point(this->x - p.x, this->y - p.y); }
    Point operator-() const { return Point(-this->x, -this->y); }
    Point& operator+=(const Point& p) { return *this = *this + p; }
    Point& operator-=(const Point& p) { return *this = *this - p; }
    bool operator==(const Point& p) const { return x == p.x && y == p.y; }
    bool operator!=(const Point& p) const { return !(*this == p); }
    bool operator<(const Point& p) const { return x == p.x ? y < p.y : x < p.x; }
    bool operator<=(const Point& p) const { return *this == p || *this < p; }
    bool operator>(const Point& p) const { return !(*this <= p); }
    bool operator>=(const Point& p) const { return !(*this < p); }
    double length() const { return std::sqrt(x * x + y * y); }
    double length2() const { return x * x + y * y; }
    double distance(const Point& p) const { return sqrt(pow(x - p.x, 2.0) + pow(y - p.y, 2.0)); }
    friend std::ostream& operator<<(std::ostream& o, const Point& p) {
      o << '(' << p.x << ',' << p.y << ')';
      return o;
    }
    friend std::istream& operator>>(std::istream& i, Point& p) {
      i >> p.x >> p.y;
      return i;
    }
  };
  
  /* vector */
  using Vector = Point;
  double cross_product(const Vector& v1, const Vector& v2) {
    return v1.x * v2.y - v2.x * v1.y;
  }
  double inner_product(const Vector& v1, const Vector& v2) {
    return v1.x * v2.x + v1.y * v2.y;
  }
  enum struct ccw_t {
    COUNTER_CLOCKWISE,
    CLOCKWISE,
    ONLINE_BACK,
    ONLINE_FRONT,
    ON_SEGMENT
  };
  ccw_t ccw(const Point& p0, const Point& p1, const Point& p2) {
    Vector v1 = p1 - p0, v2 = p2 - p0;
    if (cross_product(v1, v2) > eps) return ccw_t::COUNTER_CLOCKWISE;
    if (cross_product(v1, v2) < -eps) return ccw_t::CLOCKWISE;
    if (inner_product(v1, v2) < -eps) return ccw_t::ONLINE_BACK;
    if (v1.length2() < v2.length2()) return ccw_t::ONLINE_FRONT;
    return ccw_t::ON_SEGMENT;
  }

  /* line */
  struct Line {
    Point p1, p2;
    Line() {}
    Line(const Point& p1, const Point& p2) : p1(p1), p2(p2) {}
    Line(double x1, double y1, double x2, double y2) : p1(Point(x1, y1)), p2(Point(x2, y2)) {}
    Vector to_vector() const { return p2 - p1; }
    Point projection(const Point& p) const {
      Vector v12(p2 - p1);
      double det = v12.length2();
      double a = v12.y * p1.x - v12.x * p1.y, b = v12.y * p.y + v12.x * p.x;
      double x = v12.y * a + v12.x * b, y = v12.y * b - v12.x * a;
      return Point(x / det, y / det);
    }
    Point reflection(const Point& p) const {
      Point proj = projection(p);
      return proj + proj - p;
    }
    double distance(const Point& p) const {
      return projection(p).distance(p);
    }
    bool is_parallel(const Line& l) const {
      return abs(cross_product(this->to_vector(), l.to_vector())) < eps;
    }
    bool is_orthogonal(const Line& l) const {
      return abs(inner_product(this->to_vector(), l.to_vector())) < eps;
    }
    Point intersection(const Line& l) const {
      Point p0(this->p1), p1(this->p2), p2(l.p1), p3(l.p2);
      Vector v01(p1 - p0), v23(p3 - p2);
      double det = cross_product(v01, v23);
      double a = v01.y * p0.x - v01.x * p0.y, b = v23.y * p2.x - v23.x * p2.y;
      double x = v01.x * b - v23.x * a;
      double y = v01.y * b - v23.y * a;
      return Point(x / det, y / det);
    }
    friend std::ostream& operator<<(std::ostream& o, const Line& l) {
      o << '(' << l.p1 << ',' << l.p2 << ')';
      return o;
    }
    friend std::istream& operator>>(std::istream& i, Line& l) {
      i >> l.p1 >> l.p2;
      return i;
    }
  };

  /* segment */
  using Segment = Line;
  bool is_intersect_segments(const Segment& s1, const Segment& s2) {
    Vector v2 = s2.to_vector(), p1(s1.p1 - s2.p1), p2(s1.p2 - s2.p1);
    if (cross_product(v2, p1) * cross_product(v2, p2) > eps) return false;
    Vector v1 = s1.to_vector(), p3(s2.p1 - s1.p1), p4(s2.p2 - s1.p1);
    if (cross_product(v1, p3) * cross_product(v1, p4) > eps) return false;
    if (inner_product(s2.p1 - s1.p1, s2.p2 - s1.p1) < eps) return true;
    if (inner_product(s2.p1 - s1.p2, s2.p2 - s1.p2) < eps) return true;
    if (inner_product(s1.p1 - s2.p1, s1.p2 - s2.p1) < eps) return true;
    if (inner_product(s1.p1 - s2.p2, s1.p2 - s2.p2) < eps) return true;
    return false;
  }
  bool is_intersect_segment_line(const Segment s, const Line& l) {
    if (l.is_parallel(s)) return false;
    Vector vst = l.to_vector();
    Point ps = l.p1;
    return cross_product(vst, s.p1 - ps) * cross_product(vst, s.p2 - ps) < eps;
  }
  double segment_distance(const Segment& s, const Point& p) {
    Point proj = s.projection(p);
    if (ccw(s.p1, proj, s.p2) == ccw_t::ONLINE_FRONT) return p.distance(proj);
    return min(p.distance(s.p1), p.distance(s.p2));
  }
  double segment_distance(const Segment& s1, const Segment& s2) {
    if (is_intersect_segments(s1, s2)) return 0.0;
    return min({
      segment_distance(s1, s2.p1), segment_distance(s1, s2.p2),
      segment_distance(s2, s1.p1), segment_distance(s2, s1.p2)
      });
  }

  /* polygon */
  using Polygon = std::vector<Point>;
  double area(const Polygon& poly) {
    if (poly.size() <= 2) return 0;
    Point b(DBL_MAX, DBL_MAX);
    for (const Point& p : poly) {
      b.x = min(b.x, p.x); b.y = min(b.y, p.y);
    }
    b.x -= 1.0; b.y -= 1.0;
    int n = (int)poly.size();
    double area = 0.0;
    for (int i = 0; i < n; i++) {
      area += cross_product(poly[i] - b, poly[(i + 1) % n] - b) * 0.5;
    }
    return area;
  }
  bool is_convex(const Polygon& poly) {
    if (poly.size() <= 2) return false;
    int n = (int)poly.size();
    for (int i = 0; i < n; i++) {
      if (ccw(poly[i], poly[(i + 1) % n], poly[(i + 2) % n]) == ccw_t::CLOCKWISE) {
        return false;
      }
    }
    return true;
  }
  enum struct poly_t {
    EXTERNAL = 0,
    ON_SEGMENT = 1,
    INTERNAL = 2
  };
  poly_t is_inside(const Point& p, const Polygon& poly) {
    int n = (int)poly.size();
    double rad = 0.0;
    for (int i = 0; i < n; i++) {
      const Point& p1 = poly[i];
      const Point& p2 = poly[(i + 1) % n];
      double d1 = p.distance(p1), d2 = p.distance(p2);
      if (segment_distance(Segment(p1, p2), p) < eps) return poly_t::ON_SEGMENT;
      Vector v1(p1 - p), v2(p2 - p);
      double r = atan2(cross_product(v1, v2), inner_product(v1, v2));
      rad += r;
    }
    return rad < eps ? poly_t::EXTERNAL : poly_t::INTERNAL;
  }

  /* convex hull */
  using Hull = Polygon;
  Hull convex_hull(std::vector<Point> points, bool strict = true) {
    double e = strict ? eps : -eps;
    std::sort(points.begin(), points.end());
    int n = (int)points.size(), k = 0;
    Hull hull(2 * n);
    for (int i = 0; i < n; i++) {
      while (k > 1 && cross_product(hull[k - 1] - hull[k - 2], points[i] - hull[k - 1]) < e) k--;
      hull[k++] = points[i];
    }
    for (int i = n - 2, t = k; i >= 0; i--) {
      while (k > t && cross_product(hull[k - 1] - hull[k - 2], points[i] - hull[k - 1]) < e) k--;
      hull[k++] = points[i];
    }
    hull.resize(k - 1);
    return hull;
  }
  double convex_diameter(const Hull& hull) {
    int n = (int)hull.size();
    if (n == 2) return hull.front().distance(hull.back());
    int i = 0, j = 0;
    for (int k = 0; k < n; k++) {
      if (hull[k] < hull[i]) i = k;
      if (hull[j] < hull[k]) j = k;
    }
    double d = 0.0;
    int si = i, sj = j;
    while (i != sj || j != si) {
      d = max(d, hull[i].distance(hull[j]));
      if (cross_product(hull[(i + 1) % n] - hull[i], hull[(j + 1) % n] - hull[j]) < 0.0) {
        i = (i + 1) % n;
      }
      else {
        j = (j + 1) % n;
      }
    }
    return d;
  }
  std::pair<Hull, Hull> convex_cut(const Hull& hull, const Line& l) {
    int n = (int)hull.size(), i = -1, j = -1;
    Point pi, pj;
    for (int k = 0; k < n; k++) {
      Segment s(hull[k], hull[(k + 1) % n]);
      if (is_intersect_segment_line(s, l)) {
        if (cross_product(l.to_vector(), s.to_vector()) < 0) {
          i = k;
          pi = l.intersection(s);
        }
        else {
          j = k;
          pj = l.intersection(s);
        }
      }
    }
    if (i < 0) {
      // no cut: 左か右か判定
      if (cross_product(l.to_vector(), hull.front() - l.p1) > 0) {
        // left
        return std::make_pair(hull, Hull());
      }
      else {
        return std::make_pair(Hull(), hull);
      }
    }
    Hull left({ pi, pj }), right({ pj, pi });
    for (int k = (j + 1) % n, e = (i + 1) % n; k != e; k = (k + 1) % n) {
      if(left.back().distance(hull[k]) > eps) left.push_back(hull[k]);
    }
    for (int k = (i + 1) % n, e = (j + 1) % n; k != e; k = (k + 1) % n) {
      if(right.back().distance(hull[k]) > eps) right.push_back(hull[k]);
    }
    if (left.front().distance(left.back()) < eps) left.pop_back();
    if (right.front().distance(right.back()) < eps) right.pop_back();
    return std::make_pair(left, right);
  }

  /* closest pair : 逐次構成法 */
  double closest_pair_incremental(std::vector<Point> ps) {
    using ll = long long;
    using Grid = std::unordered_map<ll, std::vector<Point>>;
    // for random
    uint64_t x = 88172645463325252LL;
    auto rnd = [&x](int mod) { x = x ^ (x << 7); x = x ^ (x >> 9); return unsigned(x % mod); };
    // shuffle
    int n = (int)ps.size();
    for (int i = n - 1; i >= 1; i--) {
      int j = (int)rnd(i);
      std::swap(ps[i], ps[j]);
    }
    // set bounding box
    double x_min = DBL_MAX, x_max = DBL_MIN;
    double y_min = DBL_MAX, y_max = DBL_MIN;
    for (const Point& p : ps) {
      x_min = min(x_min, p.x); x_max = max(x_max, p.x);
      y_min = min(y_min, p.y); y_max = max(y_max, p.y);
    }
    x_min -= eps; x_max += eps; y_min -= eps; y_max += eps;
    // grid generator
    double delta = ps[0].distance(ps[1]);
    auto generate_grid = [&](int sz, double delta) {
      ll h = (int)ceil((y_max - y_min) / delta);
      ll w = (int)ceil((x_max - x_min) / delta);
      Grid grid;
      for (int i = 0; i < sz; i++) {
        double x = ps[i].x, y = ps[i].y;
        ll ix = (ll)floor((x - x_min) / delta);
        ll iy = (ll)floor((y - y_min) / delta);
        grid[iy * w + ix].push_back(ps[i]);
      }
      return std::make_tuple(h, w, std::move(grid)); 
    };
    // 幅 delta のグリッド構築
    ll h, w;
    Grid grid;
    tie(h, w, grid) = generate_grid(2, delta);
    for (int k = 2; k < n; k++) {
      // d_i = d(p_i, S_i) を計算
      double x = ps[k].x, y = ps[k].y;
      ll ix = (ll)floor((x - x_min) / delta);
      ll iy = (ll)floor((y - y_min) / delta);
      // 近傍のみ調べればいい
      double ndelta = delta;
      for (ll i = max(iy - 1, 0LL); i <= min(iy + 1, h - 1); i++) {
        for (ll j = max(ix - 1, 0LL); j <= min(ix + 1, w - 1); j++) {
          if (!grid.count(i * w + j)) continue;
          for (const auto& p : grid[i * w + j]) {
            ndelta = std::min(ndelta, ps[k].distance(p));
          }
        }
      }
      if (ndelta < delta) {
        // update grid
        delta = ndelta;
        tie(h, w, grid) = generate_grid(k + 1, delta);
      }
      else {
        // insert point
        grid[iy * w + ix].push_back(ps[k]);
      }
    }
    return delta;
  }

  /* closest pair : 篩法 */
  double closest_pair_sieve(const std::vector<Point>& ps) {
    using ll = long long;
    using Grid = std::unordered_map<ll, std::vector<Point>>;
    // init grid
    Grid grid;
    for (const Point& p : ps) grid[0].push_back(p);
    // for random
    uint64_t x = 88172645463325252LL;
    auto rnd = [&x](int mod) { x = x ^ (x << 7); x = x ^ (x >> 9); return unsigned(x % mod); };
    // set bounding box
    double x_min = DBL_MAX, x_max = DBL_MIN;
    double y_min = DBL_MAX, y_max = DBL_MIN;
    for (const Point& p : ps) {
      x_min = min(x_min, p.x); x_max = max(x_max, p.x); 
      y_min = min(y_min, p.y); y_max = max(y_max, p.y);
    }
    x_min -= eps; x_max += eps; y_min -= eps; y_max += eps;
    // grid updator
    auto update_grid = [&](const Grid& grid, double delta, bool erase_mode = true) {
      int erased = 0;
      ll h = (ll)ceil((y_max - y_min) / delta);
      ll w = (ll)ceil((x_max - x_min) / delta);
      Grid ngrid;
      for (auto it = grid.begin(); it != grid.end(); ++it) {
        for (const Point& p : it->second) {
          ll ix = (ll)floor((p.x - x_min) / delta);
          ll iy = (ll)floor((p.y - y_min) / delta);
          ngrid[iy * w + ix].push_back(p);
        }
      }
      if (erase_mode) {
        // 孤立点の除去
        auto it = ngrid.begin();
        while (it != ngrid.end()) {
          if (it->second.size() >= 2) { ++it; continue; }
          ll pos = it->first, iy = pos / w, ix = pos % w;
          // 8 近傍に点がなければ、削除する
          bool found = [&]() {
            for (ll i = max(0LL, iy - 1); i <= min(h - 1, iy + 1); i++) {
              for (ll j = max(0LL, ix - 1); j <= min(w - 1, ix + 1); j++) {
                if (i == iy && j == ix) continue;
                if (ngrid.count(i * w + j)) {
                  return true;
                }
              }
            }
            return false;
          } ();
          if (!found) {
            it = ngrid.erase(ngrid.find(pos));
            erased++;
          }
          else ++it;
        }
      }
      return make_tuple(erased, h, w, std::move(ngrid));
    };
    // elimination phase
    int n = (int)ps.size(), erased;
    ll h = 1, w = 1;
    double delta = DBL_MAX;
    while (n) {
      // ランダムに点を選ぶ
      auto it = std::next(grid.begin(), rnd((int)grid.size()));
      ll pos = it->first;
      auto& cands = it->second;
      int i = rnd((int)cands.size());
      Point selected = cands[i];
      // 一旦消す
      cands.erase(cands.begin() + i);
      // pos 周辺を探索
      ll iy = pos / w, ix = pos % w;
      for (ll i = max(0LL, iy - 1); i <= min(h - 1, iy + 1); i++) {
        for (ll j = max(0LL, ix - 1); j <= min(w - 1, ix + 1); j++) {
          if (!grid.count(i * w + j)) continue;
          for (const auto& p : grid[i * w + j]) {
            delta = min(delta, selected.distance(p));
          }
        }
      }
      // 元に戻す
      cands.push_back(selected);
      // 幅 delta / 8 で grid を作成
      delta /= 8;
      tie(erased, h, w, grid) = update_grid(grid, delta);
      n -= erased;
    }
    delta *= 8;
    // 最終的な delta で最近点対探索
    // reset grid
    for (const Point& p : ps) grid[0].push_back(p);
    tie(erased, h, w, grid) = update_grid(grid, delta, false);
    // find closest points
    delta = DBL_MAX;
    for (auto it = grid.begin(); it != grid.end(); ++it) {
      ll pos = it->first;
      auto& cands = it->second;
      // 自身の近傍
      for (int i = 0; i < (int)cands.size() - 1; i++) {
        for (int j = i + 1; j < cands.size(); j++) {
          delta = min(delta, cands[i].distance(cands[j]));
        }
      }
      // 周辺を探索
      ll iy = pos / w, ix = pos % w;
      for (ll i = max(0LL, iy - 1); i <= min(h - 1, iy + 1); i++) {
        for (ll j = max(0LL, ix - 1); j <= min(w - 1, ix + 1); j++) {
          if (i == iy && j == ix) continue;
          if (!grid.count(i * w + j)) continue;
          for (const auto& p1 : cands) {
            for (const auto& p2 : grid[i * w + j]) {
              delta = min(delta, p1.distance(p2));
            }
          }
        }
      }
    }
    return delta;
  }

  /* closest pair: 分割統治法 */
  double closest_pair_impl(std::vector<Point>& ps, int l, int r) {
    static const auto cmp_y = [](const Point& a, const Point& b) { return a.y < b.y; };
    int n = r - l, m = (l + r) >> 1;
    if (n <= 1) return DBL_MAX;
    double x = ps[m].x;
    double d = min(closest_pair_impl(ps, l, m), closest_pair_impl(ps, m, r));
    std::inplace_merge(ps.begin() + l, ps.begin() + m, ps.begin() + r, cmp_y);
    std::vector<Point> b;
    for (int i = 0; i < n; i++) {
      if (abs(ps[i + l].x - x) >= d) continue;
      for (int j = (int)b.size() - 1; j >= 0; j--) {
        double dx = ps[i + l].x - b[j].x, dy = ps[i + l].y - b[j].y;
        if (dy >= d) break;
        d = min(d, sqrt(dx * dx + dy * dy));
      }
      b.push_back(ps[i + l]);
    }
    return d;
  }
  double closest_pair(std::vector<Point> ps) {
    std::sort(ps.begin(), ps.end());
    return closest_pair_impl(ps, 0, (int)ps.size());
  }
}

// T have +-*/ and 0
template<class T> class BIT {
public:
  vector<T> dat;
  int N;

  BIT() {}
  BIT(int N) : N(N) { dat.assign(N, 0); }
  // sum [0,c)
  T sum(int i) {
    T ret = 0;
    for (--i; i >= 0; i = (i & (i + 1)) - 1) ret += dat[i];
    return ret;
  }
  // sum [c,j1)
  T sum(int i1, int i2) { return sum(i2) - sum(i1); }
  T at(int i) { return sum(i, i + 1); }
  // add x to c
  void add(int i, T x) { for (; i < N; i |= i + 1) dat[i] += x; }
};

constexpr int RIGHT = 0;
constexpr int DOWN = 1;
constexpr int LEFT = 2;
struct L {
  int x, y, len, dir;
  L() {}
  L(int x, int y, int len, int dir) : x(x), y(y), len(len), dir(dir) {}
  bool operator<(const L& l) const {
    if (x == l.x) return dir < l.dir;
    return x < l.x;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  using namespace geom;

  int n;
  cin >> n;
  vector<int> x1(n), y1(n), x2(n), y2(n);
  for (int i = 0; i < n; i++) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    if (x1[i] > x2[i]) swap(x1[i], x2[i]);
    if (y1[i] > y2[i]) swap(y1[i], y2[i]);
  }

  map<int, int> cmp_x, cmp_y;
  for (int x : x1) cmp_x[x] = -1;
  for (int x : x2) cmp_x[x] = -1;
  for (int y : y1) cmp_y[y] = -1;
  for (int y : y2) cmp_y[y] = -1;
  int c = 0;
  for (auto& e : cmp_x) e.second = c++;
  c = 0;
  for (auto& e : cmp_y) e.second = c++;

  for (int i = 0; i < n; i++) {
    x1[i] = cmp_x[x1[i]];
    x2[i] = cmp_x[x2[i]];
    y1[i] = cmp_y[y1[i]];
    y2[i] = cmp_y[y2[i]];
  }

  vector<L> ls;
  for (int i = 0; i < n; i++) {
    if (x1[i] == x2[i]) {
      ls.emplace_back(x1[i], y1[i], y2[i] - y1[i], DOWN);
    }
    else {
      ls.emplace_back(x1[i], y1[i], x2[i] - x1[i], RIGHT);
      ls.emplace_back(x2[i], y2[i], x2[i] - x1[i], LEFT);
    }
  }

  sort(ls.begin(), ls.end());

  int ans = 0;
  BIT<int> bit(cmp_y.size() + 2);
  for (const L& l : ls) {
    switch (l.dir) {
    case RIGHT:
      bit.add(l.y, 1);
      break;
    case DOWN:
      ans += bit.sum(l.y, l.y + l.len + 1);
      break;
    case LEFT:
      bit.add(l.y, -1);
      break;
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 13724