/*
	_(┐「ε:)_
*/
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define spc(x, y) setprecision(y) << fixed << x
#define slc(x, w, c) setw(w) << setfill(c) << x
#define file "TEST"
typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef double db;
#define _OD "DEBUG>> "
#define deb_v(x) cerr << _OD << (#x) << ": " << x << '\n'
#define deb_vec(x) cerr << _OD << (#x) << ": "; for (auto i : x) cerr << i << ' '; cerr << '\n'
#define deb_arr(x, l, r) cerr << _OD << (#x) << ": "; for (int i = l; i <= r; ++i) cerr << x[i] << ' '; cerr << '\n'
#define _deb_vec(x) cerr << _OD << (#x) << ": "; for (int i = x.size() - 1; i >= 0; --i) cerr << x[i] << ' '; cerr << '\n'
#define _deb_arr(x, r, l) cerr << _OD << (#x) << ": "; for (int i = r; i >= l; --i) cerr << x[i] << ' '; cerr << '\n'
#define START_TIMER clock_t _, __; _ = clock()
#define END_TIMER __ = clock(); db ___ = db(__ - _) / (db)CLOCKS_PER_SEC; cerr << "\nTime executed: " << spc(___, 5) << " sec\n"
mt19937_64 rd(time(0));
template<typename T> T gcd(T a, T b) { return (b == 0)? a : gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T max(T a, T b, T c) { return max(a, max(b, c)); }
template<typename T> T max(T a, T b, T c, T d) { return max(a, max(b, c, d)); }
ll mulmod(ll a, ll b, ll n) {
	if (b == 0)
		return 0;
	ll tmp = mulmod(a, b >> 1, n);
	if (b & 1)
		return (tmp * 2 % n + a) % n;
	return tmp * 2 % n;
}
template<typename T>
T i_rand(T l, T r) {
	assert(l <= r);
	return uniform_int_distribution<T>(l, r)(rd);
}
template<typename T>
T r_rand(T l, T r) {
	return uniform_real_distribution<T>(l, r)(rd);
}
template<typename T>
void sfe(T a[], int l, int r) {
	shuffle(a + l, a + 1 + r, rd);
}
template<typename T>
void sfe(vector<T> a) {
	shuffle(a.begin(), a.end(), rd);
}
int n;
db l[2001], r[2001], t[2001];
signed main() {
	START_TIMER; ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
	// freopen(file".INP", "r", stdin);
	// freopen(file".OUT", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> t[i] >> l[i] >> r[i];
		if (t[i] == 1)
			continue;
		if (t[i] == 2)
			r[i] -= 0.5;
		if (t[i] == 3)
			l[i] += 0.5;
		if (t[i] == 4) {
			r[i] -= 0.5;
			l[i] += 0.5;
		}
	}
	int rs = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j < i; ++j)
			if (max(l[i], l[j]) <= min(r[i], r[j]))
				++rs;
	cout << rs;
	END_TIMER; return 0;
}
/*
	proof & correctness
	run some pretest
	int32 overflow
	array size
	reinit after tests
	write a tester
	read code line after line again (without reading the template)
	submit
*/
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define forn(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define sz(x) ((int)(x).size())
#define dbg(x) cerr << #x << "->" << x << "\n";
#define prnt(x) cerr<<"{ ";for(auto i:x)cerr<<i<<" ";cerr<<"}\n";

void solve() {
	int N; cin >> N;
	vector<pair<long double, long double>> v;
	long double d = 1e-9;
	forn(_, N) {
		int t;
		long double l, r;
		cin >> t >> l >> r;
		if (t == 1) v.pb({l, r});
		if (t == 2) v.pb({l, r - d});
		if (t == 3) v.pb({l + d, r});
		if (t == 4) v.pb({l + d, r - d});
	}
	int ans = 0 ;
	forn(i, N) {
		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;
}

int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int t = 1;
	// cin >> t;
	forn(i, t)
	solve();
}