#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (int)(a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using VD = vector<double>;
using VII = vector<VI>;
using VLL = vector<VL>;
using VDD = vector<VD>;
using P = pair<int, int>;
using PL = pair<ll, ll>;

template <typename T>
bool chmax(T& a, const T& b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  VI t(N);
  VI l(N);
  VI r(N);
  REP(i, N) {
    cin >> t[i] >> l[i] >> r[i];
    l[i] *= 2;
    r[i] *= 2;
    if(t[i] == 2) {
      r[i]--;
    }
    if(t[i] == 3) {
      l[i]++;
    }
    if(t[i] == 4) {
      l[i]++;
      r[i]--;
    }
  }
  vector<PL> p(N);
  REP(i, N) {
    p[i].first = l[i];
    p[i].second = r[i];
  }
  sort(p.begin(), p.end());

  ll ans = 0;
  FOR(i, 0, N - 2) FOR(j, i + 1, N - 1) {
    if(p[i].second >= p[j].first) ans++;
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  int t;
  vector<double> l(n);
  vector<double> r(n);
  for(int i = 0;i < n;i++){
    cin >> t >> l[i] >> r[i];
    if(t >= 3) l[i] += 0.1f;
    if(t % 2 == 0) r[i] -= 0.1f;
  }
  int ans = 0;
  for(int i = 0;i < n - 1;i++){
    for(int j = i + 1;j < n;j++){
      if(l[i] <= r[j] && r[i] >= l[j]) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

