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

#define ll     long long
#define test   int tt; cin>>tt; while(tt--)
#define ff     first
#define ss     second
#define pb     push_back
#define ppb    pop_back
#define pf     push_front
#define ppf    pop_front

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin>>n;

    vector<pair<pair<int, int>, int>> intervals(n);

    for(auto &[in, t]: intervals)
        cin>>t>>in.ff>>in.ss;

    sort(intervals.begin(), intervals.end());

    ll int ans=0;

    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            int l1=intervals[i].ff.ff;
            int r1=intervals[i].ff.ss;
            int t1=intervals[i].ss;

            int l2=intervals[j].ff.ff;
            int r2=intervals[j].ff.ss;
            int t2=intervals[j].ss;

            if((t1==1 || t1==3) && t2<=2 && r1>=l2)
                ans++;
            else if((t1==1 || t1==3) && t2>2 && r1>l2)
                ans++;
            else if((t1==2 || t1==4) && r1>l2)
                ans++;

        }
    }

    cout<<ans<<endl;
}

#include <bits/stdc++.h>
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
double mina(double a,double b)
{
    if(a<=b)
    return a;
    return b;
}
double maxa(double a,double b)
{
    if(a<=b)
    return b;
    return a;
}



int main() {
   long long int t,n,i,j,k,l,flag,flag1,count,count1,count2,count3,count4,sum,max1,max2,m,c1,c2,temp,suma,sumb;
  long long int d,e,a,b,c;
  
  double a2[300001],b1[2002][3],a1[300001];

 
        //vector< long long int> v1,v2,v;
        //  vector< pair <long long int,long long int> > v3; 
  //  string s1,s2,s;
//  char s[300001],s1[300001];
  //  long long int f[100001];
  //   for(i=0;i<100001;i++)
  //    f[i]=0;
    count=0,flag=0,flag1=0,sum=0,max1=0,max2=0,c1=0,c2=0,temp=0,suma=0,sumb=0,count1=0,count2=0,count3=0,count4=0;
  // long long int max3=0,max4=0,ans=0,mina=999999999999999999,c0=0,c3,c4;
   cin>>n;
   for(i=0;i<n;i++)
   {
       for(j=0;j<3;j++)
       cin>>b1[i][j];
   }
   for(i=0;i<n;i++)
   {
       if(b1[i][0]==2)
       b1[i][2]=b1[i][2]-0.1;
      else  if(b1[i][0]==3)
       b1[i][1]=b1[i][1]+0.1;
        if(b1[i][0]==4)
        {
       b1[i][2]=b1[i][2]-0.1;
       b1[i][1]=b1[i][1]+0.1;
        }
       
   }
   
   for(i=0;i<n;i++)
   {
       if(b1[i][1]>b1[i][2])
       swap(b1[i][1],b1[i][2]);
   }
   for(i=0;i<n;i++)
   {
       for(j=i+1;j<n;j++)
       {
           if(mina(b1[i][2],b1[j][2]) >=maxa( b1[i][1],b1[j][1]) )
           count++;
          
       }
   }
   //for(i=0;i<n;i++)
  // for(j=0;j<3;j++)
  // cout<<b1[i][j];
   cout<<count;
	return 0;
}