#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define endline '\n'
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define pb push_back
#define fr(i,a,b) for(int i=a;i<(int)b;i++)
#define rfr(i,a,b) for(int i=a;i>=(int)b;i--)
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
const ll mod=1e9+7;
#define INF 0x3f3f3f3f

const int N = 1e6+2;
 
void solution(){
	vector<pair<ll,pll>> v;
    int n;cin>>n;
    fr(i,0,n)
    {
        ll x,y,z; cin>>x>>y>>z;
        v.pb({x,{y,z}});
    }
    int c=0;
    sort(all(v));

    fr(i,0,n)
    {
        fr(j,i+1,n)
        {
            double a1[]={0,0,0.00001,0.00001};
            double b1[]={0,-0.00001,0,-0.00001};
            int f1=v[i].first;int f2=v[j].first;
            long double x1=0,y1=0,x2=0,y2=0;
            fr(k,0,4)
            {
                if(f1==k+1)
                {
                    x1=v[i].second.first+a1[k],y1=v[i].second.second+b1[k];
                }
                if(f2==k+1)
                {
                    x2=v[j].second.first+a1[k],y2=v[j].second.second+b1[k];
                }
            }
            
            if((x1<=x2 and x2<=y1) or (x2<=x1 and x1<=y2) or (x1<=y2 and y2<=y1) or (x2<=y1 and y1<=y2))c++;
        }
    }
    cout<<c<<endline;
}

int main() {
	// your code goes here
	int t=1;
	//cin>>t;
	while(t--){
		solution();
	}

	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;

const int N = 2e3 + 50;

double l[N], r[N];

bool ck(int u, int v)
{
    if (r[u] < l[v] || l[u] > r[v]) return false;
    else return true;
}

int main()
{
    int n, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i ++)
    {
        int t;
        cin >> t >> l[i] >> r[i];
        if (t == 2 || t == 4) r[i] -= 0.5;
        if (t == 3 || t == 4) l[i] += 0.5;
        for (int j = 0; j < i; j ++)
            if (ck(i, j)) ans ++;
    }
    cout << ans << endl;

    return 0;
}