#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
const int N = 2e3 + 5;
struct interval { int l, r, t; } a[N];
int n, ans;

bool check (int x, int y) {
	if(a[x].r > a[y].r) swap(x, y);
	if(a[x].r > a[y].l) return true;
	if(a[x].r < a[y].l) return false;
	if(a[x].t == 2 || a[x].t == 4 || a[y].t == 3 || a[y].t == 4) return false;
	return true;
}

signed main () {
//	freopen ("C.in", "r", stdin);
	cin >> n;
	rep(i, 1, n) cin >> a[i].t >> a[i].l >> a[i].r;
	rep(i, 1, n) rep(j, i + 1, n) if(check(i, j)) ++ans;
	cout << ans;
	return 0; 
}
#include <bits/stdc++.h>
#define MAX (ll)(2e5 + 7)
#define INF (ll)(1e18 + 7)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;
using cd = complex<double>;
using ul = unsigned long;

void f_io () {
 ios_base :: sync_with_stdio (false);
 cin.tie (nullptr);
}

ll f[MAX], t[MAX];

void up (ll ind, ll v) {
	for (ll i = ind; i < MAX; i += i & (-i))  {
		f[i] += v;
	}
}

ll qu (ll ind) {
	ll s = 0;
	for (ll i = ind; i; i -= i & (-i)) {
		s += f[i];
	}
	return s;
}

ll mult (ll a, ll b) {
	return (((a % MOD) * (b % MOD)) % MOD);
}

ll add (ll a, ll b) {
	b = (((b % MOD) + MOD) % MOD);
	return (a % MOD + b % MOD) % MOD;
}

ll pw (ll a, ll b) {
	ll r = 1;
	while (b) {
		if (b & 1) {
			r = mult (r, a);
		}
		b >>= 1;
		a = mult (a, a);
	}
	return r;
}

ll ncr (ll n , ll r) {
	if (r < 0 || n < 0 || n < r) return 0;
	return mult (f[n], pw (mult (f[n - r], f[r]), MOD -2 ));
}

void sieve () {
	for (ll i = 1; i < MAX; i++) {
		for (ll j = i; j < MAX; j += i) {
			f[j]++;
		}
	}
}

ll gc (ll a, ll b) {
	if (!a || !b) {
		return max (a, b);
	}
	ll r = a % b;
	while (r) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

vector<pair<int,  int>> gr[MAX], vvs;
vector<pair<string, int>> vs;
vector<pair<int, string>> fe[MAX];
map<string, int> ma;

int main () {
	int n;
	cin >> n;
	int g = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		g = gc (x, g);
	}
	cout << g << "\n";
}
