/*
problem :
algorithm :
created : Programmer_juruo
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define N 2000005
#define M 2005
#define lowbit(x) x & (-x)
#define F1(i, n) for(int i = 1; i <= n; i++)
#define F(i, a, n) for(int i = a; i <= n; i++)
#define F0(i, n) for(int i = 0; i < n; i++)
#define dbg(x) cout << #x << ":" << x << endl;
#define se second
#define fi first
#define y1 juruo
#define mp make_pair
#define pb push_back
#define arr vector<int>
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

typedef pair <int, int> pii;
typedef priority_queue <int> pq;
typedef long long ll;

const ll inf = 0x3f3f3f3f3f3f3f3f;
const int p = 107;
const int P = 100007;
const int Mod = 1e9+7;

int n, m;
int t[N], l[N], r[N];
vector <pair<int, pair<int, int> > > v; 
void work() {
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = i+1; j <= n; j++) {
			v.clear();
			v.pb(mp(l[i], pii(r[i], t[i])));
			v.pb(mp(l[j], pii(r[j], t[j])));
			sort(v.begin(), v.end());
			if(v[0].se.fi > v[1].fi) {
				++ans;
			} else if(v[0].se.fi == v[1].fi) {
				if(v[0].se.se == 1 || v[0].se.se == 3) {
					if(v[1].se.se == 1 || v[1].se.se == 2) {
						++ans;
					}
				}
			}
		}
	}
	cout << ans << endl;
}

signed main() {
  //freopen("1.in", "r", stdin);
  //freopen("1.out", "w", stdout);
  int T = 1;

  //cin >> T;

  while(T--) {
  	work();
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define fo(a,b,c) for(int a=b;a<c;a++)
#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 3e5 + 5;
const int inf = 1e18 + 2;
int power(int a,int b)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    {
    int c=power(a,b/2);
    return (c*c)%mod;
    }
    else
    return ((a%mod)*(power(a,b-1)%mod))%mod;
}
void solve(int Case)
{
    int n,s=0;
    cin>>n;
    int a[n][3];
    fo(i,0,n)
    {
        fo(j,0,3)
        {
            cin>>a[i][j];
        }
    }
    fo(i,0,n)
    {
        fo(j,i+1,n)
        {
            if(a[i][2]>a[j][2])
            {
                if(a[i][1]<a[j][2])
                s++;
                else if(a[i][1]==a[j][2])
                {
                    if((a[i][0]==1||a[i][0]==2)&&(a[j][0]==3||a[j][0]==1))
                    s++;
                }
            }
            else if(a[i][2]<a[j][2])
            {
                swap(i,j);
                if(a[i][1]<a[j][2])
                s++;
                else if(a[i][1]==a[j][2])
                {
                    if((a[i][0]==1||a[i][0]==2)&&(a[j][0]==3||a[j][0]==1))
                    s++;
                }
                swap(i,j);
            }
            else
            s++;
        }
    }
    cout<<s;
}
int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int Case = 1;
    while(testcase --)
    {
        solve(Case);
    }
    return 0;
}