#include <bits/stdc++.h>
using namespace std;
#define int long long
#define M (int)(1e9 + 7)

const int len = 1e8 + 8;
//int ar[len];
bool comp(array<int, 3> a, array<int, 3> b)
{
    if (a[0] == b[0])
    {
        return a[1] < b[1];
    }
    else
        return a[0] < b[0];
}

int solve()
{
    
    int n;
    cin >> n;

    vector<pair<double,double>> values;
    for(int i=0;i<n;i++){
        double t,l,r;
        cin >> t >> l >> r;

        if(t == 1)
        {
            values.push_back({l,r});
        }
        else if(t==2)
        {
            values.push_back({l,r-0.1});
        }
        else if(t==3)
        {
            values.push_back({l+0.1,r});
        }
        else {
            values.push_back({l+0.1,r-0.1});
        }
    }
    int count = 0;

    sort(values.begin(),values.end());

    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(values[i].second>= values[j].first)
            {
                count++;
            }
        }
    }
    return count;
    

    
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    // int t;
    // cin >> t;
    // while (t--)
    // {
    //      cout << solve() << "\n";
    //     //solve();
    // }
    cout <<  solve() <<"\n";
}
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=2004};

struct sth{
	int t,l,r;
	bool operator < (const sth&e){ return l<e.l; }
} d[N];

int main(){
	int n = ci();
	int ans = 0;
	rep(i,1,n) d[i] = {ci(),ci(),ci()};
	sort(d+1,d+n+1);
	rep(i,1,n){
		rep(j,1,i-1){
			bool ok = 0;
			if( d[j].r > d[i].l ) ok = 1;
			if( d[j].r == d[i].l && (d[j].t&1) && (d[i].t<=2) ) ok = 1;
			ans += ok;
		}
	}
	cout<<ans<<endl;
	return 0;
}
