// #pragma GCC optimize("O3") // (code on steroids)
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
# define int ll
# define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
# define len(x) (ll((x).size()))


# define print(x) cout<<(x)<<"\n"
# define P0(x) cout<<(x)<<' '
# define P1(x) cout<<(x)<<"\n"
# define P2(x,y) cout<<(x)<<' '<<(y)<<"\n"
# define P3(x,y,z) cout<<(x)<<' '<<(y)<<' '<<(z)<<"\n"
# define P4(x,y,z,w) cout<<(x)<<' '<<(y)<<' '<<(z)<<' '<<(w)<<"\n"

// using auto in for
# define printv(v) {auto kjhg = v;for(auto idnphq : kjhg) cout<< idnphq << ' ';cout << "\n";}
# define printvv(v) {auto kjhg = v;for(auto idnphq : kjhg) {for(auto plinrw : idnphq) cout<< plinrw << ' ';cout << "\n";}}
# define prints(s) {auto kjhg = s;for(auto idnphq : kjhg) cout<< idnphq << ' ';cout << "\n";}
# define printm(m) {auto kjhg = m;for(auto idnphq : kjhg) cout<< idnphq.first << ':' << idnphq.second << ' ';cout << "\n";}

// for runtime errors (assertions and segmentation faults)
# define debug(x) {\
    cout<<"all good "<<x<<"\n";\
    exit(0);\
}

int isl(vector<int> a){
	return(a[0]<=2);
}
int isr(vector<int> a){
	return(a[0]%2);
}

int f(vector<int> a, vector<int> b){
	// case 1 if left corrdinates are equal
	if(b[1]==a[1]){
		return(1);
	}
	// case two unequal
	if(b[1]<a[1]) swap(a,b);// a is now the one with lesser left coordinate
	if(a[2]>b[1]){
		return(1);
	}else if(a[2]==b[1]){
		int fl = isr(a) && isl(b);
		return(fl);
	}else{
		return(0);
	}
}

int32_t main(){
fastio;

int n; cin>>n;

vector<vector<int>> a = {};
for(int i = 0; i<n ; i++){
	vector<int> dat(3);
	cin>>dat[0]>>dat[1]>>dat[2];
	a.push_back(dat);
}
// printvv(a);
int cnt = 0;
for(int i = 0; i<n ; i++){
	for( int j = i+1; j<n ; j++){
		cnt+=f(a[i],a[j]);
		// print(f(a[i],a[j]));
	}
}

print(cnt);

return(0);
}


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

typedef long long ll;
#define ephsilon 1e-9
#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const long long mod = 1e9+7;
const long long mod1 = 998244353;
const int maxN = 2e5+1;
const int mx = 1e5+1;


int32_t main()
{
    fastio;
    int n;
    double a,b;
    cin>>n;
    vector<pair<double,double>>v;
    int t;
    for(int i=0;i<n;i++)
    {
        cin>>t>>a>>b;
        if(t==2)b-=.1;
        else if(t==3)a+=.1;
        else if(t==4)a+=.1,b-=.1;
        v.push_back({a,b});
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            double l1=v[i].first,r1=v[i].second;
            double l2=v[j].first,r2=v[j].second;

            if(l1>r2 || r1<l2)continue;
            else ans++;
        }
    }
    cout<<ans<<"\n";

return 0;
}


