#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pair<int, int>>;
using pl = pair<ll, ll>;
using vl = vector<ll>;

#define all(v) (v).begin(), (v).end()
#define ar array
#define PB push_back
#define sz(x) (int)(x).size()

template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
    os << '{';
    string sep;
    for (const T &x : v)
        os << sep << x, sep = ", ";
    return os << '}';
}
void dbg_out()
{
    cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7; //998244353

void solve()
{
	int n;
	cin >> n;
	vector<pair<pi,pi>> p(n);
	for (int i=0;i<n;++i){
		int t,l,r;
		cin >> t >> l >> r;
		if (t==1) p[i] = {{l,1}, {r,1}};
		else if (t==2) p[i] = {{l,1}, {r,0}};
		else if (t==3) p[i] = {{l,0}, {r,1}};
		else p[i] = {{l,0}, {r,0}};
	}
	int ans = 0;
	for (int i=0;i<n;++i){
		pi l = p[i].first, r = p[i].second;
		for (int j=i+1;j<n;++j){
			pi L = p[j].first, R = p[j].second;
			if (L.first>r.first||R.first<l.first) continue;
			ans++;
			dbg(l, r, L,R);
			if (L.first==r.first&&(!L.second||!r.second))ans--;
			if (R.first==l.first&&(!R.second||!l.second))ans--;
		}
	}
	cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
}
#include <bits/stdc++.h>
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mb make_pair
#define el "\n"
#define MAX 100005
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	tez
	ll t = 1;
	// cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		vector <vector <ll>> p(n, vector <ll> (3));
		for (ll i = 0; i < n; ++i)
			cin >> p[i][2] >> p[i][0] >> p[i][1];
		sort(p.begin(), p.end());
		// for (ll i = 0; i < n; ++i)
		// {
		// 	cout << p[i][0] << " " << p[i][1] << " " << p[i][2];
		// 	cout << el;
		// }
		ll ans = 0;
		for (ll i = 0; i < n; ++i)
		{
			ll ed = p[i][1];
			for (ll j = i + 1; j < n; ++j)
			{
				if (p[j][0] > ed)
					break;
				else
				{
					if (p[j][0] < ed)
						ans++;
					else
					{
						if ((p[i][2] == 1 && p[j][2] == 1) ||
						        (p[i][2] == 1 && p[j][2] == 2) ||
						        (p[i][2] == 3 && p[j][2] == 1) ||
						        (p[i][2] == 3 && p[j][2] == 2))
							ans++;
					}
				}
			}
		}
		cout << ans << el;
	}
	return 0;
}