#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ll long long
#define ld long double
#define ALL(a) (a).begin(), (a).end()


int main() {
  int n;
  cin >> n;
  
  vector<pair<ll,ll>> a;
  
  rep(i,n){
    ll t, l, r;
    cin >> t >> l >> r;
    l *= 2;
    r *= 2;
    if(t==2) r--;
    else if(t==3) l++;
    else if(t==4){
      l++; r--;
    }
    a.push_back(make_pair(l,r));
  }
  
  sort(ALL(a));
  
  ll ans = 0;
  for(int i=0; i < (int)a.size()-1; i++){
    ll s = a[i].second;
    for(int j=i+1; j < (int)a.size(); j++){
      ll t = a[j].first;
      ll u = a[j].second;
      if(t <= s && s <= u) ans++;
      else if(u <= s) ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}
// ＵＴＦ−８

#include<bits/stdc++.h>

using namespace std;
using ll = long long int;
using lc = complex<double>;
template <class T>
bool complex_comparator(const complex<T> &a, const complex<T> &b) {
    return real(a) == real(b) ? imag(a) < imag(b) : real(a) < real(b);
}

/* #include<atcoder/all> */
/* using namespace atcoder; */

template<class T>bool chmax(T &a, const T &b) { return (a<b ? (a=b,1) : 0); }
template<class T>bool chmin(T &a, const T &b) { return (a>b ? (a=b,1) : 0); }

int main(void) {
    constexpr ll MOD = 1 ? 1e9+7 : 998244353;
    const double PI = acos(-1);
    constexpr double eps = 1e-5;
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    if(1) {
        ll n;
        cin >> n;
        vector<tuple<ll,ll,ll>> v(n);
        for(auto &[t, l, r]: v)
            cin >> t >> l >> r;

        ll res = 0;
        for(ll i=0; i<n; i++)
            for(ll j=i+1; j<n; j++) {
                auto [t1, l1, r1] = v[i];
                auto [t2, l2, r2] = v[j];

                bool ok = true;

                ok &= ((t1<3) && ((t2&1) == 1) && l1 <= r2) || l1 < r2;
                ok &= ((t2<3) && ((t1&1) == 1) && l2 <= r1) || l2 < r1;

                res += ok;
            }
        cout << res<< endl;
    }
    return 0;
}