#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  double x[2010][5];
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<3;j++){
      cin>>x[i][j];
      if(x[i][0]==2)
        x[i][2]-=0.1;
      if(x[i][0]==3)
        x[i][1]+=0.1;
      if(x[i][0]==4){
        x[i][1]+=0.1;
        x[i][2]-=0.1;
      }
    }
  for(int k=0;k<n;k++)
    for(int u=k+1;u<n;u++){
      if(max(x[u][1],x[k][1])<=min(x[u][2],x[k][2]))
      ans++;
    }
  cout<<ans<<endl;
  return 0;
}
// Daniel Grzegorzewski15
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

const int N = 2003;

int n, res, t[N], l[N], r[N], in[N];

bool cmp(int i, int j) {
  return l[i] < l[j];
}

int main() {
  init_ios();
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    in[i] = i;
    cin >> t[i] >> l[i] >> r[i];
  }
  sort(in+1, in+n+1, cmp);
  for (int i = 1; i <= n; ++i)
    for (int j = i+1; j <= n; ++j) {
      int p = in[i], q = in[j];
      if (l[q] <= r[p]) {
        if (l[q] == r[p]) {
          if (t[p] == 2 || t[p] == 4 || t[q] == 3 || t[q] == 4)
            continue;
        }
        ++res;
      }
    }
  cout<<res<<"\n";
}