#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vv e;

bool check(ll i,ll j){
    ll nl=e[1][i],nr=e[2][i],ml=e[1][j],mr=e[2][j];
    ll n = e[0][i];
    ll m = e[0][j];
    if(nl > ml){
        swap(nl,ml);
        swap(nr,mr);
        swap(n,m);
    }
    else if(nl==ml && (n==3 || n==4) && (m==1 || m==2)){
        swap(nl,ml);
        swap(nr,mr);
        swap(n,m);
    }
    if(nr>ml){
        return true;
    }
    else if(nr==ml){
        if((n==1 || n==3)&&(m==1 || m==2))return true;
        else return false;
    }
    else return false;
}
int main(){
    ll N;
    cin>>N;
    e.resize(3,v(N));

    rep(i,0,N){
        cin>>e[0][i]>>e[1][i]>>e[2][i];
    }
    ll ans = 0;
    rep(i,0,N)rep(j,i+1,N){
        if(check(i,j))ans++;
    }
    cout<<ans;
    return 0;
}
#include <bits/stdc++.h>
#define REP_(i, a_, b_, a, b, ...) \
  for (int i = (a), END_##i = (b); i < END_##i; ++i)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(x) std::begin(x), std::end(x)
using i64 = long long;

template<typename T, typename U>
inline bool chmax(T &a, U b) {
  return a < b and ((a = std::move(b)), true);
}
template<typename T, typename U>
inline bool chmin(T &a, U b) {
  return a > b and ((a = std::move(b)), true);
}

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &a) {
  for (auto &x : a) is >> x;
  return is;
}
template<typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
}

void print() { std::cout << "\n"; }
template<class T>
void print(const T &x) {
  std::cout << x << "\n";
}
template<typename Head, typename... Tail>
void print(const Head &head, Tail... tail) {
  std::cout << head << " ";
  print(tail...);
}

void read_from_cin() {}
template<typename T, typename... Ts>
void read_from_cin(T &value, Ts &...args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define INPUT(type, ...) \
  type __VA_ARGS__;      \
  read_from_cin(__VA_ARGS__);

#ifdef ENABLE_DEBUG
#include "debug_dump.hpp"
#else
#define DUMP(...)
#endif

using namespace std;

auto solve() {
  INPUT(int, n);
  vector<array<i64, 3>> a(n);
  REP(i, n) {
    INPUT(i64, t, l, r);
    l *= 2;
    r *= 2;
    if (t == 1) {
      //
    } else if (t == 2) {
      r -= 1;
    } else if (t == 3) {
      l += 1;
    } else {
      l += 1;
      r -= 1;
    }
    a[i][0] = l;
    a[i][1] = r;
  }
  i64 ans = 0;
  REP(i, n) {
    REP(j, i + 1, n) {
      bool no_over = false;
      if (a[i][1] < a[j][0]) {
        no_over = true;
      } else if (a[j][1] < a[i][0]) {
        no_over = true;
      }
      if (not no_over) {
        ++ans;
      }
    }
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  cout << std::fixed << std::setprecision(15);
  int t = 1;
  REP(test_case, t) {
    auto ans = solve();
    print(ans);
  }
}
