#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar('-');
  }
  while(s--){
    my_putchar(f[s]+'0');
  }
}
int N;
double L[2000+10];
double R[2000+10];
int intersect(int i, int j){
  if(L[j] <=  L[i]  &&   L[i] <= R[j] ){
    return 1;
  }
  if(L[j] <=  R[i]  &&   R[i] <= R[j] ){
    return 1;
  }
  if(L[i] <=  L[j]  &&   L[j] <= R[i] ){
    return 1;
  }
  if(L[i] <=  R[j]  &&   R[j] <= R[i] ){
    return 1;
  }
  return 0;
}
int main(){
  int i;
  rd(N);
  for(i=(0);i<(N);i++){
    int t;
    int l;
    int r;
    rd(t);
    rd(l);
    rd(r);
    if(t == 1){
      L[i] = l;
      R[i] = r;
    }
    else if( t == 2){
      L[i] = l;
      R[i] = r-0.5;
    }
    else if( t == 3){
      L[i] = l+0.5;
      R[i] = r;
    }
    else if( t == 4){
      L[i] = l+0.5;
      R[i] = r-0.5;
    }
    if(L[i] > R[i]){
      L[i] = R[i] = -1;
    }
  }
  int ans = 0;
  for(i=(0);i<(N);i++){
    int j;
    for(j=(i+1);j<(N);j++){
      ans += intersect(i, j);
    }
  }
  wt_L(ans);
  wt_L('\n');
  return 0;
}
// cLay version 20210405-1

// --- original code ---
// //no-unlocked
// int N;
// double L[2d3+10], R[];
// 
// int intersect(int i, int j){
//     if(L[j] <=  L[i] <= R[j] ) return 1;
//     if(L[j] <=  R[i] <= R[j] ) return 1;
//     if(L[i] <=  L[j] <= R[i] ) return 1;
//     if(L[i] <=  R[j] <= R[i] ) return 1;
//     return 0;
// }
// { 
//     rd(N);
//     rep(i, N){
//         int t, l, r;
//         rd(t, l, r);
//         if(t == 1){
//             L[i] = l;
//             R[i] = r;
//         }else if( t == 2){
//             L[i] = l;
//             R[i] = r-0.5;
//         }else if( t == 3){
//             L[i] = l+0.5;
//             R[i] = r;
//         }else if( t == 4){
//             L[i] = l+0.5;
//             R[i] = r-0.5;
//         }
//         if(L[i] > R[i]) L[i] = R[i] = -1;
//     }
//     int ans = 0;
//     rep(i, N){
//         rep(j, i+1, N){
//             ans += intersect(i, j);
//         }
//     }
//     wt(ans);
// } 
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//cout << std::fixed << std::setprecision(15) << res << endl;

int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int N;
  cin >> N;
  struct edge {
    int t;
    int l;
    int r;
    edge(int t, int l, int r) : t(t), l(l), r(r) {}
    edge() : t(0),l(0),r(0) {}
  };
  vector<edge> kukan(N);
  
  rep(i, N) {
    int t,l,r;
    cin >> t >> l >> r;
    kukan[i] = edge(t,l,r);
  }
  ll res = 0;
  rep (i, N) {
    for (int j = i+1; j < N; j++) {
      edge e1 = kukan[i];
      edge e2 = kukan[j];
      if (e2.l < e1.l) {
        edge tmp = e2;
        e2 = e1;
        e1 = tmp;
      } else if (e2.l == e1.l && ((e1.t == 2 || e1.t == 3) && (e2.t == 1 || e2.t == 2))) {
        edge tmp = e2;
        e2 = e1;
        e1 = tmp;
      }

      if (e2.l < e1.r) {
        res++;
      } else if (e2.l == e1.r) {
        if ((e1.t == 1 || e1.t == 3) && (e2.t == 1 || e2.t == 2)) {
          res++;
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}

