#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
#include<cstring>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef vector<pll> vpll; 
 
#define endl '\n' 
#define fast std::ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair

void solve(){
   ll n;
   cin>>n;
   pair<ll,ll> p[n];
   ll t[n];
   for(int i=0;i<n;i++){
      cin>>t[i]>>p[i].first>>p[i].second;
   }
   int ans=0;
   for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){

         if(p[i].first>p[j].second || p[i].second<p[j].first)continue;
         if(p[i].first==p[j].second){
            if(!((t[i]==1 || t[i]==2)&&(t[j]==1 || t[j]==3)))continue;
         }
         if(p[i].second==p[j].first){
            //cout<<"*"<<endl;
            if(!((t[j]==1 || t[j]==2)&&(t[i]==1 || t[i]==3)))continue;
         }
         ans++;
        // cout<<i<<" "<<j<<endl;
      }
   }
   cout<<ans<<endl;
}

int main(){
   fast;
   //clock_t begin = clock();
   ll tc=1;//cin>>tc;
   for(ll i=1;i<=tc;i++){
       //cout<<"Case #"<<i<<": ";
       solve();
   }
   //clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs;

}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1e9
typedef long long ll;
typedef long double ld;

int main(){
  ll n;
  cin >> n;
  vector<pair<double,double>> v(n);
  REP(i,n){
    ll t;
    double l, r;
    cin >> t >> l >> r;
    if(t == 2)r-=0.1;
    else if(t==3)l+=0.1;
    else if(t==4){
      l+=0.1;
      r-=0.1;
    }
    v[i] = {l,r};
  }
  ll cnt = 0;
  REP(i,n-1){
    FOR(j,i+1,n){
      if(v[j].first <= v[i].second && v[i].first <= v[j].second)cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
