#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define pf first
#define ps second
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define Endl '\n'
#define codejam cout<<"Case #"<<t<<": ";
#define PI 3.141592653589793238462
#define sz(x) ((int)(x).size())
#define mod 1000000007
#define forn(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double lld;

//////////////////////////////////// DEBUGGER ///////////////////////////////////////////
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; debugger(x); cerr << endl;
#else
#define debug(x)
#endif
void debugger(ll t) {cerr << t;}void debugger(int t) {cerr << t;}void debugger(string t) {cerr << t;}void debugger(char t) {cerr << t;}void debugger(lld t) {cerr << t;}void debugger(double t) {cerr << t;}void debugger(ull t) {cerr << t;}template <class T, class V> void debugger(pair <T, V> p);template <class T> void debugger(vector <T> v);template <class T> void debugger(set <T> v);template <class T, class V> void debugger(map <T, V> v);template <class T> void debugger(multiset <T> v);template <class T, class V> void debugger(pair <T, V> p) {cerr << "{"; debugger(p.pf); cerr << ","; debugger(p.ps); cerr << "}";}template <class T> void debugger(vector <T> v) {cerr << "[ "; for (T i : v) {debugger(i); cerr << " ";} cerr << "]";}template <class T> void debugger(set <T> v) {cerr << "[ "; for (T i : v) {debugger(i); cerr << " ";} cerr << "]";}template <class T> void debugger(multiset <T> v) {cerr << "[ "; for (T i : v) {debugger(i); cerr << " ";} cerr << "]";}template <class T, class V> void debugger(map <T, V> v) {cerr << "[ "; for (auto i : v) {debugger(i); cerr << " ";} cerr << "]";}
ll gcd(ll a,ll b) {if(b==0 || a==0) return max(a,b);return gcd(b,a%b);}

//////////////////////////////////// JAI SHREE RAM /////////////////////////////////////
const ll N=1e5+5;

void JAISHREERAM()
{
    ll n,ans=0;
    cin>>n;
    vector<pair<double,double>> a(n);
    forn(i,n) 
    {
        ll x;
        cin>>x>>a[i].pf>>a[i].ps;
        if(x==2)  a[i].ps-=0.000001;
        else if(x==3) a[i].pf+=0.000001;
        else if(x==4) a[i].pf+=0.000001,a[i].ps-=0.000001;
    }
    n=sz(a);
    sort(all(a));
    forn(i,n)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[j].pf>a[i].ps) continue;
            ans++;
        }
    }
    cout<<ans;
}
int main()
{
    fast;
    int T=1;
    // cin>>T;
    for(int t=1;t<=T;t++)
    {
        // codejam
        JAISHREERAM();
    }
    return 0;
}
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};


struct range_t
{
	int l, r;
};


int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;

	for(;;)
	{
		cin >> n;
		if(cin.fail()) break;
		vpii range(n);
		for(int i=0;i<n;i++)
		{
			int t, l, r;
			cin >> t >> l >> r;
			l*=2;
			r*=2;
			switch(t)
			{
				case 1: break;
				case 2: r--; break;
				case 3: l++; break;
				case 4: l++; r--; break;
			}
			range[i]=make_pair(l, r);
		}
		sort(range.begin(), range.end());

		int ans=0;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(range[i].second>=range[j].first) ans++;
			}
		}
		cout << ans << "\n";
	}
	return 0;
}
