#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <limits>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
 // < でBの方が大

int main() {
    ll N;
    cin >> N;
    vector<ll> T(N);
    vector<ll> L(N);
    vector<ll> R(N);
    rep(n, N) {
        ll t;
        cin >> T[n] >> L[n] >> R[n];
        
    }
    ll ans = 0;
    rep(n, N) {
        ll l = L[n];
        ll r = R[n];
        ll t = T[n];
        for(ll i = n+1; i < N; i++) {
            // n と iの区間を比較
            ll li = L[i];
            ll ri = R[i];
            ll ti = T[i];

            if (t == 1 && ti == 1) {
                if (li>= l && li <= r) ans++;
                if (li < l && !(ri < l)) ans++;
            }
            if (t == 1 && ti == 2) {
                if (li>= l && li <= r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }
            if (t == 1 && ti == 3) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri < l)) ans++;
            }
            if (t == 1 && ti == 4) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }

            if (t == 2 && ti == 1) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri < l)) ans++;
            }
            if (t == 2 && ti == 2) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }
            if (t == 2 && ti == 3) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri < l)) ans++;
            }
            if (t == 2 && ti == 4) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }

            if (t == 3 && ti == 1) {
                if (li>= l && li <= r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }
            if (t == 3 && ti == 2) {
                if (li>= l && li <= r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }
            if (t == 3 && ti == 3) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }
            if (t == 3 && ti == 4) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }

            if (t == 4 && ti == 1) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }
            if (t == 4 && ti == 2) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }
            if (t == 4 && ti == 3) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }
            if (t == 4 && ti == 4) {
                if (li>= l && li < r) ans++;
                if (li < l && !(ri <= l)) ans++;
            }
        }
    }
    cout << ans << endl;
} 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

#define ordered_pair_multiset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>

#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define fillc(a,b) memset(a,b,sizeof(a))
#define MOD 1000000007
#define INF 1e17
#define multi_test 0

bool compare(pll u,pll v)
{
	return u.ff<=v.ff;
}

void solve()
{
	ll n,i,j,t;
	cin>>n;
	pair<long double,long double> in[n];
	long double inc=1e-9;
	for(i=0;i<n;i++)
	{
		cin>>t>>in[i].ff>>in[i].ss;
		if(t==2)
			in[i].ss-=inc;
		else if(t==3)
			in[i].ff+=inc;
		else if(t==4)
			in[i].ff+=inc,in[i].ss-=inc;
	}
	sort(in,in+n);
	ll ans=0;
	/*for(i=0;i<n;i++)
		cout<<setprecision(20)<<l[i]<<" "<<r[i]<<endl;*/
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(in[j].ff>=in[i].ff && in[j].ff<=in[i].ss)
				ans++;
			//cout<<ans<<" ";
		}
		//cout<<endl;
	}
	cout<<ans<<endl;
}

int main()
{
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1,i;
    if (multi_test)
        cin>>t;
    for(i=1;i<=t;i++)
        solve();
}