// Rishabh Singhal
#include<bits/stdc++.h>
#define w(x)            int x; cin>>x; for(int tc=1;tc<=x;tc++)
#define trace(x) 		cerr<<#x<<": "<<x<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define f first
#define s second
#define inf 1e18

using namespace std;
bool cmp(vector<int>a, vector<int>b) {
	if (a[1] == b[1]) {
		return a[2] < b[2];
	} else
		return a[1] < b[1];
}
void solve(int tc) {
	int n;
	cin >> n;
	vector<vector<int>>vec;
	int a, b, c;
	for (int i = 0; i < n; i++) {
		cin >> a >> b >> c;
		vec.push_back({a, b, c});
	}
	sort(vec.begin(), vec.end(), cmp);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int type = vec[i][0];
		int x = vec[i][1];
		int y = vec[i][2];
		for (int j = i + 1; j < n; j++) {
			if (type == 1 or type == 3) {
				if (vec[j][1] > y) {

				} else if (vec[j][1] == y) {
					if (vec[j][0] == 1 or vec[j][0] == 2) {
						ans++;
					}
				} else {
					ans++;
				}
			} else {
				if (vec[j][1] < y) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

int32_t main() {
	FIO
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	// w(x) {
	solve(1);
// }
	return 0;
}

//mistakes
// debug fast don't be lazy
// always check for n = 1 condition
// clear the graph -- check index 1 based or 0 based
// set vis to 0
// check constraints of graph question
// use map and set wherever need

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<double,double> pdd;
#define forn(i,x,n) for(int i = x;i <= n;++i)
#define forr(i,x,n) for(int i = n;i >= x;--i)
#define Angel_Dust ios::sync_with_stdio(0);cin.tie(0)
#define x first
#define y second

const int N = 2005;
pdd a[N];

int main()
{
    int n;scanf("%d",&n);
    forn(i,1,n)
    {
        int t,l,r;scanf("%d%d%d",&t,&l,&r);
        a[i] = {l,r};
        if(t == 2)  a[i].y -= 0.1;
        if(t == 3)  a[i].x += 0.1;
        if(t == 4)  a[i].x += 0.1,a[i].y -= 0.1; 
    }

    int res = 0;
    forn(i,1,n) forn(j,i + 1,n)
    {
        if(min(a[i].y,a[j].y) < max(a[i].x,a[j].x)) continue;
        ++res;
    }
    printf("%d\n",res);

    return 0;
}
