#include <algorithm>
#include <cmath>
#include <cstddef>
#include <iostream>
#include <iterator>
#include <set>
#include <vector>

const double kEpsilon = 1e-10;

inline bool equals(double a, double b)
{
    return fabs(a - b) < kEpsilon;
}

class Point
{
  public:
    int x, y;

    Point() = default;
    Point(double x, double y) : x(x), y(y)
    {
    }

    Point operator+(const Point &p)
    {
        return Point(x + p.x, y + p.y);
    }
    Point operator-(const Point &p)
    {
        return Point(x - p.x, y - p.y);
    }
    Point operator*(const double k)
    {
        return Point(x * k, y * k);
    }

    double SquaredNorm()
    {
        return x * x + y * y;
    }
    double abs()
    {
        return sqrt(this->SquaredNorm());
    }

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

    double dot(const Point &p) const
    {
        return x * p.x + y * p.y;
    }
    double cross(const Point &p) const
    {
        return x * p.y - y * p.x;
    }
};

double dot(const Point &p1, const Point &p2)
{
    return p1.x * p2.x + p1.y * p2.y;
}
double cross(const Point &p1, const Point &p2)
{
    return p1.x * p2.y - p1.y * p2.x;
}

auto swap = [](auto &a, auto &b) {
    auto tmp = a;
    a = b;
    b = tmp;
};

class EndPoint : public Point
{
  public:
    int id, st;
    EndPoint() = default;
    EndPoint(double x, double y, int id, int st) : Point(x, y), id(id), st(st){};

    bool operator<(EndPoint &p)
    {
        return y != p.y ? y < p.y : st < p.st;
    }
};
struct Segment
{
    Point p1, p2;

    Segment() = default;
    Segment(Point p1, Point p2) : p1(p1), p2(p2)
    {
    }
};

const int LEFT = 1;
const int RIGHT = 2;
const int TOP = 3;
const int BOTTOM = 0;

int main()
{
    int n;
    std::cin >> n;

    EndPoint p1, p2;
    std::vector<EndPoint> endpoints;
    std::set<int> tree;
    std::vector<Segment> segments;

    tree.insert(1000000001);

    for (size_t i = 0; i < n; ++i)
    {
        std::cin >> p1.x >> p1.y >> p2.x >> p2.y;
        p1.id = i;
        p2.id = i;
        if (p1.y == p2.y)
        {
            if (p1.x < p2.x)
            {
                p1.st = LEFT;
                p2.st = RIGHT;
            }
            else
            {
                p1.st = RIGHT;
                p2.st = LEFT;
            }
        }
        else if (p1.x == p2.x)
        {
            if (p1.y < p2.y)
            {
                p1.st = BOTTOM;
                p2.st = TOP;
            }
            else
            {
                p1.st = TOP;
                p2.st = BOTTOM;
            }
        }
        endpoints.push_back(p1);
        endpoints.push_back(p2);

        if (p1 < p2)
            segments.push_back(Segment(p1, p2));
        else
            segments.push_back(Segment(p2, p1));
    }

    std::sort(endpoints.begin(), endpoints.end(), [](EndPoint a, EndPoint b) { return a < b; });

    int ans = 0;
    for (auto p : endpoints)
    {
        // auto p = endpoints.at(i);
        //    printf("%d %d: %d %d\n", p.x, p.y, p.id, p.st);

        if (p.st == BOTTOM)
        {
            tree.insert(p.x);
        }
        else if (p.st == TOP)
        {
            tree.erase(p.x);
        }
        else if (p.st == LEFT)
        {
            auto lower = tree.lower_bound(segments[p.id].p1.x);
            auto upper = tree.upper_bound(segments[p.id].p2.x);
            ans += std::distance(lower, upper);

            //  std::cout << "(xl, xu = )" << segments[p.id].p1.x << ", " << segments[p.id].p2.x << ":";
            // for (auto node : tree)
            // {
            //     std::cout << node << " ";
            // }
            // std::cout << std::endl;
            // std::cout << "ans+=" << ans << std::endl
            //  ;
        }
    }

    std::cout << ans << std::endl;
}



Measured memory_bytes: 10072