#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  int n;
  cin >> n;
  double a[n],b[n],c[n];
  int ans = n*(n-1)/2;
  
  rep(i,n){
    cin >> a[i] >> b[i] >> c[i];
     if(a[i] ==2)
     {c[i] -= 0.1;}
    else if(a[i] ==3)
      {b[i] += 0.1;}
    else if(a[i] ==4)
    {c[i] -= 0.1;
     b[i] += 0.1;}
  }
  
   rep(i,n-1){
     for(int j =i+1;j<n;j++){
       if(c[i] < b[j] || b[i] > c[j])
       {ans -=1;}
     }
   }
    cout << ans << endl;
  
  
return 0;
}

/********************************************************************************/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define int long long int
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
const double PI = 4*atan(1);

#define loop(i,n) for(int i=0;i<n;i++)
#define itr(it,v)  for(auto it=v.begin();it!=v.end();++it)  
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl ;
#define MOD (int)(1e9+7)

void solve()
{
    int n;
    cin>>n;

    int t[n],l[n],r[n];
    int ans=0;
    for(int i=0;i<n;i++)
    {
      cin>>t[i];

      cin>>l[i]>>r[i];
  

      for(int k=i-1;k>=0;k--)
      {
        int x1=l[k];
        int y1=r[k];

        if((y1<l[i] or x1>r[i]) or((r[k]==l[i] and (t[k]==2 or t[k]==4 or t[i]==4 or t[i]==3)) or (r[i]==l[k] and (t[i]==2 or t[k]==4 or t[i]==4 or t[k]==3))))
        {
          
        }
        else
          ans++;
      }

      //cout<<ans<<endl;

    }
    cout<<ans<<endl;

}

int32_t main()
{ IOS


    int t=1;
    //cin>>t;
    
    while(t--)
    {
      solve();
    }
    return 0; 
}