#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int x[2010];
int y[2010];

int main() {
	int n,t,li,ri,ans;

	cin >> n;
	rep(i,n){
		cin >> t >> li >> ri;
		li*=2;
		ri*=2;
		if(t==2)ri--;
		if(t==3)li++;
		if(t==4){
			li++;
			ri--;
		}
		x[i]=li;
		y[i]=ri;
	}
	ans=0;
	rep(i,n){
		rep(j,n){
			if(i>=j) continue;
			if(y[i]<x[j]) continue;
			if(y[j]<x[i]) continue;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
const ll INF = 1e9+7;
 
int main(){		
	ll n;
	cin >> n;
	double t, a, b;
	vector<pair<double, double>>v;
	for(ll i=0; i<n; i++){
		cin >> t >> a >> b;
		if(t == 1)
			v.push_back(make_pair(a, b));
		else if(t == 2)
			v.push_back(make_pair(a, b-0.5));
		else if(t == 3)
			v.push_back(make_pair(a+0.5, b));
		else if(t == 4)
			v.push_back(make_pair(a+0.5, b-0.5));
	}
	ll ans = 0;
	for(int i=0; i<n-1; i++){
		for(int j=i+1; j<n; j++){
			if(max(v[i].first, v[j].first) <= min(v[i].second, v[j].second))
				ans++;
		}
	}
	cout << ans << endl;
	return 0;
}