#include <bits/stdc++.h>
#define ll long long
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
using namespace std;
const ll N = 5e5 + 100;
ll num[N << 2], sum[N << 2], s[N];
struct poll {
    ll flag;
    ll x, y;
    poll (){}
    poll (ll _x, ll _y, ll _flag) {
        x = _x, y = _y, flag = _flag;
    }
    void input () {
        scanf ("%lld %lld", &x, &y);
    }
    bool operator < (const poll &b) const {
        return x < b.x || (x == b.x && y < b.y);
    }
} ;
struct line {
    ll y, flag;
    poll s, e;
    void input () {
        s.input (), e.input ();
    }
} ps[N << 2];
ll cmp (line a, line b) {
    return a.y < b.y || (a.y == b.y && a.flag < b.flag);
}
inline void F (ll rt) {
    sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
void update (ll pos, ll k, ll l, ll r, ll rt) {
    if (l == r) {
        sum[rt] += k;
        return;
    }
    ll mid = l + r >> 1;
    if (pos <= mid) update (pos, k, lson);
    else update (pos, k, rson);
    F (rt);
}
ll query (ll L, ll R, ll l, ll r, ll rt) {
    if (L <= l && r <= R) return sum[rt];
    ll mid = l + r >> 1, ans = 0;
    if (L <= mid) ans += query (L, R, lson);
    if (R > mid) ans += query (L, R, rson);
    return ans;
}
int main () {
//    freopen ("in.txt", "r", stdin);
    ll n, v = 0, ans = 0;
    cin >> n;
    ll temp = n;
    for (ll i = 0; i < n; i++) ps[i].input (), s[v++] = ps[i].s.x, s[v++] = ps[i].s.y, s[v++] = ps[i].e.x, s[v++] = ps[i].e.y;
    sort (s, s + v);
//    cout << endl;
    ll len = unique (s, s + v) - s;
    for (ll i = 0, flag; i < n; i++) {
        if (ps[i].e < ps[i].s) swap (ps[i].s, ps[i].e);
//        cout << ps[i].s.x << ' ' << ps[i].s.y << ' ' << ps[i].e.x << ' ' << ps[i].e.y << endl;
        if (ps[i].e.x == ps[i].s.x) {
            ps[i].flag = -1;
            ps[i].y = ps[i].s.y;

            ps[temp].flag = 1;
            ps[temp].s.x = ps[i].s.x;
            ps[temp].y = ps[i].e.y;
            temp++;
        } else {
            ps[i].flag = 0;
            ps[i].y = ps[i].s.y;
        }
    }
    sort (ps, ps + temp, cmp);
    for (ll i = 0; i < temp; i++) {
        if (ps[i].flag) {
            ll u = lower_bound(s, s + len, ps[i].s.x) - s + 1;
//            cout << "****" << ps[i].s.x << ' ' << ps[i].y << ' ' << u << ' ' << ps[i].flag << endl;
            if (ps[i].flag > 0) update (u, -1, 1, len, 1);
            else update (u, 1, 1, len, 1);
        } else {
//            cout << ps[i].s.x << ' ' << ps[i].e.x << endl;
            ll a = lower_bound(s, s + len, ps[i].s.x) - s + 1;
            ll b = lower_bound(s, s + len, ps[i].e.x) - s + 1;
            ans += query (a, b, 1, len, 1);
//        cout << ans << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

