#include <bits/stdc++.h>   using namespace std;   void doRoutine() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     srand(322179);   }   const int C = 5010;   int tr[C * 8];   bool cross(pair<pair<int, int>, int> hor, pair<int, pair<int, int> > vert) {     return (vert.second.first <= hor.second &&             hor.second <= vert.second.second) &&            (hor.first.first <= vert.first && vert.first <= hor.first.second);   }   void init() {     for (int i = 0; i < C * 8; ++i) {       tr[i] = 0;     }   }   int get(int l, int r, int lb = -C, int rb = C, int v = 0) {     if (l == lb && r == rb) {       return tr[v];     } else {       int mb = (lb + rb) / 2;       if (r <= mb) {         return get(l, r, lb, mb, v * 2 + 1);       } else if (l >= mb) {         return get(l, r, mb, rb, v * 2 + 2);       } else {         return get(l, mb, lb, mb, v * 2 + 1) + get(mb, r, mb, rb, v * 2 + 2);       }     }   }   void add(int i, int x, int lb = -C, int rb = C, int v = 0) {     if (lb + 1 == rb) {       tr[v] += x;     } else {       int mb = (lb + rb) / 2;       if (i < mb) {         add(i, x, lb, mb, v * 2 + 1);       } else if (i >= mb) {         add(i, x, mb, rb, v * 2 + 2);       }       tr[v] = tr[v * 2 + 1] + tr[v * 2 + 2];     }   }   signed main() {     doRoutine();     int n;     cin >> n;     vector<pair<int, pair<int, int> > > verts;     vector<pair<pair<int, int>, int> > hors;     for (int i = 0; i < n; ++i) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (x1 > x2) {         swap(x1, x2);       }       if (y1 > y2) {         swap(y1, y2);       }       if (x1 == x2) {         verts.push_back({x1, {y1, y2}});       } else {         hors.push_back({{x1, x2}, y1});       }     }     sort(verts.begin(), verts.end());     long long ans = 0;     for (int i = 0; i < verts.size(); ++i) {       vector<pair<int, int> > events;       for (auto seg : hors) {         if (cross(seg, verts[i])) {           events.push_back({seg.first.second, seg.second});         }       }       if (!events.empty()) {         sort(events.begin(), events.end());         reverse(events.begin(), events.end());         int ptr = 0;         init();         for (int j = (int)verts.size() - 1; j > i; --j) {           while ((ptr < events.size() && events[ptr].first >= verts[j].first)) {             add(events[ptr].second, 1);             ++ptr;           }           int cnt = get(verts[j].second.first, verts[j].second.second + 1);           ans += cnt * (cnt - 1) / 2;         }       }     }     cout << ans << endl;     return 0;   }   