For given $n$ segments which are parallel to X-axis or Y-axis, find the number of intersections of them.

Constraints

* $1 \leq n \leq 100,000$
* $ -1,000,000,000 \leq x_1, y_1, x_2, y_2 \leq 1,000,000,000$
* Two parallel segments never overlap or touch.
* The number of intersections $\leq 1,000,000$

Input

In the first line, the number of segments $n$ is given. In the following $n$ lines, the $i$-th segment is given by coordinates of its end points in the following format:

$x_1 \; y_1 \; x_2 \; y_2$

The coordinates are given in integers.

Output

Print the number of intersections in a line.

Example

Input

6
2 2 2 5
1 3 5 3
4 1 4 4
5 2 7 2
6 1 6 3
6 5 6 7


Output

3
/*<<head>> {{{*/
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//INF = 1 061 109 567 ; INF + INF = 2 122 219 134 ;
//LINF = 4 557 430 888 798 830 399 ; LINF + LINF = 9 114 861 777 597 660 798 ;
const int INF = 0x3f3f3f3f;     // -INF: 0xc0   abs(-INF) = INF + 1
const ll LINF = 0x3f3f3f3f3f3f3f3f;
/*}}}*/                         // zr, zm
const int MOD = (int)1e9+7;     // when MOD = 1e9+7, inv2 = 500000004
const int N = (int)1e6+7;

// ------- 变量 ------- //

struct node {
    int x1, x2, y, ty;
    node () {} node (int x1, int x2, int y, int ty) : x1(x1), x2(x2), y(y), ty(ty) {}
    bool operator < (const node &rhs) const {
        return y != rhs.y ? y < rhs.y : ty > rhs.ty;
    }
};

int n;
vector <node> endp;
vi dis;

// ------- 函数 ------- //

int rk(int x) { return lower_bound(all(dis), x) - dis.begin() + 1; }

int t[N];
int sum(int x) { int res = 0; for (; x > 0; x -= x&-x) res += t[x]; return res; }
void upd(int x, int d) { for (; x <= N; x += x&-x) t[x] += d; }

void Init() {
    endp.clear(); dis.clear();
    rep(i, 0, n) {
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        if (x1 == x2) {
            if (y1 > y2) swap(y1, y2);
            endp.pb(node(x1, 0, y1, 1));
            endp.pb(node(x1, 0, y2, -1));
        } else {
            if (x1 > x2) swap(x1, x2);
            endp.pb(node(x1, x2, y1, 0));
        }
        dis.pb(x1); dis.pb(x2);
    }
    sort(all(dis));
    dis.erase(unique(all(dis)), dis.end());
    sort(all(endp));
}

int Solve() {
    int ans = 0;
    for (auto o : endp) {
        if (o.ty == 0) {
            ans += sum(rk(o.x2)) - sum(rk(o.x1)-1);
        } else {
            upd(rk(o.x1), o.ty);
        }
    }
    printf("%d\n", ans);
    return 0;
}

// ------- main ------- //

int main ()
{
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    //Pre();
    //int t; scanf("%d", &t); while (t--) {
    while (~scanf("%d", &n)) {
    //while(fgets(s, N, stdin)) {   // 注意 fgets 会读入换行符
        //if (n == 0) break;
        //static int kase = 0; printf("Case %d: ", ++kase);
        Init();
        Solve();
        //if (t) puts("");
    }
    return 0;
}
