#include<cstdio>
#include<iostream>
using namespace std;
int n,t[2010];
int l[2010],r[2010];
int cnt=0;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&t[i],&l[i],&r[i]);
		l[i]*=2,r[i]*=2;
		if (t[i]==2)
			r[i]--;
		else if (t[i]==3)
			l[i]++;
		else if (t[i]==4) l[i]++,r[i]--;
	}
	for (int i=1;i<n;i++)
		for (int j=i+1;j<=n;j++)
		{
			if (r[i]<l[j]||r[j]<l[i]) continue;
			cnt++;
		}
	printf("%d\n",cnt);
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <memory.h>

using namespace std;

typedef vector<int> VI;
typedef pair<int, int> PI;
typedef vector<PI> VPI;

#define FOR(i,a,n) for (int i = (a); i < (n); ++i)
#define FORE(i,a,n) for (int i = (a); i <= (n); ++i)
#define FORD(i,a,b) for (int i = (a); i >= (b); --i)
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FORE(i,0,n)
#define LL long long
#define FIR(n) REP(i,n)
#define FJR(n) REP(j,n)
#define ALL(v) v.begin(), v.end()

#define FI FIR(n)
#define FJ FJR(n)
#define FR(i,a) FOR(i,a,n)
#define REPN(i) REP(i,n)

#define GI(n) scanf("%d", &n)
#define GI2(n,m) scanf("%d %d", &n, &m)

int a[2020], b[2020];

int main() {
#ifdef LOCALF
	freopen("input.txt", "rt", stdin);
#endif
	ios::sync_with_stdio(false); cin.tie(0);	

	
	int n; cin >> n;
	int t, s, f;
	FI{
		cin >> t >> s >> f;
		s *= 2;
		f *= 2;
		if (t >= 3) ++s;
		if (t % 2 == 0) --f;
		a[i] = s;
		b[i] = f;
	}

	int res = 0;
	FI FOR(j, i + 1, n) if ((a[i] <= a[j] && a[j] <= b[i]) || (a[j] <= a[i] && a[i] <= b[j]))
		++res;
	cout << res << endl;

	
}
