#include <bits/stdc++.h>
//#include <cmath>
typedef long long ll;
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
//#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define bs(yup,x) binary_search(yup.begin(),yup.end(),x) //it will return bollean value
#define lb(yup,x) lower_bound(yup.begin(),yup.end(),x)  //it will return the adress of the number which is equal to or just greater than x ,and if it is equal to yup.end() than their in no such number exist
#define ub(yup,x) upper_bound(yup.begin(),yup.end(),x)
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long N=1000001,INF=2000000000000000000;
const long double EPS= 0.000000000001;

// calculate a^b%p
ll power(ll a, ll b, ll p)
    {
        if(a==0)
        return 0;
        ll res=1;
        //a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

//sieve to calculate an array of prime and non prime integers till N
vi prime;
bool isprime[N];
void pre()
{
    for(int i=2;i<N;i++)
    {
        if(isprime[i])
        {
            for(int j=i*i;j<N;j+=i)
            isprime[j]=false;
            prime.pb(i);
        }
    }
    return;
}

double fn_ternary(double b,double c,double x){
	double ans = (x*x + b*x + c)/(sin(x));
	return ans;
}

double ternary_search(double l,double r,double b,double c){
	//for finding minimum
	//to find max interchange r and l
	double eps = 1e-10;
	while(r-l>eps){
		double m1 = l+(r-l)/3;
		double m2 = r-(r-l)/3;
		double f1 = fn_ternary(b,c,m1);
		double f2 = fn_ternary(b,c,m2);
		if(f1<f2){
			r = m2;
		}else{
			l = m1;
		}
	}
	return fn_ternary(b,c,l);
}

ll binary_search(ll a[],int n,ll k){
	int l = 0,r = n-1;
	while(l<=r){
		int m = l + (r-l)/2;
		if(a[m]==k){
			return m;
		}
		else if(a[m]>=k){
			r = m - 1;
		}
		else if(a[m]<k){
			l = m + 1;
		}
	}
	return -1;
}

// if more values to calculate use pascals triangle (C(n,k) = C(n-1,k-1)+C(n-1,k))
/*
const ll maxn = 1000000;
ll C[maxn+1][maxn+1];
C[0][0] = 1;
void nCr(ll p){
	for(ll i=1;i<=maxn;i++){
		C[i][0] = C[i][i] = 1;
		for(int j = 1;j<=i;j++){
			C[i][j] = (C[i-1][j-1]%p + C[i-1][j]%p)%p;
		}	
	}
	return ;
}
*/
//calculating ncr modulo using fermats little theorem 
//useful while calculating less discrete values of ncr

ll modinverse(ll n,ll p){
	return power(n,p-2,p);
}

ll nCr(ll n,ll r,ll p){
	ll f[n+1];
	f[0] = 1;
	for(ll i=1;i<=n;i++){
		f[i] = f[i-1]*i%p;
	}
	
	return (f[n]%p * modinverse(f[r],p)%p * modinverse(f[n-r],p)%p)%p;
}



bool comp(vector<int> v1,vector<int> v2){
	return v2[0]>v1[0];
}
int main() {
    IOS;
    //fill(isprime, true);
    //pre();
    int t;
    //cin>>t;
    t=1;
    while(t--){
		int n;
		cin>>n;
		vector<int> v[n];
		for(int i=0;i<n;i++){
			int id,x,y;
			cin>>id>>x>>y;
			v[i].push_back(x);
			v[i].push_back(y);
			v[i].push_back(id);
		}
		int cnt = 0;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				vector<int> a = v[i],b = v[j];
				if(a[0]<=b[0]){
					if(a[1]==b[0]&&(a[2]==1||a[2]==3)&&(b[2]==1||b[2]==2)){
						cnt++;
					}
					else if(a[1]>b[0]){
						cnt++;
					}
				}
				else{
					if(b[1]==a[0]&&(b[2]==1||b[2]==3)&&(a[2]==1||a[2]==2)){
						cnt++;
					}
					else if(b[1]>a[0]){
						cnt++;
					}
				}
	
				
			}
		}
		cout<<cnt<<endl;
	}
	
	return 0;
}
#include <iostream>
#include <vector>
#pragma GCC optimize ("-O3")
using namespace std;

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<double> l(n), r(n);
    for (int i = 0; i < n; i++) {
        int t; cin >> t >> l[i] >> r[i];
        t--;
        if (t & 1) r[i] -= 0.5;
        if (t & 2) l[i] += 0.5;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += (max(l[i], l[j]) <= min(r[i], r[j]));
        }
    }
    cout << ans << endl;
}