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
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

template<typename V> class BIT {
private:
	int n; vector<V> bit;
public:
	void add(int i,V x){ i++; while(i < n) bit[i] += x, i += i & -i;}
	V sum(int i){ i++; V s = 0; while(i>0) s += bit[i], i -= i & -i; return s;} //0_indexedでi以下の要素の和
	BIT(){} BIT(int sz){ n = sz + 1, bit.resize(n,0);} //初期値がすべて0の場合
	BIT(vector<V> v){ n = (int)v.size()+1; bit.resize(n); rep(i,n-1) add(i,v[i]);}
	void print(){ rep(i,n-1)cout<<sum(i)-sum(i-1)<< " ";cout<<endl;}
	void print_sum(){ rep(i,n)cout<<sum(i-1)<<" ";cout<<endl;}	//-1スタート
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> X(2*n),Y(2*n);
    vector<int> a(n),b(n),c(n),d(n);
    rep(i,n){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        if(a[i] > c[i]) swap(a[i],c[i]);
        if(b[i] > d[i]) swap(b[i],d[i]);
        X[2*i] = a[i], X[2*i+1] = c[i];
        Y[2*i] = b[i], Y[2*i+1] = d[i];
    }
    zip(X),zip(Y);
    vector<vector<int> > st(len(Y)),ed(len(Y));
    vector<vector<P> > ch(len(Y));
    rep(i,n){
        if(a[i] != c[i]){
            //横線
            ch[lower_bound(all(Y),b[i])-Y.begin()].pb(P(lower_bound(all(X),a[i])-X.begin(),lower_bound(all(X),c[i])-X.begin()));
        }else{
            //縦線
            st[lower_bound(all(Y),b[i])-Y.begin()].pb(lower_bound(all(X),a[i])-X.begin());
            ed[lower_bound(all(Y),d[i])-Y.begin()].pb(lower_bound(all(X),a[i])-X.begin());
        }
    }
    int ans = 0;
    BIT<int> bt(len(X));
    rep(i,len(Y)){
        each(j,st[i]){
            bt.add(j,1);
        }
        each(j,ch[i]){
            ans += bt.sum(j.se) - bt.sum(j.fi-1);
        }
        each(j,ed[i]){
            bt.add(j,-1);
        }
    }
    cout << ans << "\n";
    return 0;
}

