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

using namespace std;

struct Segment {
    int x1, y1, x2, y2;
    
    Segment(int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0): 
    x1(min(x1, x2)), x2(max(x1, x2)), y1(min(y1, y2)), y2(max(y1, y2)) {}
    
};

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

struct Event {
    int seg;
    int type;
    int x;
    
    Event(int seg = -1, int type = -1, int x = -1): seg(seg), type(type), x(x) {}
    
    bool operator<(const Event other) const {
        if (x == other.x) {
            return type < other.type;
        }
        else {
            return x < other.x;
        }
    } 
};

int main() {
    int n;
    cin >> n;
    int x1, y1, x2, y2;
    vector<Segment> segs(n);
    vector<Event> events;
    
    for (int i = 0; i < n; i++) {
        cin >> x1 >> y1 >> x2 >> y2;
        segs[i] = Segment(x1, y1, x2, y2);
        if (segs[i].y1 == segs[i].y2) {
            events.push_back(Event(i, LEFT, segs[i].x1));
            events.push_back(Event(i, RIGHT, segs[i].x2));
        }
        else {
           events.push_back(Event(i, BOTTOM, segs[i].x1));
           events.push_back(Event(i, TOP, segs[i].x1)); 
        }  
    }
    
    sort(events.begin(), events.end());
    
//    for (Segment s : segs) {
//        cout << s.x1 << " " << s.y1 << " " << s.x2 << " " << s.y2 << endl;
//    }
//    
//    for (Event e : events) {
//        cout << e.x << " " << e.type << " " << e.seg << endl;
//    }
    
    int count = 0;
    set<int> bst;
    
    for (Event e: events) {
        Segment s = segs.at(e.seg);
        if (e.type == LEFT) {
            bst.insert(s.y1);
        }
        else if (e.type == RIGHT) {
            bst.erase(s.y1);
        }
        else if (e.type == TOP) {
            auto lower = bst.lower_bound(s.y1);
            auto upper = bst.upper_bound(s.y2);
            count += distance(lower, upper);
        }
    }
    cout << count << endl;
    
    return 0;
}